From patchwork Thu Nov 8 06:29:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 994663 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aMr5rgYL"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42rD1Q1Y5jz9sBZ for ; Thu, 8 Nov 2018 17:30:34 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 82FE886F; Thu, 8 Nov 2018 06:29:59 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 7763F5A8 for ; Thu, 8 Nov 2018 06:29:58 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 0183276F for ; Thu, 8 Nov 2018 06:29:57 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id c13-v6so9044196plz.13 for ; Wed, 07 Nov 2018 22:29:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PJru096UaAj9OrE1NwMyHobG6kj/hy5lCV0Ad9l6n7M=; b=aMr5rgYLUuscf0i5XiLmb2I7QOWjKQCOS1SYL52/HShX1QvSQrkL/Si5yYO5mt8a6L bkbeSrIeMK7lwOLMwAvqQVvhfYaZT7AeS1czU/A3h0f9SlNvqyl9aj8E2tF2nyz3mNzo iXzztoFSk9vziIX7J8khBAWkNbM1gZ2+8DfWKd0vOTFNqgwwZj/fd9SubmLwD6q49lcx e5e9qSsEu/8FPxDoAMrtkOuwua7PbPs+1zI7cdJ53CJE86Y6uOgJfr9R4kNwfcRd4bDa M1+TI/Dp434FMdvZJdzXhrGiz4LsqBWABp+WYCeeMV7vyhE9gdwJdqISAA46YoYpWFzJ R/Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PJru096UaAj9OrE1NwMyHobG6kj/hy5lCV0Ad9l6n7M=; b=r0d8sTwj136z4jOJWTdn+sEu5LnUt4J661zzFAU5DxZF5iBWXEd490rmpbEYX6RD1F 7RUh0HEkENNOoayjiSjIG9MIwHOWDyxDt+l6XMnmEDhbFS87didbc8zjppGQqH7szCrr FYrVYOt+5CnsnCYE4MsWb+IBMRv5isTLgE3YNggwfVRH9TnWQb4vZjKudABa6YBfN2IG OyBaydDlRVs5EYsbBEwg+hwJrU/tL3uHZ6yaoyIgC1+GQPLUFHhdnuIw31qy+3+pWvfH lQqP+KlQlAL9ZCrjNqYpNTbICOfIS8dFsnCkXIzPzrYakihLRFRhhhYGKdbHjMfAhI9K GHHQ== X-Gm-Message-State: AGRZ1gJHX7FBLxvqh1iEQd+eESjMukN4pFFVS4VyFErdCh4ocxscXafz TBNRGVq6mz0ocAsxNfpbUnda4Enm X-Google-Smtp-Source: AJdET5ebhZv8bpqpXKeoUhneNdsuE1XT9I6ryQD2v/4/Kva3aY1Uj+oIITT2RZdJuDRoybw34BUn1g== X-Received: by 2002:a17:902:e207:: with SMTP id ce7-v6mr3234973plb.47.1541658597330; Wed, 07 Nov 2018 22:29:57 -0800 (PST) Received: from localhost.localdomain.localdomain ([216.113.160.71]) by smtp.gmail.com with ESMTPSA id o12-v6sm2927271pfh.20.2018.11.07.22.29.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 22:29:56 -0800 (PST) From: Han Zhou X-Google-Original-From: Han Zhou To: dev@openvswitch.org Date: Wed, 7 Nov 2018 22:29:44 -0800 Message-Id: <1541658584-73372-2-git-send-email-hzhou8@ebay.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1541658584-73372-1-git-send-email-hzhou8@ebay.com> References: <1541658584-73372-1-git-send-email-hzhou8@ebay.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 2/2] ofproto.c: Handle the situation when ofp_port number exhausted. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Han Zhou When ofp_port number is exhausted, OFPP_NONE (65535) will be returned by alloc_ofp_port(). In this case we should error out instead of continue using 65535 as port number. Using the invalid number causes unpredictable consequences: 2018-11-06T01:29:10.042Z|142103|dpif(ovs-vswitchd)|WARN|system@ovs-system: failed to add ovn-aded97-0 as port: Device or resource busy 2018-11-06T01:29:10.045Z|142104|bridge(ovs-vswitchd)|INFO|bridge br-int: added interface ovn-aded97-0 on port 65535 2018-11-06T01:29:11.479Z|142108|ofproto(ovs-vswitchd)|WARN|br-int: cannot configure bfd on nonexistent port 65535 2018-11-06T01:29:11.479Z|142109|ofproto(ovs-vswitchd)|WARN|br-int: cannot configure LLDP on nonexistent port 65535 2018-11-06T01:29:11.479Z|142110|ofproto(ovs-vswitchd)|WARN|br-int: cannot configure datapath on nonexistent port 65535 ... 2018-11-06T01:29:18.783Z|142117|bfd(ovs-vswitchd)|INFO|ovn-aded97-0: BFD state change: admin_down->down "No Diagnostic"->"No Diagnostic". 2018-11-06T01:29:18.785Z|00061|bfd(monitor82)|INFO|Interface ovn-aded97-0 remote mult value 0 changed to 3 2018-11-06T01:29:18.785Z|00062|bfd(monitor82)|INFO|ovn-aded97-0: New remote min_rx. ... 2018-11-06T01:29:18.773Z|142111|bridge(ovs-vswitchd)|INFO|bridge br-int: deleted interface ovn-aded97-0 on port 65535 ... 2018-11-06T01:29:18.779Z|142115|dpif(ovs-vswitchd)|WARN|system@ovs-system: failed to add ovn-aded97-0 as port: Device or resource busy 2018-11-06T01:29:18.782Z|142116|bridge(ovs-vswitchd)|INFO|bridge br-int: added interface ovn-aded97-0 on port 65535 ... 2018-11-06T01:29:18.785Z|00064|bfd(monitor82)|WARN|ovn-aded97-0: Incorrect your_disc. ... Signed-off-by: Han Zhou --- ofproto/ofproto.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index bb020fe..dfcbc54 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -2314,18 +2314,20 @@ dealloc_ofp_port(struct ofproto *ofproto, ofp_port_t ofp_port) } } -/* Opens and returns a netdev for 'ofproto_port' in 'ofproto', or a null - * pointer if the netdev cannot be opened. On success, also fills in - * '*pp'. */ -static struct netdev * +/* Opens a netdev for 'ofproto_port' in 'ofproto' and set to p_netdev, + * or a null pointer if the netdev cannot be opened. On success, also + * fills in '*pp'. Returns 0 on success, or a positive error number. */ +static int ofport_open(struct ofproto *ofproto, struct ofproto_port *ofproto_port, - struct ofputil_phy_port *pp) + struct ofputil_phy_port *pp, + struct netdev **p_netdev) { enum netdev_flags flags; struct netdev *netdev; int error; + *p_netdev = NULL; error = netdev_open(ofproto_port->name, ofproto_port->type, &netdev); if (error) { VLOG_WARN_RL(&rl, "%s: ignoring port %s (%"PRIu32") because netdev %s " @@ -2333,15 +2335,22 @@ ofport_open(struct ofproto *ofproto, ofproto->name, ofproto_port->name, ofproto_port->ofp_port, ofproto_port->name, ovs_strerror(error)); - return NULL; + return 0; } if (ofproto_port->ofp_port == OFPP_NONE) { if (!strcmp(ofproto->name, ofproto_port->name)) { ofproto_port->ofp_port = OFPP_LOCAL; } else { - ofproto_port->ofp_port = alloc_ofp_port(ofproto, - ofproto_port->name); + ofp_port_t ofp_port = alloc_ofp_port(ofproto, + ofproto_port->name); + if (ofp_port == OFPP_NONE) { + VLOG_WARN_RL(&rl, "%s: failed to allocated ofp port number " + "for %s.", ofproto->name, ofproto_port->name); + netdev_close(netdev); + return ENOSPC; + } + ofproto_port->ofp_port = ofp_port; } } pp->port_no = ofproto_port->ofp_port; @@ -2356,7 +2365,8 @@ ofport_open(struct ofproto *ofproto, pp->curr_speed = netdev_features_to_bps(pp->curr, 0) / 1000; pp->max_speed = netdev_features_to_bps(pp->supported, 0) / 1000; - return netdev; + *p_netdev = netdev; + return 0; } /* Returns true if most fields of 'a' and 'b' are equal. Differences in name @@ -2623,9 +2633,11 @@ update_port(struct ofproto *ofproto, const char *name) COVERAGE_INC(ofproto_update_port); /* Fetch 'name''s location and properties from the datapath. */ - netdev = (!ofproto_port_query_by_name(ofproto, name, &ofproto_port) - ? ofport_open(ofproto, &ofproto_port, &pp) - : NULL); + if (ofproto_port_query_by_name(ofproto, name, &ofproto_port)) { + netdev = NULL; + } else { + error = ofport_open(ofproto, &ofproto_port, &pp, &netdev); + } if (netdev) { port = ofproto_get_port(ofproto, ofproto_port.ofp_port); @@ -2703,7 +2715,7 @@ init_ports(struct ofproto *p) ofp_to_u16(iface_hint->ofp_port)); } - netdev = ofport_open(p, &ofproto_port, &pp); + ofport_open(p, &ofproto_port, &pp, &netdev); if (netdev) { ofport_install(p, netdev, &pp); if (ofp_to_u16(ofproto_port.ofp_port) < p->max_ports) {