X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fnetdev-linux.c;h=ccc3f845c9c2a96afcdf5d93171936d498c29911;hb=847c7448532ddf90f28ace17233f4993e403f6f2;hp=d45349b29b7f3f84229f32cbf5c33daa3c66888a;hpb=88258e0034cc7ca6ffde0974f1fb92d26289ad6a;p=openvswitch diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index d45349b2..ccc3f845 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -75,7 +75,7 @@ #endif static struct rtnetlink_notifier netdev_linux_cache_notifier; -static struct shash cache_map = SHASH_INITIALIZER(&cache_map); +static int cache_notifier_refcount; enum { VALID_IFINDEX = 1 << 0, @@ -220,16 +220,22 @@ netdev_linux_cache_cb(const struct rtnetlink_change *change, { struct netdev_dev_linux *dev; if (change) { - dev = shash_find_data(&cache_map, change->ifname); - if (dev) { + struct netdev_dev *base_dev = netdev_dev_from_name(change->ifname); + if (base_dev) { + dev = netdev_dev_linux_cast(base_dev); dev->cache_valid = 0; } } else { + struct shash device_shash; struct shash_node *node; - SHASH_FOR_EACH (node, &cache_map) { + + shash_init(&device_shash); + netdev_dev_get_devices(&netdev_linux_class, &device_shash); + SHASH_FOR_EACH (node, &device_shash) { dev = node->data; dev->cache_valid = 0; } + shash_destroy(&device_shash); } } @@ -573,18 +579,18 @@ netdev_linux_create_system(const char *name, const char *type UNUSED, VLOG_WARN("%s: arguments for system devices should be empty", name); } - if (shash_is_empty(&cache_map)) { + if (!cache_notifier_refcount) { error = rtnetlink_notifier_register(&netdev_linux_cache_notifier, netdev_linux_cache_cb, NULL); if (error) { return error; } } + cache_notifier_refcount++; netdev_dev = xzalloc(sizeof *netdev_dev); - netdev_dev->shash_node = shash_add(&cache_map, name, &netdev_dev); - netdev_dev_init(&netdev_dev->netdev_dev, name, &netdev_linux_class); + *netdev_devp = &netdev_dev->netdev_dev; return 0; } @@ -787,9 +793,9 @@ netdev_linux_destroy(struct netdev_dev *netdev_dev_) const char *type = netdev_dev_get_type(netdev_dev_); if (!strcmp(type, "system")) { - shash_delete(&cache_map, netdev_dev->shash_node); + cache_notifier_refcount--; - if (shash_is_empty(&cache_map)) { + if (!cache_notifier_refcount) { rtnetlink_notifier_unregister(&netdev_linux_cache_notifier); } } else if (!strcmp(type, "tap")) { @@ -812,6 +818,7 @@ netdev_linux_open(struct netdev_dev *netdev_dev_, int ethertype, /* Allocate network device. */ netdev = xzalloc(sizeof *netdev); + netdev->fd = -1; netdev_init(&netdev->netdev, netdev_dev_); error = netdev_get_flags(&netdev->netdev, &flags); @@ -868,8 +875,6 @@ netdev_linux_open(struct netdev_dev *netdev_dev_, int ethertype, if (error) { goto error; } - } else { - netdev->fd = -1; } *netdevp = &netdev->netdev; @@ -886,7 +891,7 @@ netdev_linux_close(struct netdev *netdev_) { struct netdev_linux *netdev = netdev_linux_cast(netdev_); - if (netdev->fd >= 0 && strcmp(netdev_get_type(netdev_), "tap")) { + if (netdev->fd > 0 && strcmp(netdev_get_type(netdev_), "tap")) { close(netdev->fd); } free(netdev); @@ -1543,8 +1548,8 @@ netdev_linux_set_policing(struct netdev *netdev, COVERAGE_INC(netdev_set_policing); if (kbits_rate) { if (!kbits_burst) { - /* Default to 10 kilobits if not specified. */ - kbits_burst = 10; + /* Default to 1000 kilobits if not specified. */ + kbits_burst = 1000; } /* xxx This should be more careful about only adding if it