public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
To: Ido Schimmel <idosch@mellanox.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel@savoirfairelinux.com,
	"David S. Miller" <davem@davemloft.net>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>, Scott Feldman <sfeldma@gmail.com>,
	Jiri Pirko <jiri@resnulli.us>,
	nikolay@cumulusnetworks.com, Elad Raz <eladr@mellanox.com>
Subject: Re: [RFC PATCH net-next 1/2] net: bridge: add switchdev attr for port bridging
Date: Wed, 09 Mar 2016 17:58:22 -0500	[thread overview]
Message-ID: <87k2lbb6nl.fsf@ketchup.mtl.sfl> (raw)
In-Reply-To: <20160309214214.GA4865@colbert.idosch.org>

Hi Ido,

Ido Schimmel <idosch@mellanox.com> writes:

> Wed, Mar 09, 2016 at 07:42:47PM IST, vivien.didelot@savoirfairelinux.com wrote:
>>Add a new SWITCHDEV_ATTR_ID_PORT_BRIDGE_IF switchdev attribute which is
>>set before adding a port to a bridge and deleting a port from a bridge.
>>
>>The main purpose for this attribute is to provide switchdev users a
>>simple and common way to retrieve bridging information, instead of
>>implementing complex notifier blocks to listen to global netdev events.
>>
>>We can also imagine a switchdev user returning an error different from
>>-EOPNOTSUPP in the prepare phase to prevent a port from being bridged.
>
> I don't really understand the motivation for this change. We are already
> doing all these stuff with the notifiers and it's pretty
> straight-forward.
>
> In fact, I believe using an existing mechanism instead of introducing
> more switchdev hooks is more elegant. This RFC only deals with bridge,
> but you'll have to do the same for team, bond and vlan devices. And
> you'll probably place the hooks in the exact locations where the
> notifiers are called from anyway.
>
>>
>>Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
>>---
>> include/net/switchdev.h |  2 ++
>> net/bridge/br_if.c      | 27 +++++++++++++++++++++++++++
>> 2 files changed, 29 insertions(+)
>>
>>diff --git a/include/net/switchdev.h b/include/net/switchdev.h
>>index d451122..65f8514 100644
>>--- a/include/net/switchdev.h
>>+++ b/include/net/switchdev.h
>>@@ -46,6 +46,7 @@ enum switchdev_attr_id {
>> 	SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
>> 	SWITCHDEV_ATTR_ID_PORT_STP_STATE,
>> 	SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS,
>>+	SWITCHDEV_ATTR_ID_PORT_BRIDGE_IF,
>> 	SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME,
>> 	SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
>> };
>>@@ -58,6 +59,7 @@ struct switchdev_attr {
>> 		struct netdev_phys_item_id ppid;	/* PORT_PARENT_ID */
>> 		u8 stp_state;				/* PORT_STP_STATE */
>> 		unsigned long brport_flags;		/* PORT_BRIDGE_FLAGS */
>>+		bool join;				/* PORT_BRIDGE_IF */
>> 		u32 ageing_time;			/* BRIDGE_AGEING_TIME */
>> 		bool vlan_filtering;			/* BRIDGE_VLAN_FILTERING */
>> 	} u;
>>diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
>>index a73df33..105b9fd 100644
>>--- a/net/bridge/br_if.c
>>+++ b/net/bridge/br_if.c
>>@@ -28,6 +28,24 @@
>> 
>> #include "br_private.h"
>> 
>>+static int switchdev_bridge_if(struct net_device *dev, struct net_bridge *br,
>>+			       bool join)
>>+{
>>+	struct switchdev_attr attr = {
>>+		.orig_dev = br->dev,
>
> This should be just 'dev', since you need to know for which stacked
> device on top of the port this was called for. This also means you'll
> have to call netdev_master_upper_dev_get() from within your driver if
> you want to limit the number of VLAN filtering bridges (for example).
> However, since this is called before bridge dev and dev itself are
> linked, you'll get NULL.
>
>>+		.id = SWITCHDEV_ATTR_ID_PORT_BRIDGE_IF,
>>+		.flags = SWITCHDEV_F_SKIP_EOPNOTSUPP,
>>+		.u.join = join,
>>+	};
>>+	int err;
>>+
>>+	err = switchdev_port_attr_set(dev, &attr);
>>+	if (err && err != -EOPNOTSUPP)
>>+		return err;
>>+
>>+	return 0;
>>+}
>>+
>> /*
>>  * Determine initial path cost based on speed.
>>  * using recommendations from 802.1d standard
>>@@ -297,6 +315,10 @@ static void del_nbp(struct net_bridge_port *p)
>> 	br_netpoll_disable(p);
>> 
>> 	call_rcu(&p->rcu, destroy_nbp_rcu);
>>+
>>+	if (switchdev_bridge_if(dev, br, false))
>>+		br_warn(br, "error unbridging port %u(%s)\n",
>>+			(unsigned int) p->port_no, dev->name);
>> }
>> 
>> /* Delete bridge device */
>>@@ -347,6 +369,11 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,
>> {
>> 	int index;
>> 	struct net_bridge_port *p;
>>+	int err;
>>+
>>+	err = switchdev_bridge_if(dev, br, true);
>
> If you look at br_add_if() - where new_nbp() is called from - then
> you'll see that you aren't rollbacking this operation in case of error.
> Same for subsequent errors in this function I believe.
>
>>+	if (err)
>>+		return ERR_PTR(err);
>> 
>> 	index = find_portno(br);
>> 	if (index < 0)
>>-- 
>>2.7.2
>>
>
> Maybe this is something we'll have to do in the future, but for now I
> think we are OK with the notifiers. :)
>
> Thanks Vivien!

I didn't have the big picture for team, bond and vlan devices as well.

I can drop this RFC then. Thanks for the details!

    Vivien

  reply	other threads:[~2016-03-09 22:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-09 17:42 [RFC PATCH net-next 0/2] net: switchdev: add attribute for port bridging Vivien Didelot
2016-03-09 17:42 ` [RFC PATCH net-next 1/2] net: bridge: add switchdev attr " Vivien Didelot
2016-03-09 19:26   ` Sergei Shtylyov
2016-03-09 21:42   ` Ido Schimmel
2016-03-09 22:58     ` Vivien Didelot [this message]
2016-03-09 17:42 ` [RFC PATCH net-next 2/2] net: dsa: support SWITCHDEV_ATTR_ID_PORT_BRIDGE_IF Vivien Didelot
2016-03-09 18:32   ` Andrew Lunn
2016-03-09 19:24     ` Jiri Pirko
2016-03-09 22:15       ` Vivien Didelot
2016-03-09 19:32     ` Vivien Didelot
2016-03-09 20:07       ` Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k2lbb6nl.fsf@ketchup.mtl.sfl \
    --to=vivien.didelot@savoirfairelinux.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=eladr@mellanox.com \
    --cc=f.fainelli@gmail.com \
    --cc=idosch@mellanox.com \
    --cc=jiri@resnulli.us \
    --cc=kernel@savoirfairelinux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@cumulusnetworks.com \
    --cc=sfeldma@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox