From 0bb0393a0b274776ebd61ca2265a252ac8dfbe2a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 21 May 2013 15:42:44 -0700 Subject: [PATCH] netdev: New function netdev_ref(). I suspect that this makes it easier to make sure that a netdev stays open as long as needed in some cases where a module needs access to a netdev opened by some higher-level module. CC: Ethan Jackson Signed-off-by: Ben Pfaff --- lib/netdev.c | 11 +++++++++++ lib/netdev.h | 1 + 2 files changed, 12 insertions(+) diff --git a/lib/netdev.c b/lib/netdev.c index 5c2e9f55e..5aae01c6c 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -277,6 +277,17 @@ netdev_open(const char *name, const char *type, struct netdev **netdevp) return 0; } +/* Returns a reference to 'netdev_' for the caller to own. */ +struct netdev * +netdev_ref(const struct netdev *netdev_) +{ + struct netdev *netdev = CONST_CAST(struct netdev *, netdev_); + + ovs_assert(netdev->ref_cnt > 0); + netdev->ref_cnt++; + return netdev; +} + /* Reconfigures the device 'netdev' with 'args'. 'args' may be empty * or NULL if none are needed. */ int diff --git a/lib/netdev.h b/lib/netdev.h index c7f3c1d2d..b1cc31940 100644 --- a/lib/netdev.h +++ b/lib/netdev.h @@ -110,6 +110,7 @@ bool netdev_is_reserved_name(const char *name); /* Open and close. */ int netdev_open(const char *name, const char *type, struct netdev **); +struct netdev *netdev_ref(const struct netdev *); void netdev_close(struct netdev *); void netdev_parse_name(const char *netdev_name, char **name, char **type); -- 2.43.0