]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
rtnetlink: Define rtnl_net_trylock().
authorKuniyuki Iwashima <kuniyu@amazon.com>
Mon, 21 Oct 2024 18:32:36 +0000 (11:32 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 29 Oct 2024 10:54:57 +0000 (11:54 +0100)
We will need the per-netns version of rtnl_trylock().

rtnl_net_trylock() calls __rtnl_net_lock() only when rtnl_trylock()
successfully holds RTNL.

When RTNL is removed, we will use mutex_trylock() for per-netns RTNL.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
include/linux/rtnetlink.h
net/core/rtnetlink.c

index 0e62918de63b377a8a1d65c279b36731c0c4632d..14b88f55192085def8f318c7913a76d5447b4975 100644 (file)
@@ -101,6 +101,7 @@ void __rtnl_net_lock(struct net *net);
 void __rtnl_net_unlock(struct net *net);
 void rtnl_net_lock(struct net *net);
 void rtnl_net_unlock(struct net *net);
+int rtnl_net_trylock(struct net *net);
 int rtnl_net_lock_cmp_fn(const struct lockdep_map *a, const struct lockdep_map *b);
 
 bool rtnl_net_is_locked(struct net *net);
@@ -132,6 +133,11 @@ static inline void rtnl_net_unlock(struct net *net)
        rtnl_unlock();
 }
 
+static inline int rtnl_net_trylock(struct net *net)
+{
+       return rtnl_trylock();
+}
+
 static inline void ASSERT_RTNL_NET(struct net *net)
 {
        ASSERT_RTNL();
index 194a81e5f6081a9b5387d283bce14dbad4adb639..dda8230fdfd4af847e5bf7fec023342f73746d5a 100644 (file)
@@ -210,6 +210,17 @@ void rtnl_net_unlock(struct net *net)
 }
 EXPORT_SYMBOL(rtnl_net_unlock);
 
+int rtnl_net_trylock(struct net *net)
+{
+       int ret = rtnl_trylock();
+
+       if (ret)
+               __rtnl_net_lock(net);
+
+       return ret;
+}
+EXPORT_SYMBOL(rtnl_net_trylock);
+
 static int rtnl_net_cmp_locks(const struct net *net_a, const struct net *net_b)
 {
        if (net_eq(net_a, net_b))