From 335562c0b9b190f61c0cc457a4098c2688561387 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 15 Jun 2009 16:51:46 -0700 Subject: [PATCH] dpif: Rename dpif_get_name() to dpif_port_get_name(), update interface. With multiple kinds of datapaths, code should not just use "dp%u" along with dpif_minor() to print a datapath name, because not all datapaths can sensibly be named that way. We want to use a function with a name like dpif_get_name() to retrieve a datapath name for printing to the user, in which case the existing dpif_get_name() function would be confusing. So rename the existing one to something more explicit. --- lib/dpif.c | 37 ++++++++++++++++++++----------------- lib/dpif.h | 3 ++- secchan/discovery.c | 3 ++- secchan/in-band.c | 3 ++- secchan/ofproto.c | 3 ++- utilities/ovs-ofctl.c | 2 +- vswitchd/bridge.c | 3 ++- 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/lib/dpif.c b/lib/dpif.c index 21f1173f..3dc7af00 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -168,22 +168,6 @@ dpif_create(const char *name, struct dpif *dpif) } } -int -dpif_get_name(struct dpif *dpif, char *name, size_t name_size) -{ - struct odp_port port; - int error; - - assert(name_size > 0); - *name = '\0'; - - error = dpif_port_query_by_number(dpif, ODPP_LOCAL, &port); - if (!error) { - ovs_strlcpy(name, port.devname, name_size); - } - return error; -} - int dpif_delete(struct dpif *dpif) { @@ -322,6 +306,24 @@ dpif_port_query_by_name(const struct dpif *dpif, const char *devname, } } +int +dpif_port_get_name(struct dpif *dpif, uint16_t port_no, + char *name, size_t name_size) +{ + struct odp_port port; + int error; + + assert(name_size > 0); + + error = dpif_port_query_by_number(dpif, port_no, &port); + if (!error) { + ovs_strlcpy(name, port.devname, name_size); + } else { + *name = '\0'; + } + return error; +} + int dpif_port_list(const struct dpif *dpif, struct odp_port **ports, size_t *n_ports) @@ -698,7 +700,8 @@ dpifmon_create(const char *datapath_name, struct dpifmon **monp) if (error) { goto error; } - error = dpif_get_name(&mon->dpif, local_name, sizeof local_name); + error = dpif_port_get_name(&mon->dpif, ODPP_LOCAL, + local_name, sizeof local_name); if (error) { goto error_close_dpif; } diff --git a/lib/dpif.h b/lib/dpif.h index d81cf631..a0e60311 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -40,7 +40,6 @@ int dpif_create(const char *name, struct dpif *); void dpif_close(struct dpif *); static inline unsigned int dpif_id(const struct dpif *dpif); -int dpif_get_name(struct dpif *, char *name, size_t name_size); int dpif_delete(struct dpif *); @@ -59,6 +58,8 @@ int dpif_port_query_by_number(const struct dpif *, uint16_t port_no, struct odp_port *); int dpif_port_query_by_name(const struct dpif *, const char *devname, struct odp_port *); +int dpif_port_get_name(struct dpif *, uint16_t port_no, + char *name, size_t name_size); int dpif_port_list(const struct dpif *, struct odp_port **, size_t *n_ports); int dpif_port_group_set(struct dpif *, uint16_t group, diff --git a/secchan/discovery.c b/secchan/discovery.c index 0c08de39..2868db5a 100644 --- a/secchan/discovery.c +++ b/secchan/discovery.c @@ -112,7 +112,8 @@ discovery_create(const char *re, bool update_resolv_conf, d->update_resolv_conf = update_resolv_conf; /* Initialize DHCP client. */ - error = dpif_get_name(dpif, local_name, sizeof local_name); + error = dpif_port_get_name(dpif, ODPP_LOCAL, + local_name, sizeof local_name); if (error) { VLOG_ERR("failed to query datapath local port: %s", strerror(error)); goto error_regfree; diff --git a/secchan/in-band.c b/secchan/in-band.c index 9dccf5f1..1e242385 100644 --- a/secchan/in-band.c +++ b/secchan/in-band.c @@ -321,7 +321,8 @@ in_band_create(struct ofproto *ofproto, int error; *in_bandp = NULL; - error = dpif_get_name(dpif, local_name, sizeof local_name); + error = dpif_port_get_name(dpif, ODPP_LOCAL, + local_name, sizeof local_name); if (error) { return error; } diff --git a/secchan/ofproto.c b/secchan/ofproto.c index aa9e44a1..8cde9bfe 100644 --- a/secchan/ofproto.c +++ b/secchan/ofproto.c @@ -3233,7 +3233,8 @@ pick_datapath_id(struct dpif *dpif, uint64_t fallback_dpid) uint8_t ea[ETH_ADDR_LEN]; int error; - error = dpif_get_name(dpif, local_name, sizeof local_name); + error = dpif_port_get_name(dpif, ODPP_LOCAL, + local_name, sizeof local_name); if (!error) { error = netdev_nodev_get_etheraddr(local_name, ea); if (!error) { diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 583e5548..254aa957 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -268,7 +268,7 @@ open_vconn(const char *name, struct vconn **vconnp) char *socket_name; char *vconn_name; - run(dpif_get_name(&dpif, dpif_name, sizeof dpif_name), + run(dpif_port_get_name(&dpif, ODPP_LOCAL, dpif_name, sizeof dpif_name), "obtaining name of %s", dpif_name); dpif_close(&dpif); if (strcmp(dpif_name, name)) { diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index ba905287..7ecf1245 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -288,7 +288,8 @@ bridge_init(void) retval = dpif_open(devname, &dpif); if (!retval) { char dpif_name[IF_NAMESIZE]; - if (dpif_get_name(&dpif, dpif_name, sizeof dpif_name) + if (dpif_port_get_name(&dpif, ODPP_LOCAL, + dpif_name, sizeof dpif_name) || !cfg_has("bridge.%s.port", dpif_name)) { dpif_delete(&dpif); } -- 2.30.2