dpll: do not fail on interrupted dumps
Subsystems (3)
cover dpll: do not fail on interrupted dumps
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(-)
Signature · 1 line
2.56.0
PATCH 1/2 mnl_utils: add a dump helper for NLM_F_DUMP_INTR
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.
--- include/mnl_utils.h | 5 ++++ lib/mnl_utils.c | 58 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 7 deletions(-)
include/mnl_utils.h +5 -0
@@ -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);
lib/mnl_utils.c +51 -7
97 lines not on this page · raw message
Signature · 1 line
2.56.0
Re: [PATCH iproute2-next 1/2] mnl_utils: add a dump helper for NLM_F_DUMP_INTR
Quoted 25 lines · Petr Oros
The kernel sets
NLM_F_DUMP_INTRon 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, asrtnl_dump_filter()does for rtnetlink dumps.The receive loop is shared with
mnlu_socket_recv_run()andmnlu_gen_socket_sndrcv(), which behave as before.Reviewed-by Ivan Vecera <[email protected]>Signed-off-by Petr Oros <[email protected]>--- include/mnl_utils.h | 5 ++++ lib/mnl_utils.c | 58 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 7 deletions(-)
...
lib/mnl_utils.c int mnlu_socket_recv_run(struct mnl_socket *nl, unsigned int seq, void *buf, siz · line 147
Quoted 6 lines
lib/mnl_utils.c +2
-0@@ -120,6 +143,12 @@ int mnlu_socket_recv_run(struct mnl_socket *nl, unsigned int seq, void *buf, sizreturn 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.
PATCH 2/2 dpll: warn about interrupted dumps
In reply to Petr OrosPin 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.
--- dpll/dpll.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-)
dpll/dpll.c +23 -14
@@ -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 );
Signature · 1 line
2.56.0