From patchwork Tue Jul 26 14:33:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 652782 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3rzLGG012Gz9t1S for ; Wed, 27 Jul 2016 00:33:41 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 935B410B4A; Tue, 26 Jul 2016 07:33:40 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 9FEFB10B49 for ; Tue, 26 Jul 2016 07:33:39 -0700 (PDT) Received: from bar6.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 1B45A16216F for ; Tue, 26 Jul 2016 08:33:39 -0600 (MDT) X-ASG-Debug-ID: 1469543616-0b323703f95b3fe0001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar6.cudamail.com with ESMTP id M1p8a6GZvmTLU2YN (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 26 Jul 2016 08:33:36 -0600 (MDT) X-Barracuda-Envelope-From: cascardo@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx1-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 26 Jul 2016 14:33:36 -0000 Received-SPF: pass (mx1-pf2.cudamail.com: SPF record at _spf1.redhat.com designates 209.132.183.28 as permitted sender) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54A747F7A2; Tue, 26 Jul 2016 14:33:33 +0000 (UTC) Received: from indiana.gru.redhat.com (ovpn-116-130.phx2.redhat.com [10.3.116.130]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6QEXTIo005527 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 26 Jul 2016 10:33:31 -0400 Date: Tue, 26 Jul 2016 11:33:28 -0300 X-CudaMail-Envelope-Sender: cascardo@redhat.com From: Thadeu Lima de Souza Cascardo To: Daniele Di Proietto X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E2-725025134 X-CudaMail-DTE: 072616 X-CudaMail-Originating-IP: 209.132.183.28 Message-ID: <20160726143328.GP23554@indiana.gru.redhat.com> X-ASG-Orig-Subj: [##CM-E2-725025134##]Re: [ovs-dev] [RFC 4/5] dpctl: uses open_type when calling netdev_open References: <1468861225-8569-1-git-send-email-cascardo@redhat.com> <1468861225-8569-5-git-send-email-cascardo@redhat.com> <20160725165731.GM23554@indiana.gru.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.1 (2016-04-27) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 26 Jul 2016 14:33:33 +0000 (UTC) X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1469543616 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Cc: "dev@openvswitch.org" Subject: Re: [ovs-dev] [RFC 4/5] dpctl: uses open_type when calling netdev_open X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@openvswitch.org Sender: "dev" On Mon, Jul 25, 2016 at 11:03:29AM -0700, Daniele Di Proietto wrote: > 2016-07-25 9:57 GMT-07:00 Thadeu Lima de Souza Cascardo >: > > > On Fri, Jul 22, 2016 at 02:49:39PM -0700, Daniele Di Proietto wrote: > > > I would prefer if dpctl kept using the datapath types. The translation > > > from database types to datapath type should happen in ofproto, dpctl is > > > supposed to be used to interact with the datapath directly. > > > > > > What do you guys think? > > > > > > The rest of the series looks good to me as well. > > > > > > Thanks, > > > > > > Daniele > > > > > > > > Hi Cascardo, > > Thanks for the detailed analysis. The problem is that there are three > types: > > a) the database type > b) the port type in dpif-netdev > c) the netdev type > > I was assuming that b and c are always equal, but they're not. The only > case > when they're not equal is the "ovs-netdev" (or "ovs-dummy") port. > > I think we can easily remove this case and make b and c always equal > with the following changes: Well, we also have ofproto type. I had a different approach, in which I would use the netdev_type when doing the query. That broke tests too. The affected tests were just dpctl output shown to the user. But I would expect some breakage when ofproto_query also used the same type and vswitchd would see the database type and ofproto type as different and try to reconfigure the port. Then, I looked at your patch below and noticed that you do the opposite, you eliminate the open_type and only use it for the internal type. Then I thought that would break other cases. But dpif_netdev_port_add uses the netdev_type already. Hey... So, dpctl does see it as tap when I add an internal port. Which probably means ofproto_type is also tap. I guess we will have to fix that too. I am attaching my version of the patch here as well. Which of the 3 versions do you think I should send? The original one I sent will not require changes in the tests and also doesn't change behavior for the user output, so I would stick to it for now. Cascardo. ---8<--- ---8<--- > > ---8<--- > diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c > index 787851d..effa7e0 100644 > --- a/lib/dpif-netdev.c > +++ b/lib/dpif-netdev.c > @@ -941,7 +941,9 @@ create_dp_netdev(const char *name, const struct > dpif_class *class, > ovs_mutex_lock(&dp->port_mutex); > dp_netdev_set_nonpmd(dp); > > - error = do_add_port(dp, name, "internal", ODPP_LOCAL); > + error = do_add_port(dp, name, dpif_netdev_port_open_type(dp->class, > + "internal"), > + ODPP_LOCAL); > ovs_mutex_unlock(&dp->port_mutex); > if (error) { > dp_netdev_free(dp); > @@ -1129,7 +1131,7 @@ hash_port_no(odp_port_t port_no) > } > > static int > -port_create(const char *devname, const char *open_type, const char *type, > +port_create(const char *devname, const char *type, > odp_port_t port_no, struct dp_netdev_port **portp) > { > struct netdev_saved_flags *sf; > @@ -1142,7 +1144,7 @@ port_create(const char *devname, const char > *open_type, const char *type, > *portp = NULL; > > /* Open and validate network device. */ > - error = netdev_open(devname, open_type, &netdev); > + error = netdev_open(devname, type, &netdev); > if (error) { > return error; > } > @@ -1233,8 +1235,7 @@ do_add_port(struct dp_netdev *dp, const char > *devname, const char *type, > return EEXIST; > } > > - error = port_create(devname, dpif_netdev_port_open_type(dp->class, > type), > - type, port_no, &port); > + error = port_create(devname, type, port_no, &port); > if (error) { > return error; > } > root@diproiettod-dev:~/ovs# git diff > diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c > index 787851d..effa7e0 100644 > --- a/lib/dpif-netdev.c > +++ b/lib/dpif-netdev.c > @@ -941,7 +941,9 @@ create_dp_netdev(const char *name, const struct > dpif_class *class, > ovs_mutex_lock(&dp->port_mutex); > dp_netdev_set_nonpmd(dp); > > - error = do_add_port(dp, name, "internal", ODPP_LOCAL); > + error = do_add_port(dp, name, dpif_netdev_port_open_type(dp->class, > + "internal"), > + ODPP_LOCAL); > ovs_mutex_unlock(&dp->port_mutex); > if (error) { > dp_netdev_free(dp); > @@ -1129,7 +1131,7 @@ hash_port_no(odp_port_t port_no) > } > > static int > -port_create(const char *devname, const char *open_type, const char *type, > +port_create(const char *devname, const char *type, > odp_port_t port_no, struct dp_netdev_port **portp) > { > struct netdev_saved_flags *sf; > @@ -1142,7 +1144,7 @@ port_create(const char *devname, const char > *open_type, const char *type, > *portp = NULL; > > /* Open and validate network device. */ > - error = netdev_open(devname, open_type, &netdev); > + error = netdev_open(devname, type, &netdev); > if (error) { > return error; > } > @@ -1233,8 +1235,7 @@ do_add_port(struct dp_netdev *dp, const char > *devname, const char *type, > return EEXIST; > } > > - error = port_create(devname, dpif_netdev_port_open_type(dp->class, > type), > - type, port_no, &port); > + error = port_create(devname, type, port_no, &port); > if (error) { > return error; > } > ---8<--- > > With this incremental case 2 is covered, dpctl/show always shows the > datapath type. > (The incremental also requires some testsuite changes) > > For case 1 and 3 is just a matter of deciding if we want to support database > types (in addition to netdev) in dpctl. I would lean towards no: I find it > confusing > that both types are acceptable. > > That said, I feel like I'm nitpicking, dpctl is a tool used for debugging > and I think > we should do whatever comes easier. > > Thanks, > > Daniele > > Hi, Daniele. > > > > Thanks for the comment. > > > > The best example that breaks currently is the internal type on the netdev > > datapath. > > > > There are three scenarios in dpctl, and two of them are changed with this > > patch. > > > > 1) The user input type, given for add-if. In this particular case, the code > > would try to use the "internal" type, but thinks would break as the Linux > > internal type would not work for the netdev datapath. The user was > > expected to > > use "tap" instead. We the patch applied, either way should work. So we are > > not > > breaking behavior. > > > > 2) When the type is output to the user. The current patch does not change > > its > > behavior, which basically prints what we get from dpif_port_query. However, > > dpif-netdev uses a cache of the database type and returns that, not the > > netdev > > type. That could be changed, but then the output to the user would be the > > real > > dpif. Would that be acceptable? It could break scripts out there which > > look for > > internal. Or would dpctl do the reverse mapping? That would require some > > new > > code on the dpif level. > > > > > 3) Using the dpif_port.type in netdev_open. We could use the same > > alternative > > solution here as proposed for scenario 2. Make dpif_port_query return the > > real > > netdev type. This would require the new reverse mapping in order to be > > used also > > at the ofproto level, so ofproto_port_query uses the database type. > > > > I have a patch that changes dpif-netdev to return the netdev open type. > > However, > > as it broke dpctl output, I decided to provice this current patch instead, > > as I > > realized a lot more would be needed on other code, and we risked breaking > > a lot > > of behavior. > > > > I would keep this patch as is in the series, as it keeps behavior, and > > improves > > the case in add-if, without breaking it; and leave the dpif_port_query fix > > and > > reverse mapping to another day. > > > > What do you think? > > > > Regards. > > Cascardo. > > > > > > > 2016-07-18 10:00 GMT-07:00 Thadeu Lima de Souza Cascardo < > > > cascardo@redhat.com>: > > > > > > > dpctl uses a user or database defined type when calling netdev_open. > > > > Instead, it > > > > should use the type from dpif_port_open_type. Otherwise, when using the > > > > internal > > > > type, it could open it with that type instead of the correct one, which > > > > would be > > > > tap or dummy. > > > > --- > > > > lib/dpctl.c | 17 ++++++++++++----- > > > > 1 file changed, 12 insertions(+), 5 deletions(-) > > > > > > > > diff --git a/lib/dpctl.c b/lib/dpctl.c > > > > index 003602a..f896161 100644 > > > > --- a/lib/dpctl.c > > > > +++ b/lib/dpctl.c > > > > @@ -274,7 +274,8 @@ dpctl_add_if(int argc OVS_UNUSED, const char > > *argv[], > > > > } > > > > } > > > > > > > > - error = netdev_open(name, type, &netdev); > > > > + error = netdev_open(name, dpif_port_open_type(dpif_type(dpif), > > > > type), > > > > + &netdev); > > > > if (error) { > > > > dpctl_error(dpctl_p, error, "%s: failed to open network > > > > device", > > > > name); > > > > @@ -356,7 +357,8 @@ dpctl_set_if(int argc, const char *argv[], struct > > > > dpctl_params *dpctl_p) > > > > dpif_port_destroy(&dpif_port); > > > > > > > > /* Retrieve its existing configuration. */ > > > > - error = netdev_open(name, type, &netdev); > > > > + error = netdev_open(name, dpif_port_open_type(dpif_type(dpif), > > > > type), > > > > + &netdev); > > > > if (error) { > > > > dpctl_error(dpctl_p, error, "%s: failed to open network > > > > device", > > > > name); > > > > @@ -558,10 +560,13 @@ show_dpif(struct dpif *dpif, struct dpctl_params > > > > *dpctl_p) > > > > qsort(port_nos, n_port_nos, sizeof *port_nos, compare_port_nos); > > > > > > > > for (int i = 0; i < n_port_nos; i++) { > > > > + const char *type; > > > > if (dpif_port_query_by_number(dpif, port_nos[i], &dpif_port)) > > { > > > > continue; > > > > } > > > > > > > > + type = dpif_port_open_type(dpif_type(dpif), dpif_port.type); > > > > + > > > > dpctl_print(dpctl_p, "\tport %u: %s", > > > > dpif_port.port_no, dpif_port.name); > > > > > > > > @@ -570,7 +575,7 @@ show_dpif(struct dpif *dpif, struct dpctl_params > > > > *dpctl_p) > > > > > > > > dpctl_print(dpctl_p, " (%s", dpif_port.type); > > > > > > > > - error = netdev_open(dpif_port.name, dpif_port.type, > > &netdev); > > > > + error = netdev_open(dpif_port.name, type, &netdev); > > > > if (!error) { > > > > struct smap config; > > > > > > > > @@ -603,7 +608,7 @@ show_dpif(struct dpif *dpif, struct dpctl_params > > > > *dpctl_p) > > > > struct netdev_stats s; > > > > int error; > > > > > > > > - error = netdev_open(dpif_port.name, dpif_port.type, > > &netdev); > > > > + error = netdev_open(dpif_port.name, type, &netdev); > > > > if (error) { > > > > dpctl_print(dpctl_p, ", open failed (%s)", > > > > ovs_strerror(error)); > > > > @@ -891,6 +896,7 @@ get_in_port_netdev_from_key(struct dpif *dpif, > > const > > > > struct ofpbuf *key) > > > > struct dpif_port dpif_port; > > > > odp_port_t port_no; > > > > int error; > > > > + const char *type; > > > > > > > > port_no = ODP_PORT_C(nl_attr_get_u32(in_port_nla)); > > > > error = dpif_port_query_by_number(dpif, port_no, &dpif_port); > > > > @@ -898,7 +904,8 @@ get_in_port_netdev_from_key(struct dpif *dpif, > > const > > > > struct ofpbuf *key) > > > > goto out; > > > > } > > > > > > > > - netdev_open(dpif_port.name, dpif_port.type, &dev); > > > > + type = dpif_port_open_type(dpif_type(dpif), dpif_port.type); > > > > + netdev_open(dpif_port.name, type, &dev); > > > > dpif_port_destroy(&dpif_port); > > > > } > > > > > > > > -- > > > > 2.7.4 > > > > > > > > _______________________________________________ > > > > dev mailing list > > > > dev@openvswitch.org > > > > http://openvswitch.org/mailman/listinfo/dev > > > > > > > _______________________________________________ > > > dev mailing list > > > dev@openvswitch.org > > > http://openvswitch.org/mailman/listinfo/dev > > > _______________________________________________ > dev mailing list > dev@openvswitch.org > http://openvswitch.org/mailman/listinfo/dev Signed-off-by: Daniele Di Proietto diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 37c2631..19b1f87 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1437,11 +1437,12 @@ do_del_port(struct dp_netdev *dp, struct dp_netdev_port *port) } static void -answer_port_query(const struct dp_netdev_port *port, +answer_port_query(struct dp_netdev *dp OVS_UNUSED, const struct dp_netdev_port *port, struct dpif_port *dpif_port) { + const char *type = dpif_netdev_port_open_type(dp->class, port->type); dpif_port->name = xstrdup(netdev_get_name(port->netdev)); - dpif_port->type = xstrdup(port->type); + dpif_port->type = xstrdup(type); dpif_port->port_no = port->port_no; } @@ -1456,7 +1457,7 @@ dpif_netdev_port_query_by_number(const struct dpif *dpif, odp_port_t port_no, ovs_mutex_lock(&dp->port_mutex); error = get_port_by_number(dp, port_no, &port); if (!error && dpif_port) { - answer_port_query(port, dpif_port); + answer_port_query(dp, port, dpif_port); } ovs_mutex_unlock(&dp->port_mutex); @@ -1474,7 +1475,7 @@ dpif_netdev_port_query_by_name(const struct dpif *dpif, const char *devname, ovs_mutex_lock(&dp->port_mutex); error = get_port_by_name(dp, devname, &port); if (!error && dpif_port) { - answer_port_query(port, dpif_port); + answer_port_query(dp, port, dpif_port); } ovs_mutex_unlock(&dp->port_mutex);