netdev: New function netdev_ref().
authorBen Pfaff <blp@nicira.com>
Tue, 21 May 2013 22:42:44 +0000 (15:42 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 22 May 2013 18:10:30 +0000 (11:10 -0700)
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>
lib/netdev.c
lib/netdev.h

index 5c2e9f5..5aae01c 100644 (file)
@@ -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
index c7f3c1d..b1cc319 100644 (file)
@@ -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);