Netdev List
 help / color / mirror / Atom feed
* [PATCH iproute2-next 0/2] dpll: do not fail on interrupted dumps
@ 2026-11-10 11:00 Petr Oros
  2026-11-10 11:01 ` [PATCH iproute2-next 1/2] mnl_utils: add a dump helper for NLM_F_DUMP_INTR Petr Oros
  2026-11-10 11:01 ` [PATCH iproute2-next 2/2] dpll: warn about interrupted dumps Petr Oros
  0 siblings, 2 replies; 4+ messages in thread
From: Petr Oros @ 2026-11-10 11:00 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Stephen Hemminger, Ivan Vecera, Jiri Pirko,
	Petr Oros

A dpll device or pin dump that races with a registration or an
unregistration ends today as a failed command with a part of the list
on the output. This series makes the tool behave the way ip does in the
same situation. The whole dump is printed and a warning on stderr says
that it may be inconsistent.

The handling is added to mnl_utils as a separate helper that a caller
has to ask for, so the other users of mnlu_gen_socket keep their
current behaviour and can be converted one by one later. The helper
only reports the interruption. Whether to repeat the dump or to warn
is left to the caller, and dpll warns.

Petr Oros (2):
  mnl_utils: add a dump helper for NLM_F_DUMP_INTR
  dpll: warn about interrupted dumps

 dpll/dpll.c         | 37 ++++++++++++++++++-----------
 include/mnl_utils.h |  5 ++++
 lib/mnl_utils.c     | 58 +++++++++++++++++++++++++++++++++++++++------
 3 files changed, 79 insertions(+), 21 deletions(-)

-- 
2.56.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH iproute2-next 1/2] mnl_utils: add a dump helper for NLM_F_DUMP_INTR
  2026-11-10 11:00 [PATCH iproute2-next 0/2] dpll: do not fail on interrupted dumps Petr Oros
