The database prevents multiple ports or interfaces with a single name, but
duplicates can still occur if, for example, two bridges' "ports" columns
both point to a single Port record. The existing warning just says in this
case that the database contains a duplicate port name. This prompts users
to dump the Port table to look for the duplicate. Of course there isn't
one, so then they ask me to point out the problem.
This commit improves the log message to point out the actual problem.
struct ovsrec_port *port_cfg = br_cfg->ports[j];
if (!sset_add(&ports, port_cfg->name)) {
struct ovsrec_port *port_cfg = br_cfg->ports[j];
if (!sset_add(&ports, port_cfg->name)) {
- VLOG_WARN("%s: database contains duplicate port name",
- port_cfg->name);
+ /* Duplicate port name. (We will warn about that later.) */
sset_destroy(&ports);
sset_init(&bridges);
sset_destroy(&ports);
sset_init(&bridges);
for (i = 0; i < ovs->n_bridges; i++) {
struct ovsrec_bridge *br_cfg = ovs->bridges[i];
struct vsctl_bridge *br;
for (i = 0; i < ovs->n_bridges; i++) {
struct ovsrec_bridge *br_cfg = ovs->bridges[i];
struct vsctl_bridge *br;
struct vsctl_port *port;
size_t k;
struct vsctl_port *port;
size_t k;
- if (!sset_add(&ports, port_cfg->name)) {
+ port = shash_find_data(&info->ports, port_cfg->name);
+ if (port) {
+ if (port_cfg == port->port_cfg) {
+ VLOG_WARN("%s: port is in multiple bridges (%s and %s)",
+ port_cfg->name, br->name, port->bridge->name);
+ } else {
+ /* Log as an error because this violates the database's
+ * uniqueness constraints, so the database server shouldn't
+ * have allowed it. */
+ VLOG_ERR("%s: database contains duplicate port name",
+ port_cfg->name);
+ }
struct ovsrec_interface *iface_cfg = port_cfg->interfaces[k];
struct vsctl_iface *iface;
struct ovsrec_interface *iface_cfg = port_cfg->interfaces[k];
struct vsctl_iface *iface;
- if (shash_find(&info->ifaces, iface_cfg->name)) {
- VLOG_WARN("%s: database contains duplicate interface name",
- iface_cfg->name);
+ iface = shash_find_data(&info->ifaces, iface_cfg->name);
+ if (iface) {
+ if (iface_cfg == iface->iface_cfg) {
+ VLOG_WARN("%s: interface is in multiple ports "
+ "(%s and %s)",
+ iface_cfg->name,
+ iface->port->port_cfg->name,
+ port->port_cfg->name);
+ } else {
+ /* Log as an error because this violates the database's
+ * uniqueness constraints, so the database server
+ * shouldn't have allowed it. */
+ VLOG_ERR("%s: database contains duplicate interface "
+ "name", iface_cfg->name);
+ }
}
}
sset_destroy(&bridges);
}
}
sset_destroy(&bridges);