[ovs-dev] [netdev 20/27] netdev: Make netdev_from_name() take a reference to its returned netdev.
Andy Zhou
azhou at nicira.com
Mon Aug 5 19:56:42 UTC 2013
looks good.
Acked-by: Andy Zhou <azhou at nicira.com>
On Thu, Aug 1, 2013 at 2:29 PM, Ben Pfaff <blp at nicira.com> wrote:
> This API change is necessary for thread safety, to be added in an upcoming
> commit. Otherwise, the client would not be able to safely use the returned
> netdev because it could already have been destroyed.
>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
> lib/netdev-linux.c | 1 +
> lib/netdev.c | 17 +++++++++++++----
> 2 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
> index 5bbaf63..c59f590 100644
> --- a/lib/netdev-linux.c
> +++ b/lib/netdev-linux.c
> @@ -541,6 +541,7 @@ netdev_linux_cache_cb(const struct
> rtnetlink_link_change *change,
> struct netdev *base_dev = netdev_from_name(change->ifname);
> if (base_dev &&
> is_netdev_linux_class(netdev_get_class(base_dev))) {
> netdev_linux_update(netdev_linux_cast(base_dev), change);
> + netdev_close(base_dev);
> }
> } else {
> struct shash device_shash;
> diff --git a/lib/netdev.c b/lib/netdev.c
> index 2561538..30c44a2 100644
> --- a/lib/netdev.c
> +++ b/lib/netdev.c
> @@ -1386,11 +1386,18 @@ netdev_get_class(const struct netdev *netdev)
>
> /* Returns the netdev with 'name' or NULL if there is none.
> *
> - * The caller must not free the returned value. */
> + * The caller must free the returned netdev with netdev_close(). */
> struct netdev *
> netdev_from_name(const char *name)
> {
> - return shash_find_data(&netdev_shash, name);
> + struct netdev *netdev;
> +
> + netdev = shash_find_data(&netdev_shash, name);
> + if (netdev) {
> + netdev_ref(netdev);
> + }
> +
> + return netdev;
> }
>
> /* Fills 'device_list' with devices that match 'netdev_class'.
> @@ -1415,8 +1422,10 @@ netdev_get_devices(const struct netdev_class
> *netdev_class,
> const char *
> netdev_get_type_from_name(const char *name)
> {
> - const struct netdev *dev = netdev_from_name(name);
> - return dev ? netdev_get_type(dev) : NULL;
> + struct netdev *dev = netdev_from_name(name);
> + const char *type = dev ? netdev_get_type(dev) : NULL;
> + netdev_close(dev);
> + return type;
> }
>
> void
> --
> 1.7.10.4
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20130805/440825f1/attachment-0003.html>
More information about the dev
mailing list