@ 2026-11-10 11:01 ` Petr Oros
  2026-11-18 22:58   ` David Ahern
  2026-11-10 11:01 ` [PATCH iproute2-next 2/2] dpll: warn about interrupted dumps Petr Oros
  1 sibling, 1 reply; 4+ messages in thread
From: Petr Oros @ 2026-11-10 11:01 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Stephen Hemminger, Ivan Vecera, Jiri Pirko,
	Petr Oros

The kernel sets NLM_F_DUMP_INTR on a dump message when the dumped
objects changed between two parts of the dump, so the result can miss an
object or list it twice. mnl_cb_run2() answers the flag with EINTR on
the first such message. mnlu_gen_socket_sndrcv() then prints "kernel
answers: Interrupted system call" and returns with the rest of the dump
still queued in the socket. The caller has passed a part of the objects
to its callback by then and cannot tell an interrupted dump from a
request that failed.

Add mnlu_gen_socket_sndrcv_dump(). It clears the flag in every received
message before the callbacks run, reads the dump to its end and tells
the caller through a bool that the dump was interrupted. The caller can
then repeat the request on the same socket or warn the user, as
rtnl_dump_filter() does for rtnetlink dumps.

The receive loop is shared with mnlu_socket_recv_run() and
mnlu_gen_socket_sndrcv(), which behave as before.

Reviewed-by: Ivan Vecera <ivecera@redhat.com>
Signed-off-by: Petr Oros <poros@redhat.com>
---
 include/mnl_utils.h |  5 ++++
 lib/mnl_utils.c     | 58 +++++++++++++++++++++++++++++++++++++++------
 2 files changed, 56 insertions(+), 7 deletions(-)

diff --git a/include/mnl_utils.h b/include/mnl_utils.h
index 4df9e398e59165..82c26f05742ce3 100644
--- a/include/mnl_utils.h
+++ b/include/mnl_utils.h
@@ -2,6 +2,8 @@
 #ifndef __MNL_UTILS_H__
 #define __MNL_UTILS_H__ 1
 
+#include <stdbool.h>
+
 struct mnlu_gen_socket {
 	struct mnl_socket *nl;
 	char *buf;
@@ -22,6 +24,9 @@ struct nlmsghdr *mnlu_gen_socket_cmd_prepare(struct mnlu_gen_socket *nlg,
 					     uint8_t cmd, uint16_t flags);
 int mnlu_gen_socket_sndrcv(struct mnlu_gen_socket *nlg, const struct nlmsghdr *nlh,
 			   mnl_cb_t data_cb, void *data);
+int mnlu_gen_socket_sndrcv_dump(struct mnlu_gen_socket *nlg,
+				const struct nlmsghdr *nlh,
+				mnl_cb_t data_cb, void *data, bool *intr);
 
 struct mnl_socket *mnlu_socket_open(int bus);
 int mnl_add_nl_group(struct mnl_socket *nl, unsigned int group);
diff --git a/lib/mnl_utils.c b/lib/mnl_utils.c
index 43b4cd1a9e40d4..4b971797777cb3 100644
--- a/lib/mnl_utils.c
+++ b/lib/mnl_utils.c
@@ -102,8 +102,29 @@ static mnl_cb_t mnlu_cb_array[NLMSG_MIN_TYPE] = {
 	[NLMSG_OVERRUN]	= mnlu_cb_noop,
 };
 
-int mnlu_socket_recv_run(struct mnl_socket *nl, unsigned int seq, void *buf, size_t buf_size,
-			 mnl_cb_t cb, void *data)
+/* mnl_cb_run2() fails with EINTR on the first message with NLM_F_DUMP_INTR
+ * and leaves the rest of the dump in the socket. Clear the flag, so that
+ * the dump is read to its end, and tell the caller that it was there.
+ */
+static bool mnlu_dump_intr_clear(void *buf, size_t len)
+{
+	struct nlmsghdr *nlh = buf;
+	bool intr = false;
+	int rem = len;
+
+	for (; mnl_nlmsg_ok(nlh, rem); nlh = mnl_nlmsg_next(nlh, &rem)) {
+		if (nlh->nlmsg_flags & NLM_F_DUMP_INTR) {
+			nlh->nlmsg_flags &= ~NLM_F_DUMP_INTR;
+			intr = true;
+		}
+	}
+
+	return intr;
+}
+
+static int __mnlu_socket_recv_run(struct mnl_socket *nl, unsigned int seq,
+				  void *buf, size_t buf_size,
+				  mnl_cb_t cb, void *data, bool *intr)
 {
 	unsigned int portid = mnl_socket_get_portid(nl);
 	int err;
@@ -112,6 +133,8 @@ int mnlu_socket_recv_run(struct mnl_socket *nl, unsigned int seq, void *buf, siz
 		err = mnl_socket_recvfrom(nl, buf, buf_size);
 		if (err <= 0)
 			break;
+		if (intr)
+			*intr |= mnlu_dump_intr_clear(buf, err);
 		err = mnl_cb_run2(buf, err, seq, portid,
 				  cb, data, mnlu_cb_array,
 				  ARRAY_SIZE(mnlu_cb_array));
@@ -120,6 +143,12 @@ int mnlu_socket_recv_run(struct mnl_socket *nl, unsigned int seq, void *buf, siz
 	return err;
 }
 
+int mnlu_socket_recv_run(struct mnl_socket *nl, unsigned int seq, void *buf, size_t buf_size,
+			 mnl_cb_t cb, void *data)
+{
+	return __mnlu_socket_recv_run(nl, seq, buf, buf_size, cb, data, NULL);
+}
+
 static int ctrl_attrs_cb(const struct nlattr *attr, void *data)
 {
 	int type = mnl_attr_get_type(attr);
@@ -242,20 +271,29 @@ struct nlmsghdr *mnlu_gen_socket_cmd_prepare(struct mnlu_gen_socket *nlg,
 					    nlg->version);
 }
 
-int mnlu_gen_socket_sndrcv(struct mnlu_gen_socket *nlg, const struct nlmsghdr *nlh,
-			   mnl_cb_t data_cb, void *data)
+/* Like mnlu_gen_socket_sndrcv(), for a dump request. A dump the kernel
+ * marked as interrupted is read to its end and reported in @intr. The
+ * objects passed to @data_cb can then be incomplete or duplicated and it
+ * is up to the caller to repeat the dump or to warn the user.
+ */
+int mnlu_gen_socket_sndrcv_dump(struct mnlu_gen_socket *nlg,
+				const struct nlmsghdr *nlh,
+				mnl_cb_t data_cb, void *data, bool *intr)
 {
 	int err;
 
+	if (intr)
+		*intr = false;
+
 	err = mnl_socket_sendto(nlg->nl, nlh, nlh->nlmsg_len);
 	if (err < 0) {
 		perror("Failed to send data");
 		return -errno;
 	}
 
-	err = mnlu_socket_recv_run(nlg->nl, nlh->nlmsg_seq, nlg->buf,
-				   MNL_SOCKET_BUFFER_SIZE,
-				   data_cb, data);
+	err = __mnlu_socket_recv_run(nlg->nl, nlh->nlmsg_seq, nlg->buf,
+				     MNL_SOCKET_BUFFER_SIZE,
+				     data_cb, data, intr);
 	if (err < 0) {
 		fprintf(stderr, "kernel answers: %s\n", strerror(errno));
 		return -errno;
@@ -263,6 +301,12 @@ int mnlu_gen_socket_sndrcv(struct mnlu_gen_socket *nlg, const struct nlmsghdr *n
 	return 0;
 }
 
+int mnlu_gen_socket_sndrcv(struct mnlu_gen_socket *nlg, const struct nlmsghdr *nlh,
+			   mnl_cb_t data_cb, void *data)
+{
+	return mnlu_gen_socket_sndrcv_dump(nlg, nlh, data_cb, data, NULL);
+}
+
 int mnlu_gen_socket_recv_run(struct mnlu_gen_socket *nlg, mnl_cb_t cb,
 			     void *data)
 {
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH iproute2-next 2/2] dpll: warn about interrupted dumps
  2026-11-10 11:00 [PATCH iproute2-next 0/2] dpll: do not fail on interrupted dumps Petr Oros
  2026-11-10 11:01 ` [PATCH iproute2-next 1/2] mnl_utils: add a dump helper for NLM_F_DUMP_INTR Petr Oros
