Netdev List
 help / color / mirror / Atom feed
From: Petr Oros <poros@redhat.com>
To: netdev@vger.kernel.org
Cc: David Ahern <dsahern@kernel.org>,
	Stephen Hemminger <stephen@networkplumber.org>,
	Ivan Vecera <ivecera@redhat.com>, Jiri Pirko <jiri@resnulli.us>,
	Petr Oros <poros@redhat.com>
Subject: [PATCH iproute2-next 2/2] dpll: warn about interrupted dumps
Date: Tue, 10 Nov 2026 12:01:01 +0100	[thread overview]
Message-ID: <20261110110101.2155953-3-poros@redhat.com> (raw)
In-Reply-To: <20261110110101.2155953-1-poros@redhat.com>

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


      parent reply	other threads:[~2026-11-10 11:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Petr Oros [this message]

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=20261110110101.2155953-3-poros@redhat.com \
    --to=poros@redhat.com \
    --cc=dsahern@kernel.org \
    --cc=ivecera@redhat.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /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