diff mbox series

[RFC,net-next,15/22] nexthop: Emit a notification when a nexthop group is reduced

Message ID 20200908091037.2709823-16-idosch@idosch.org
State RFC
Delegated to: David Miller
Headers show
Series nexthop: Add support for nexthop objects offload | expand

Commit Message

Ido Schimmel Sept. 8, 2020, 9:10 a.m. UTC
From: Ido Schimmel <idosch@nvidia.com>

When a single nexthop is deleted, the configuration of all the groups
using the nexthop is effectively modified. In this case, emit a
notification in the nexthop notification chain for each modified group
so that listeners would not need to keep track of which nexthops are
member in which groups.

In the rare cases where the notification fails, emit an error to the
kernel log.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 net/ipv4/nexthop.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

David Ahern Sept. 8, 2020, 3:33 p.m. UTC | #1
On 9/8/20 3:10 AM, Ido Schimmel wrote:
> From: Ido Schimmel <idosch@nvidia.com>
> 
> When a single nexthop is deleted, the configuration of all the groups
> using the nexthop is effectively modified. In this case, emit a
> notification in the nexthop notification chain for each modified group
> so that listeners would not need to keep track of which nexthops are
> member in which groups.
> 
> In the rare cases where the notification fails, emit an error to the
> kernel log.
> 
> Signed-off-by: Ido Schimmel <idosch@nvidia.com>
> ---
>  net/ipv4/nexthop.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
> index 0edc3e73d416..33f611bbce1f 100644
> --- a/net/ipv4/nexthop.c
> +++ b/net/ipv4/nexthop.c
> @@ -893,7 +893,7 @@ static void remove_nh_grp_entry(struct net *net, struct nh_grp_entry *nhge,
>  	struct nexthop *nhp = nhge->nh_parent;
>  	struct nexthop *nh = nhge->nh;
>  	struct nh_group *nhg, *newg;
> -	int i, j;
> +	int i, j, err;
>  
>  	WARN_ON(!nh);
>  
> @@ -941,6 +941,10 @@ static void remove_nh_grp_entry(struct net *net, struct nh_grp_entry *nhge,
>  	list_del(&nhge->nh_list);
>  	nexthop_put(nhge->nh);
>  
> +	err = call_nexthop_notifiers(net, NEXTHOP_EVENT_REPLACE, nhp, NULL);
> +	if (err)
> +		pr_err("Failed to replace nexthop group after nexthop deletion\n");

This should refer to the notifier failing since wrt nexthop code the
structs are ok. extack on the stack and logging that message would be
useful too (or have the users of the notifier log why it fails).

> +
>  	if (nlinfo)
>  		nexthop_notify(RTM_NEWNEXTHOP, nhp, nlinfo);
>  }
>
Ido Schimmel Sept. 11, 2020, 4:29 p.m. UTC | #2
On Tue, Sep 08, 2020 at 09:33:42AM -0600, David Ahern wrote:
> On 9/8/20 3:10 AM, Ido Schimmel wrote:
> > From: Ido Schimmel <idosch@nvidia.com>
> > 
> > When a single nexthop is deleted, the configuration of all the groups
> > using the nexthop is effectively modified. In this case, emit a
> > notification in the nexthop notification chain for each modified group
> > so that listeners would not need to keep track of which nexthops are
> > member in which groups.
> > 
> > In the rare cases where the notification fails, emit an error to the
> > kernel log.
> > 
> > Signed-off-by: Ido Schimmel <idosch@nvidia.com>
> > ---
> >  net/ipv4/nexthop.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
> > index 0edc3e73d416..33f611bbce1f 100644
> > --- a/net/ipv4/nexthop.c
> > +++ b/net/ipv4/nexthop.c
> > @@ -893,7 +893,7 @@ static void remove_nh_grp_entry(struct net *net, struct nh_grp_entry *nhge,
> >  	struct nexthop *nhp = nhge->nh_parent;
> >  	struct nexthop *nh = nhge->nh;
> >  	struct nh_group *nhg, *newg;
> > -	int i, j;
> > +	int i, j, err;
> >  
> >  	WARN_ON(!nh);
> >  
> > @@ -941,6 +941,10 @@ static void remove_nh_grp_entry(struct net *net, struct nh_grp_entry *nhge,
> >  	list_del(&nhge->nh_list);
> >  	nexthop_put(nhge->nh);
> >  
> > +	err = call_nexthop_notifiers(net, NEXTHOP_EVENT_REPLACE, nhp, NULL);
> > +	if (err)
> > +		pr_err("Failed to replace nexthop group after nexthop deletion\n");
> 
> This should refer to the notifier failing since wrt nexthop code the
> structs are ok. extack on the stack and logging that message would be
> useful too (or have the users of the notifier log why it fails).

'extack on the stack' idea is cool! I will do that

> 
> > +
> >  	if (nlinfo)
> >  		nexthop_notify(RTM_NEWNEXTHOP, nhp, nlinfo);
> >  }
> > 
>
diff mbox series

Patch

diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 0edc3e73d416..33f611bbce1f 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -893,7 +893,7 @@  static void remove_nh_grp_entry(struct net *net, struct nh_grp_entry *nhge,
 	struct nexthop *nhp = nhge->nh_parent;
 	struct nexthop *nh = nhge->nh;
 	struct nh_group *nhg, *newg;
-	int i, j;
+	int i, j, err;
 
 	WARN_ON(!nh);
 
@@ -941,6 +941,10 @@  static void remove_nh_grp_entry(struct net *net, struct nh_grp_entry *nhge,
 	list_del(&nhge->nh_list);
 	nexthop_put(nhge->nh);
 
+	err = call_nexthop_notifiers(net, NEXTHOP_EVENT_REPLACE, nhp, NULL);
+	if (err)
+		pr_err("Failed to replace nexthop group after nexthop deletion\n");
+
 	if (nlinfo)
 		nexthop_notify(RTM_NEWNEXTHOP, nhp, nlinfo);
 }