@ 2026-11-10 11:01 ` Petr Oros
  1 sibling, 0 replies; 4+ messages in thread
From: Petr Oros @ 2026-11-10 11:01 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Stephen Hemminger, Ivan Vecera, Jiri Pirko,
	Petr Oros

Pin and device dumps are printed while they are read, one object per
netlink message. When the kernel marks a dump with NLM_F_DUMP_INTR,
because a device or a pin was registered or unregistered while the dump
was in progress, the tool stops at the marked message with "kernel
answers: Interrupted system call" and exit code 1. With -j the output
is then a valid JSON document that holds only the objects printed up to
that point, so a script that ignores the exit code works with a
truncated list.

Read such a dump to its end with mnlu_gen_socket_sndrcv_dump() and
print the warning ip prints in this case, "Dump was interrupted and may
be inconsistent.". The exit code stays 0, as every object the kernel
sent is there.

Reviewed-by: Ivan Vecera <ivecera@redhat.com>
Signed-off-by: Petr Oros <poros@redhat.com>
---
 dpll/dpll.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/dpll/dpll.c b/dpll/dpll.c
index 60404e134d0a50..5828e78f738eac 100644
--- a/dpll/dpll.c
+++ b/dpll/dpll.c
@@ -606,6 +606,26 @@ static int dpll_cmd(struct dpll *dpll, int argc, char **argv)
 	return -ENOENT;
 }
 
+/* Devices and pins registered or unregistered while a dump is in progress
+ * can be missing from it or be there twice, which the kernel reports with
+ * NLM_F_DUMP_INTR. Print the whole dump and warn the user, as ip does.
+ */
+static int dpll_dump(struct dpll *dpll, uint8_t cmd, mnl_cb_t cb, void *data)
+{
+	struct nlmsghdr *nlh;
+	bool intr;
+	int err;
+
+	nlh = mnlu_gen_socket_cmd_prepare(&dpll->nlg, cmd,
+					  NLM_F_REQUEST | NLM_F_ACK |
+					  NLM_F_DUMP);
+	err = mnlu_gen_socket_sndrcv_dump(&dpll->nlg, nlh, cb, data, &intr);
+	if (!err && intr)
+		pr_err("Dump was interrupted and may be inconsistent.\n");
+
+	return err;
+}
+
 static int dpll_init(struct dpll *dpll)
 {
 	int err;
@@ -1222,17 +1242,12 @@ static int cmd_device_show_id(struct dpll *dpll, __u32 id,
 static int cmd_device_show_dump(struct dpll *dpll,
 				struct dpll_device_filter *filter)
 {
-	struct nlmsghdr *nlh;
 	int err;
 
-	nlh = mnlu_gen_socket_cmd_prepare(&dpll->nlg, DPLL_CMD_DEVICE_GET,
-					  NLM_F_REQUEST | NLM_F_ACK |
-						  NLM_F_DUMP);
-
 	open_json_array(PRINT_JSON, "device");
 
-	err = mnlu_gen_socket_sndrcv(&dpll->nlg, nlh, cmd_device_show_dump_cb,
-				     filter);
+	err = dpll_dump(dpll, DPLL_CMD_DEVICE_GET, cmd_device_show_dump_cb,
+			filter);
 	if (err < 0) {
 		pr_err("Failed to dump devices\n");
 		close_json_array(PRINT_JSON, NULL);
@@ -1961,17 +1976,11 @@ static int cmd_pin_show_id(struct dpll *dpll, __u32 id,
 static int cmd_pin_show_dump(struct dpll *dpll,
 			     struct dpll_pin_filter *filter)
 {
-	struct nlmsghdr *nlh;
 	int err;
 
-	nlh = mnlu_gen_socket_cmd_prepare(&dpll->nlg, DPLL_CMD_PIN_GET,
-					  NLM_F_REQUEST | NLM_F_ACK |
-						  NLM_F_DUMP);
-
 	open_json_array(PRINT_JSON, "pin");
 
-	err = mnlu_gen_socket_sndrcv(&dpll->nlg, nlh, cmd_pin_show_dump_cb,
-				     filter);
+	err = dpll_dump(dpll, DPLL_CMD_PIN_GET, cmd_pin_show_dump_cb, filter);
 	if (err < 0) {
 		pr_err("Failed to dump pins\n");
 		close_json_array(PRINT_JSON, NULL);
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2-next 1/2] mnl_utils: add a dump helper for NLM_F_DUMP_INTR
  2026-11-10 11:01 ` [PATCH iproute2-next 1/2] mnl_utils: add a dump helper for NLM_F_DUMP_INTR Petr Oros
