From: Ben Pfaff <blp@nicira.com>
Date: Tue, 21 May 2013 22:42:44 +0000 (-0700)
Subject: netdev: New function netdev_ref().
X-Git-Tag: sliver-openvswitch-1.10.90-3~6^2~232
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=0bb0393a0b274776ebd61ca2265a252ac8dfbe2a;p=sliver-openvswitch.git

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 <ethan@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
---

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);