[PATCH iproute2-next 2/2] dpll: warn about interrupted dumps

From
Petr Oros <hidden>
Date
2026-11-10 11:01:17
Reply to
Petr Oros, 2026-11-10
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 <redacted>
---
 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
Thread (3 messages) 3 messages, 1 author, last reply 6d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help