Skip to contentSkip to conversation

net: store netdevs in an xarray

PATCH Superseded Jakub Kicinski 5 participants 15 messages Jul 22, 2023 – Jul 25, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

cover net: store netdevs in an xarray

One of more annoying developer experience gaps we have in netlink is iterating over netdevs. It's painful. Add an xarray to make it trivial.

Jakub Kicinski (2):
net: store netdevs in an xarray
net: convert some netlink netdev iterators to depend on the xarray

 include/linux/netdevice.h   |  3 ++
 include/net/net_namespace.h |  4 +-
 net/core/dev.c              | 82 ++++++++++++++++++++++++-------------
 net/core/netdev-genl.c      | 37 ++++-------------
 net/ethtool/netlink.c       | 56 ++++++-------------------
 net/ethtool/tunnels.c       | 73 ++++++++++++---------------------
 6 files changed, 108 insertions(+), 147 deletions(-)
Signature · 1 line
2.41.0
author maintainer
#1 lore raw

PATCH 1/2 net: store netdevs in an xarray

Iterating over the netdev hash table for netlink dumps is hard. Dumps are done in "chunks" so we need to save the position after each chunk, so we know where to restart from. Because netdevs are stored in a hash table we remember which bucket we were in and how many devices we dumped.

Since we don't hold any locks across the "chunks" - devices may come and go while we're dumping. If that happens we may miss a device (if device is deleted from the bucket we were in). We indicate to user space that this may have happened by setting NLM_F_DUMP_INTR. User space is supposed to dump again (I think) if it sees that. Somehow I doubt most user space gets this right..

To illustrate let's look at an example:

System state:
start: # [A, B, C]
del: B # [A, C]

with the hash table we may dump [A, B], missing C completely even tho it existed both before and after the "del B".

Add an xarray and use it to allocate ifindexes. This way we can iterate ifindexes in order, without the worry that we'll skip one. We may still generate a dump of a state which "never existed", for example for a set of values and sequence of ops:

System state:

  start:       # [A, B]
  add:  C      # [A, C, B]
  del:  B      # [A, C]