@ 2026-11-18 22:58   ` David Ahern
  0 siblings, 0 replies; 4+ messages in thread
From: David Ahern @ 2026-11-18 22:58 UTC (permalink / raw)
  To: Petr Oros, netdev; +Cc: Stephen Hemminger, Ivan Vecera, Jiri Pirko

On 11/10/26 5:01 AM, Petr Oros wrote:
> The kernel sets NLM_F_DUMP_INTR on a dump message when the dumped
> objects changed between two parts of the dump, so the result can miss an
> object or list it twice. mnl_cb_run2() answers the flag with EINTR on
> the first such message. mnlu_gen_socket_sndrcv() then prints "kernel
> answers: Interrupted system call" and returns with the rest of the dump
> still queued in the socket. The caller has passed a part of the objects
> to its callback by then and cannot tell an interrupted dump from a
> request that failed.
> 
> Add mnlu_gen_socket_sndrcv_dump(). It clears the flag in every received
> message before the callbacks run, reads the dump to its end and tells
> the caller through a bool that the dump was interrupted. The caller can
> then repeat the request on the same socket or warn the user, as
> rtnl_dump_filter() does for rtnetlink dumps.
> 
> The receive loop is shared with mnlu_socket_recv_run() and
> mnlu_gen_socket_sndrcv(), which behave as before.
> 
> Reviewed-by: Ivan Vecera <ivecera@redhat.com>
> Signed-off-by: Petr Oros <poros@redhat.com>
> ---
>  include/mnl_utils.h |  5 ++++
>  lib/mnl_utils.c     | 58 +++++++++++++++++++++++++++++++++++++++------
>  2 files changed, 56 insertions(+), 7 deletions(-)
> 

...

> @@ -120,6 +143,12 @@ int mnlu_socket_recv_run(struct mnl_socket *nl, unsigned int seq, void *buf, siz
>  	return err;
>  }
>  
> +int mnlu_socket_recv_run(struct mnl_socket *nl, unsigned int seq, void *buf, size_t buf_size,
> +			 mnl_cb_t cb, void *data)

fixed the line length and applied the set to iproute2-next.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-18 22:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-10 11:00 [PATCH iproute2-next 0/2] dpll: do not fail on interrupted dumps Petr Oros
2026-11-10 11:01 ` [PATCH iproute2-next 1/2] mnl_utils: add a dump helper for NLM_F_DUMP_INTR Petr Oros
2026-11-18 22:58   ` David Ahern
2026-11-10 11:01 ` [PATCH iproute2-next 2/2] dpll: warn about interrupted dumps Petr Oros

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox