add code for cleaning up unused devices mentioned in the config
authorFelix Fietkau <nbd@openwrt.org>
Tue, 5 Apr 2011 01:52:39 +0000 (03:52 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 5 Apr 2011 01:52:39 +0000 (03:52 +0200)
config.c
config/network
device.c
device.h

index 6019862..1711121 100644 (file)
--- a/config.c
+++ b/config.c
@@ -180,6 +180,7 @@ config_init_interfaces(const char *name)
                if (!strcmp(s->type, "interface"))
                        config_parse_interface(s);
        }
                if (!strcmp(s->type, "interface"))
                        config_parse_interface(s);
        }
+       cleanup_devices();
        config_init = false;
 
        start_pending_interfaces();
        config_init = false;
 
        start_pending_interfaces();
index 00c5b51..0a02e89 100644 (file)
@@ -12,6 +12,9 @@ config device
        option ifname   "eth0.1 eth0.2"
        option mtu              1500
 
        option ifname   "eth0.1 eth0.2"
        option mtu              1500
 
+config device
+       option name             dummy
+
 config interface lan
        option ifname   'br-lan'
        option proto    static
 config interface lan
        option ifname   'br-lan'
        option proto    static
index 57b0ac9..34b49d4 100644 (file)
--- a/device.c
+++ b/device.c
@@ -197,3 +197,16 @@ void remove_device_user(struct device_user *dep)
 
        dep->dev = NULL;
 }
 
        dep->dev = NULL;
 }
+
+void
+cleanup_devices(void)
+{
+       struct device *dev, *tmp;
+
+       avl_for_each_element_safe(&devices, dev, avl, tmp) {
+               if (!list_empty(&dev->users))
+                       continue;
+
+               free_device(dev);
+       }
+}
index 79aec32..bbb78d8 100644 (file)
--- a/device.h
+++ b/device.h
@@ -100,6 +100,8 @@ int claim_device(struct device *dev);
 void release_device(struct device *dev);
 int check_device_state(struct device *dev);
 
 void release_device(struct device *dev);
 int check_device_state(struct device *dev);
 
+void cleanup_devices(void);
+
 struct device *get_vlan_device_chain(const char *ifname, bool create);
 struct device *bridge_create(const char *name, struct uci_section *s);
 
 struct device *get_vlan_device_chain(const char *ifname, bool create);
 struct device *bridge_create(const char *name, struct uci_section *s);