we may generate a dump of [A], if C got an index between A and B. System has never been in such state. But I'm 90% sure that's perfectly fine, important part is that we can't _miss_ devices which exist before and after. User space which wants to mirror kernel's state subscribes to notifications and does periodic dumps so it will know that C exists from the notification about its creation or from the next dump (next dump is _guaranteed_ to include C, if it doesn't get removed).

To avoid any perf regressions keep the hash table for now. Most net namespaces have very few devices and microbenchmarking 1M lookups on Skylake I get the following results (not counting loopback to number of devs):

 #devs | hash |  xa  | delta
    2  | 18.3 | 20.1 | + 9.8%
   16  | 18.3 | 20.1 | + 9.5%
   64  | 18.3 | 26.3 | +43.8%
  128  | 20.4 | 26.3 | +28.6%
  256  | 20.0 | 26.4 | +32.1%
 1024  | 26.6 | 26.7 | + 0.2%
 8192  |541.3 | 33.5 | -93.8%

No surprises since the hash table has 256 entries.
The microbenchmark scans indexes in order, if the pattern is more random xa starts to win at 512 devices already. But that's a lot of devices, in practice.

---
 include/net/net_namespace.h |  4 +-
 net/core/dev.c              | 82 ++++++++++++++++++++++++-------------
 2 files changed, 57 insertions(+), 29 deletions(-)
include/net/net_namespace.h +3 -1
index 78beaa765c73..9f6add96de2d 100644
@@ -42,6 +42,7 @@
 #include <linux/idr.h>
 #include <linux/skbuff.h>
 #include <linux/notifier.h>
+#include <linux/xarray.h>
 
 struct user_namespace;
 struct proc_dir_entry;
@@ -69,7 +70,7 @@ struct net {
 	atomic_t		dev_unreg_count;
 
 	unsigned int		dev_base_seq;	/* protected by rtnl_mutex */
-	int			ifindex;
+	u32			ifindex;
 
 	spinlock_t		nsid_lock;
 	atomic_t		fnhe_genid;
@@ -110,6 +111,7 @@ struct net {
 
 	struct hlist_head 	*dev_name_head;
 	struct hlist_head	*dev_index_head;
+	struct xarray		dev_by_index;
 	struct raw_notifier_head	netdev_chain;
 
 	/* Note that @hash_mix can be read millions times per second,
net/core/dev.c +54 -28

149 lines not on this page · raw message

Signature · 1 line
2.41.0
author maintainer
#13 lore raw

PATCH 2/2 net: convert some netlink netdev iterators to depend on the xarray

In reply to Jakub Kicinski

Reap the benefits of easier iteration thanks to the xarray. Convert just the genetlink ones, those are easier to test.

---
 include/linux/netdevice.h |  3 ++
 net/core/netdev-genl.c    | 37 +++++---------------
 net/ethtool/netlink.c     | 59 ++++++++-----------------------
 net/ethtool/tunnels.c     | 73 +++++++++++++++------------------------
 4 files changed, 52 insertions(+), 120 deletions(-)
include/linux/netdevice.h +3 -0
index 3800d0479698..1159ca17e246 100644
@@ -3014,6 +3014,9 @@ extern rwlock_t				dev_base_lock;		/* Device list lock */
 			if (netdev_master_upper_dev_get_rcu(slave) == (bond))
 #define net_device_entry(lh)	list_entry(lh, struct net_device, dev_list)
 
+#define for_each_netdev_dump(net, d, ifindex)				\
+	xa_for_each_start(&(net)->dev_by_index, (ifindex), (d), (ifindex))
+
 static inline struct net_device *next_net_device(struct net_device *dev)
 {
 	struct list_head *lh;
net/core/netdev-genl.c +8 -29
index 65ef4867fc49..797c813c7c77 100644
@@ -101,43 +101,22 @@ int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 {
 	struct net *net = sock_net(skb->sk);
 	struct net_device *netdev;
-	int idx = 0, s_idx;
-	int h, s_h;
-	int err;
-
-	s_h = cb->args[0];
-	s_idx = cb->args[1];
+	int err = 0;
 
 	rtnl_lock();
-
-	for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
-		struct hlist_head *head;
-
-		idx = 0;
-		head = &net->dev_index_head[h];
-		hlist_for_each_entry(netdev, head, index_hlist) {
-			if (idx < s_idx)
-				goto cont;
-			err = netdev_nl_dev_fill(netdev, skb,
-						 NETLINK_CB(cb->skb).portid,
-						 cb->nlh->nlmsg_seq, 0,
-						 NETDEV_CMD_DEV_GET);
-			if (err < 0)
-				break;
-cont:
-			idx++;
-		}
+	for_each_netdev_dump(net, netdev, cb->args[0]) {
+		err = netdev_nl_dev_fill(netdev, skb,
+					 NETLINK_CB(cb->skb).portid,
+					 cb->nlh->nlmsg_seq, 0,
+					 NETDEV_CMD_DEV_GET);
+		if (err < 0)
+			break;
 	}
-
 	rtnl_unlock();
 
 	if (err != -EMSGSIZE)
 		return err;
 
-	cb->args[1] = idx;
-	cb->args[0] = h;
-	cb->seq = net->dev_base_seq;
-
 	return skb->len;
 }
 
net/ethtool/netlink.c +14 -45

93 lines not on this page · raw message

net/ethtool/tunnels.c +27 -46

91 lines not on this page · raw message

Signature · 1 line
2.41.0
author maintainer
#2 lore raw
In reply to Jakub Kicinski
Quoted 8 lines · On Fri, 21 Jul 2023 18:42:36 -0700 Jakub Kicinski wrote:
 #devs | hash |  xa  | delta
    2  | 18.3 | 20.1 | + 9.8%
   16  | 18.3 | 20.1 | + 9.5%
   64  | 18.3 | 26.3 | +43.8%
  128  | 20.4 | 26.3 | +28.6%
  256  | 20.0 | 26.4 | +32.1%
 1024  | 26.6 | 26.7 | + 0.2%
 8192  |541.3 | 33.5 | -93.8%
          ^^^^^^ ^^^^^^

I failed to clarify these columns are msecs of runtime.

maintainer
#3 lore raw
In reply to Jakub Kicinski
Quoted 40 lines · Jakub Kicinski

Iterating over the netdev hash table for netlink dumps is hard. Dumps are done in "chunks" so we need to save the position after each chunk, so we know where to restart from. Because netdevs are stored in a hash table we remember which bucket we were in and how many devices we dumped.

Since we don't hold any locks across the "chunks" - devices may come and go while we're dumping. If that happens we may miss a device (if device is deleted from the bucket we were in). We indicate to user space that this may have happened by setting NLM_F_DUMP_INTR. User space is supposed to dump again (I think) if it sees that. Somehow I doubt most user space gets this right..

To illustrate let's look at an example:

System state:
start: # [A, B, C]
del: B # [A, C]

with the hash table we may dump [A, B], missing C completely even tho it existed both before and after the "del B".

Add an xarray and use it to allocate ifindexes. This way we can iterate ifindexes in order, without the worry that we'll skip one. We may still generate a dump of a state which "never existed", for example for a set of values and sequence of ops:

System state:

  start:       # [A, B]
  add:  C      # [A, C, B]
  del:  B      # [A, C]

we may generate a dump of [A], if C got an index between A and B. System has never been in such state. But I'm 90% sure that's perfectly fine, important part is that we can't _miss_ devices which exist before and after. User space which wants to mirror kernel's state subscribes to notifications and does periodic dumps so it will know that C exists from the notification about its creation or from the next dump (next dump is _guaranteed_ to include C, if it doesn't get removed).

Quoted 4 lines

To avoid any perf regressions keep the hash table for now. Most net namespaces have very few devices and microbenchmarking 1M lookups on Skylake I get the following results (not counting loopback to number of devs):

A possibly dumb question: why using an xarray over a plain list? It looks like the idea is to additionally use xarray for device lookup beyond for dumping?

WRT the above, have you considered instead replacing dev_name_head with an rhashtable? (and add the mentioned list)

Cheers,

Paolo

Reviewed-by on the v1 series
#14 lore raw
In reply to Jakub Kicinski
Quoted 7 lines · Jakub Kicinski

One of more annoying developer experience gaps we have in netlink is iterating over netdevs. It's painful. Add an xarray to make it trivial.

Jakub Kicinski (2):
net: store netdevs in an xarray
net: convert some netlink netdev iterators to depend on the xarray

author maintainer
#4 lore raw
In reply to Paolo Abeni
Quoted 1 line · On Mon, 24 Jul 2023 10:18:04 +0200 Paolo Abeni wrote:

A possibly dumb question: why using an xarray over a plain list?

We need to drop the lock during the walk. So for a list we'd need to either
- add explicit iteration "cursor" or
- suffer O(n) for insertion + O(n^2) for restart?

Or there's a easier way to do it?
The cursor is not the worst option, I guess, a bit less intuitive and harder to clean up on error, but doable?

Quoted 2 lines

It looks like the idea is to additionally use xarray for device lookup beyond for dumping?

I was measuring it to find out if we can delete the hash table without anyone noticing, but it's not really the motivation.

Quoted 2 lines

WRT the above, have you considered instead replacing dev_name_head with an rhashtable? (and add the mentioned list)

The main motivation is ease of iteration for netlink dumps.

I'll admit that my understanding of rhashtable is superficial but I don't think it's possible to do consistent dumps with it. Even if it supported "cursors" (which I'm not sure it does) a rhash could rearrange buckets and mess the order up. The comment on rhltable_walk_enter() says:

* For a completely stable walk you should construct your own data
* structure outside the hash table.

Given the iteration process is controlled by user space trying to constrain a rhash also used by the fast path to get consistent dumps seems risky.

Adding Herbert and Neil to keep me honest.

maintainer
#5 lore raw
Quoted 4 lines · Jakub Kicinski
Quoted 1 line · On Mon, 24 Jul 2023 10:18:04 +0200 Paolo Abeni wrote:

A possibly dumb question: why using an xarray over a plain list?

We need to drop the lock during the walk.

I should have looked more closely to patch 2/2.

Quoted 3 lines

So for a list we'd need
to either
- add explicit iteration "cursor" or

Would a cursor require acquiring a netdev reference? If so it looks problematic (an evil/buggy userspace could keep such reference held for an unbounded amount of time).

I agree xarray looks a better solution.

I still have some minor doubts WRT the 'missed device' scenario you described in the commit message. What if the user-space is doing 'create the new one before deleting the old one' with the assumption that at least one of old/new is always reported in dumps? Is that a too bold assumption?

Quoted 2 lines

I was measuring it to find out if we can delete the hash table without anyone noticing, but it's not really the motivation.

Understood. I though about rhashtable with the opposite assumption :) So no need to discuss such option further, I guess.

Cheers,

Paolo

author maintainer
#6 lore raw
Quoted 8 lines · On Mon, 24 Jul 2023 18:23:03 +0200 Paolo Abeni wrote:
Quoted 4 lines · Jakub Kicinski
Quoted 1 line · On Mon, 24 Jul 2023 10:18:04 +0200 Paolo Abeni wrote:

A possibly dumb question: why using an xarray over a plain list?

We need to drop the lock during the walk.

I should have looked more closely to patch 2/2.

Quoted 7 lines
Quoted 3 lines

So for a list we'd need
to either
- add explicit iteration "cursor" or

Would a cursor require acquiring a netdev reference? If so it looks problematic (an evil/buggy userspace could keep such reference held for an unbounded amount of time).

I was thinking we can add a cursor which looks like:

struct netdev_list_node {
	struct list head_list;
	bool is_a_device;
};

then iteration can put this struct into its dump state and insert *itself* into the device list. All iterations will then have to:

	struct netdev_list_node *lnode;

	list_for_each_entry... lnode) {
		/* skip cursors inserted into the list */
		if (!lnode->is_a_device)
			continue;
		netdev = containerof(lnode);

		...
	}

But then we need to add some code to .start and .stop callbacks and make sure the "cursor" is removed if someone closes the socket half way thru the dump.

Quoted 1 line

I agree xarray looks a better solution.

I do think xarray is the simplest solution.

Quoted 5 lines

I still have some minor doubts WRT the 'missed device' scenario you described in the commit message. What if the user-space is doing 'create the new one before deleting the old one' with the assumption that at least one of old/new is always reported in dumps? Is that a too bold assumption?

The problem is kinda theoretical in the first place because it assumes ifindexes got wrapped so that the new netdev comes "before" the old in the xarray. Which would require adding and removing 2B netdevs, assuming one add+remove takes 10 usec (impossibly fast), wrapping ifindex would take 68 years.

And if that's not enough we can make the iteration index ulong (i.e. something separate from ifindex as ifindex is hardwired to 31b by uAPI).

author maintainer
#7 lore raw
Quoted 11 lines · On Mon, 24 Jul 2023 10:27:41 -0700 Jakub Kicinski wrote:
Quoted 5 lines

I still have some minor doubts WRT the 'missed device' scenario you described in the commit message. What if the user-space is doing 'create the new one before deleting the old one' with the assumption that at least one of old/new is always reported in dumps? Is that a too bold assumption?

The problem is kinda theoretical in the first place because it assumes ifindexes got wrapped so that the new netdev comes "before" the old in the xarray. Which would require adding and removing 2B netdevs, assuming one add+remove takes 10 usec (impossibly fast), wrapping ifindex would take 68 years.

I guess the user space can shoot itself in the foot by selecting the lower index for the new device explicitly.

Quoted 3 lines

And if that's not enough we can make the iteration index ulong (i.e. something separate from ifindex as ifindex is hardwired to 31b by uAPI).

We can get the create, delete ordering with this or the list, but the inverse theoretical case of delete, create ordering can't be covered. A case where user wants to make sure at most one device is visible.

I'm not sure how much we should care about this. The basic hash table had the very real problem of hiding devices which were there *before and after* the dump.

Inconsistent info on devices which were created / deleted *during* the dump seems to me like something that's best handled with notifications.

I'm not sure whether we should set the inconsistency mark on the dump when del/add operation happened in the meantime either, as the probability that the user space will care is minuscule.

LMK what you think.

#12 lore raw
In reply to Jakub Kicinski
Quoted 64 lines · Jakub Kicinski

Iterating over the netdev hash table for netlink dumps is hard. Dumps are done in "chunks" so we need to save the position after each chunk, so we know where to restart from. Because netdevs are stored in a hash table we remember which bucket we were in and how many devices we dumped.

Since we don't hold any locks across the "chunks" - devices may come and go while we're dumping. If that happens we may miss a device (if device is deleted from the bucket we were in). We indicate to user space that this may have happened by setting NLM_F_DUMP_INTR. User space is supposed to dump again (I think) if it sees that. Somehow I doubt most user space gets this right..

To illustrate let's look at an example:

System state:
start: # [A, B, C]
del: B # [A, C]

with the hash table we may dump [A, B], missing C completely even tho it existed both before and after the "del B".

Add an xarray and use it to allocate ifindexes. This way we can iterate ifindexes in order, without the worry that we'll skip one. We may still generate a dump of a state which "never existed", for example for a set of values and sequence of ops:

System state:

  start:       # [A, B]
  add:  C      # [A, C, B]
  del:  B      # [A, C]

we may generate a dump of [A], if C got an index between A and B. System has never been in such state. But I'm 90% sure that's perfectly fine, important part is that we can't _miss_ devices which exist before and after. User space which wants to mirror kernel's state subscribes to notifications and does periodic dumps so it will know that C exists from the notification about its creation or from the next dump (next dump is _guaranteed_ to include C, if it doesn't get removed).

To avoid any perf regressions keep the hash table for now. Most net namespaces have very few devices and microbenchmarking 1M lookups on Skylake I get the following results (not counting loopback to number of devs):

 #devs | hash |  xa  | delta
    2  | 18.3 | 20.1 | + 9.8%
   16  | 18.3 | 20.1 | + 9.5%
   64  | 18.3 | 26.3 | +43.8%
  128  | 20.4 | 26.3 | +28.6%
  256  | 20.0 | 26.4 | +32.1%
 1024  | 26.6 | 26.7 | + 0.2%
 8192  |541.3 | 33.5 | -93.8%

No surprises since the hash table has 256 entries.
The microbenchmark scans indexes in order, if the pattern is more random xa starts to win at 512 devices already. But that's a lot of devices, in practice.

---
 include/net/net_namespace.h |  4 +-
 net/core/dev.c              | 82 ++++++++++++++++++++++++-------------
 2 files changed, 57 insertions(+), 29 deletions(-)

<...>

net/core/dev.c int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, · line 9595

Quoted 7 lines
net/core/dev.c +7 -0
+	if (!ifindex)
+		err = xa_alloc_cyclic(&net->dev_by_index, &ifindex, NULL,
+				      xa_limit_31b, &net->ifindex, GFP_KERNEL);
+	else
+		err = xa_insert(&net->dev_by_index, ifindex, NULL, GFP_KERNEL);
+	if (err)
+		return err;

Please pay attention that xa_alloc_cyclic() returns 1 if the allocation succeeded after wrapping. So the more accurate check is "if (err < 0) ..."

Thanks

maintainer
#8 lore raw
In reply to Jakub Kicinski
Quoted 28 lines · Jakub Kicinski
Quoted 11 lines · On Mon, 24 Jul 2023 10:27:41 -0700 Jakub Kicinski wrote:
Quoted 5 lines

I still have some minor doubts WRT the 'missed device' scenario you described in the commit message. What if the user-space is doing 'create the new one before deleting the old one' with the assumption that at least one of old/new is always reported in dumps? Is that a too bold assumption?

The problem is kinda theoretical in the first place because it assumes ifindexes got wrapped so that the new netdev comes "before" the old in the xarray. Which would require adding and removing 2B netdevs, assuming one add+remove takes 10 usec (impossibly fast), wrapping ifindex would take 68 years.

I guess the user space can shoot itself in the foot by selecting the lower index for the new device explicitly.

Quoted 3 lines

And if that's not enough we can make the iteration index ulong (i.e. something separate from ifindex as ifindex is hardwired to 31b by uAPI).

We can get the create, delete ordering with this or the list, but the inverse theoretical case of delete, create ordering can't be covered. A case where user wants to make sure at most one device is visible.

I'm not sure how much we should care about this. The basic hash table had the very real problem of hiding devices which were there *before and after* the dump.

Quoted 6 lines

Inconsistent info on devices which were created / deleted *during* the dump seems to me like something that's best handled with notifications.

I'm not sure whether we should set the inconsistency mark on the dump when del/add operation happened in the meantime either, as the probability that the user space will care is minuscule.

You convinced me the 'missed device' scenario is not very relevant.

The cursor with the dummy placeholder looks error-prone and/or too invasive to me.

I'm fine with this approach.

Thanks!

Paolo

author maintainer
#9 lore raw
Quoted 15 lines · On Tue, 25 Jul 2023 13:11:50 +0200 Paolo Abeni wrote:
Quoted 8 lines

We can get the create, delete ordering with this or the list, but the inverse theoretical case of delete, create ordering can't be covered. A case where user wants to make sure at most one device is visible.

I'm not sure how much we should care about this. The basic hash table had the very real problem of hiding devices which were there *before and after* the dump.

Quoted 6 lines

Inconsistent info on devices which were created / deleted *during* the dump seems to me like something that's best handled with notifications.

I'm not sure whether we should set the inconsistency mark on the dump when del/add operation happened in the meantime either, as the probability that the user space will care is minuscule.

Quoted 6 lines

You convinced me the 'missed device' scenario is not very relevant.

The cursor with the dummy placeholder looks error-prone and/or too invasive to me.

I'm fine with this approach.

I'll post a v2 with the fix Leon pointed out.

But do feel free to change your mind.

It seems like a problem where there's no perfect solution but there are multiple non-perfect ones, each with its advantages and disadvantages.

#10 lore raw
In reply to Jakub Kicinski
Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 24 Jul 2023 10:27:41 -0700 Jakub Kicinski wrote:
Quoted 5 lines

I still have some minor doubts WRT the 'missed device' scenario you described in the commit message. What if the user-space is doing 'create the new one before deleting the old one' with the assumption that at least one of old/new is always reported in dumps? Is that a too bold assumption?

Quoted 8 lines
Quoted 5 lines

The problem is kinda theoretical in the first place because it assumes ifindexes got wrapped so that the new netdev comes "before" the old in the xarray. Which would require adding and removing 2B netdevs, assuming one add+remove takes 10 usec (impossibly fast), wrapping ifindex would take 68 years.

I guess the user space can shoot itself in the foot by selecting the lower index for the new device explicitly.

Or just moving devices between netns?

Scenario 1:
- create lots of devices in netns A, last ifindex is 100 (call it dummy100)
- netns B isn't creating many devices, last ifindex is 8
- move dummy100 from netns A to netns B, it keeps ifindex=100
- create a device in netns B, it gets ifindex=9 even though we already have a device with ifindex=100

Scenario 2:
- create lots of devices in netns A, last ifindex is 100
- delete devices with ifindex 10..80 from A
- move a device with ifindex=20 into netns A, it keeps ifindex=20
- we have a new device in netns A with a smaller ifindex than the max

I think with this patch we could still see states that never existed, if both a low ifindex and then a high ifindex are created during the dump. We could see high ifindex without low ifindex being listed, if the dump was already past the low id. Or if we delete one at a low ifindex then create one at a high ifindex, we could see both devices listed in the dump when they never both existed at the same time.

Quoted 12 lines
Quoted 3 lines

And if that's not enough we can make the iteration index ulong (i.e. something separate from ifindex as ifindex is hardwired to 31b by uAPI).

We can get the create, delete ordering with this or the list, but the inverse theoretical case of delete, create ordering can't be covered. A case where user wants to make sure at most one device is visible.

I'm not sure how much we should care about this. The basic hash table had the very real problem of hiding devices which were there *before and after* the dump.

Quoted 6 lines

Inconsistent info on devices which were created / deleted *during* the dump seems to me like something that's best handled with notifications.

I'm not sure whether we should set the inconsistency mark on the dump when del/add operation happened in the meantime either, as the probability that the user space will care is minuscule.

The inconsistent dump mark may be more relevant for changes in device properties than link creation/removal. If the MTU on 2 devices changes while the dump is running (one low ifindex, one high ifindex), we'll see the old MTU for the first device and the new MTU for the 2nd. Or by adding/removing bridge ports while the dump runs, I can make it look like bridge0 has mulitple ports with the same port_no.

I don't know how likely those cases are, but if they happen I think they'd be more confusing than a missing/extra device.

Signature · 1 line
Sabrina
author maintainer
#11 lore raw
Quoted 26 lines · On Tue, 25 Jul 2023 19:54:43 +0200 Sabrina Dubroca wrote:
Quoted 12 lines
Quoted 3 lines

And if that's not enough we can make the iteration index ulong (i.e. something separate from ifindex as ifindex is hardwired to 31b by uAPI).

We can get the create, delete ordering with this or the list, but the inverse theoretical case of delete, create ordering can't be covered. A case where user wants to make sure at most one device is visible.

I'm not sure how much we should care about this. The basic hash table had the very real problem of hiding devices which were there *before and after* the dump.

Quoted 6 lines

Inconsistent info on devices which were created / deleted *during* the dump seems to me like something that's best handled with notifications.

I'm not sure whether we should set the inconsistency mark on the dump when del/add operation happened in the meantime either, as the probability that the user space will care is minuscule.

The inconsistent dump mark may be more relevant for changes in device properties than link creation/removal. If the MTU on 2 devices changes while the dump is running (one low ifindex, one high ifindex), we'll see the old MTU for the first device and the new MTU for the 2nd. Or by adding/removing bridge ports while the dump runs, I can make it look like bridge0 has mulitple ports with the same port_no.

Quoted 2 lines

I don't know how likely those cases are, but if they happen I think they'd be more confusing than a missing/extra device.

I believe that for netdevs dev_base_seq_inc() is used to indicate a change. It's only called when listing / unlisting devices so the changes to device config are already not covered :(