{
struct alias_device *alias;
- device_lock();
-
alias = avl_find_element(&aliases, name, alias, avl);
if (alias)
alias_set_device(alias, dev);
-
- device_unlock();
}
struct device *
bonding_remove_port(bp);
- device_lock();
-
device_remove_user(&bp->dev);
/*
device_set_present(dev, true);
}
- device_unlock();
-
free(bp);
}
goto restart;
}
- device_lock();
-
device_remove_user(&bm->dev);
uloop_timeout_cancel(&bm->check_timer);
device_set_present(dev, true);
}
- device_unlock();
-
free(bm);
}
vlist_update(&interfaces);
config_init = true;
- device_lock();
device_reset_config();
config_init_devices(true);
config_init_wireless();
config_init = false;
- device_unlock();
device_reset_old();
device_init_pending();
vlist_flush(&interfaces);
- device_free_unused(NULL);
interface_refresh_assignments(false);
interface_start_pending();
wireless_start_pending();
return NULL;
}
-void device_lock(void)
-{
- __devlock++;
-}
-
-void device_unlock(void)
-{
- __devlock--;
- if (!__devlock)
- device_free_unused(NULL);
-}
-
static int device_vlan_len(struct kvlist *kv, const void *data)
{
return sizeof(unsigned int);
}
static void
-__device_free_unused(struct device *dev)
+__device_free_unused(struct uloop_timeout *timeout)
{
- if (!safe_list_empty(&dev->users) ||
- !safe_list_empty(&dev->aliases) ||
- dev->current_config || __devlock)
- return;
+ struct device *dev, *tmp;
+
+ avl_for_each_element_safe(&devices, dev, avl, tmp) {
+ if (!safe_list_empty(&dev->users) ||
+ !safe_list_empty(&dev->aliases) ||
+ dev->current_config)
+ continue;
+
+ device_free(dev);
+ }
+}
+
+void device_free_unused(void)
+{
+ static struct uloop_timeout free_timer = {
+ .cb = __device_free_unused,
+ };
- device_free(dev);
+ uloop_timeout_set(&free_timer, 1);
}
void device_remove_user(struct device_user *dep)
safe_list_del(&dep->list);
dep->dev = NULL;
D(DEVICE, "Remove user for device '%s', refcount=%d\n", dev->ifname, device_refcount(dev));
- __device_free_unused(dev);
-}
-
-void
-device_free_unused(struct device *dev)
-{
- struct device *tmp;
-
- if (dev)
- return __device_free_unused(dev);
-
- avl_for_each_element_safe(&devices, dev, avl, tmp)
- __device_free_unused(dev);
+ device_free_unused();
}
void
extern struct device_type simple_device_type;
extern struct device_type tunnel_device_type;
-void device_lock(void);
-void device_unlock(void);
-
void device_vlan_update(bool done);
void device_stp_init(void);
int device_check_state(struct device *dev);
void device_dump_status(struct blob_buf *b, struct device *dev);
-void device_free_unused(struct device *dev);
+void device_free_unused(void);
struct device *get_vlan_device_chain(const char *ifname, int create);
void alias_notify_device(const char *name, struct device *dev);
inv_error:
extdev_invocation_error(ret, __extdev_methods[METHOD_CREATE], name);
error:
- device_lock();
free(edev->dev.config);
device_cleanup(&edev->dev);
free(edev);
- device_unlock();
netifd_log_message(L_WARNING, "Failed to create %s %s\n", type->name, name);
return NULL;
}
if (iface->parent_iface.iface)
interface_remove_user(&iface->parent_iface);
- device_lock();
-
if (iface->parent_ifname) {
parent = vlist_find(&interfaces, iface->parent_ifname, parent, node);
iface->parent_iface.cb = interface_alias_cb;
if (dev)
interface_set_main_dev(iface, dev);
- device_unlock();
-
if (iface->proto_handler->flags & PROTO_FLAG_INIT_AVAILABLE)
interface_set_available(iface, true);
}
struct blob_attr *vlan, bool add, bool link_ext)
{
struct device *dev;
- int ret;
-
- device_lock();
dev = device_get(name, add ? (link_ext ? 2 : 1) : 0);
- if (!dev) {
- ret = UBUS_STATUS_NOT_FOUND;
- goto out;
- }
+ if (!dev)
+ return UBUS_STATUS_NOT_FOUND;
- if (add) {
- interface_set_device_config(iface, dev);
- if (!link_ext)
- device_set_present(dev, true);
+ if (!add)
+ return interface_remove_link(iface, dev, vlan);
- ret = interface_add_link(iface, dev, vlan, link_ext);
- } else {
- ret = interface_remove_link(iface, dev, vlan);
- }
+ interface_set_device_config(iface, dev);
+ if (!link_ext)
+ device_set_present(dev, true);
-out:
- device_unlock();
-
- return ret;
+ return interface_add_link(iface, dev, vlan, link_ext);
}
void
return 0;
error:
- device_free_unused(dev);
+ device_free_unused();
return UBUS_STATUS_INVALID_ARGUMENT;
}