Message ID | 20210126174054.185084-1-edwin.peer@broadcom.com |
---|---|
State | New |
Headers | show |
Series | [iproute2-next,v2,1/2] iplink: print warning for missing VF data | expand |
On 1/26/21 10:40 AM, Edwin Peer wrote: > The kernel might truncate VF info in IFLA_VFINFO_LIST. Compare the > expected number of VFs in IFLA_NUM_VF to how many were found in the > list and warn accordingly. > > Signed-off-by: Edwin Peer <edwin.peer@broadcom.com> > --- > ip/ipaddress.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/ip/ipaddress.c b/ip/ipaddress.c > index 571346b15cc3..0bbcee2b3bb2 100644 > --- a/ip/ipaddress.c > +++ b/ip/ipaddress.c > @@ -922,6 +922,7 @@ int print_linkinfo(struct nlmsghdr *n, void *arg) > const char *name; > unsigned int m_flag = 0; > SPRINT_BUF(b1); > + bool truncated_vfs = false; > > if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK) > return 0; > @@ -1199,15 +1200,18 @@ int print_linkinfo(struct nlmsghdr *n, void *arg) > > if ((do_link || show_details) && tb[IFLA_VFINFO_LIST] && tb[IFLA_NUM_VF]) { > struct rtattr *i, *vflist = tb[IFLA_VFINFO_LIST]; > - int rem = RTA_PAYLOAD(vflist); > + int rem = RTA_PAYLOAD(vflist), count = 0; > > open_json_array(PRINT_JSON, "vfinfo_list"); > for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { > open_json_object(NULL); > print_vfinfo(fp, ifi, i); > close_json_object(); > + count++; > } > close_json_array(PRINT_JSON, NULL); > + if (count != rta_getattr_u32(tb[IFLA_NUM_VF])) > + truncated_vfs = true; > } > > if (tb[IFLA_PROP_LIST]) { > @@ -1228,6 +1232,9 @@ int print_linkinfo(struct nlmsghdr *n, void *arg) > > print_string(PRINT_FP, NULL, "%s", "\n"); > fflush(fp); > + /* prettier here if stderr and stdout go to the same place */ > + if (truncated_vfs) > + fprintf(stderr, "Truncated VF list: %s\n", name); > return 1; > } > > LGTM. I think it should go to the main branch versus -next.
diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 571346b15cc3..0bbcee2b3bb2 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -922,6 +922,7 @@ int print_linkinfo(struct nlmsghdr *n, void *arg) const char *name; unsigned int m_flag = 0; SPRINT_BUF(b1); + bool truncated_vfs = false; if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK) return 0; @@ -1199,15 +1200,18 @@ int print_linkinfo(struct nlmsghdr *n, void *arg) if ((do_link || show_details) && tb[IFLA_VFINFO_LIST] && tb[IFLA_NUM_VF]) { struct rtattr *i, *vflist = tb[IFLA_VFINFO_LIST]; - int rem = RTA_PAYLOAD(vflist); + int rem = RTA_PAYLOAD(vflist), count = 0; open_json_array(PRINT_JSON, "vfinfo_list"); for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { open_json_object(NULL); print_vfinfo(fp, ifi, i); close_json_object(); + count++; } close_json_array(PRINT_JSON, NULL); + if (count != rta_getattr_u32(tb[IFLA_NUM_VF])) + truncated_vfs = true; } if (tb[IFLA_PROP_LIST]) { @@ -1228,6 +1232,9 @@ int print_linkinfo(struct nlmsghdr *n, void *arg) print_string(PRINT_FP, NULL, "%s", "\n"); fflush(fp); + /* prettier here if stderr and stdout go to the same place */ + if (truncated_vfs) + fprintf(stderr, "Truncated VF list: %s\n", name); return 1; }
The kernel might truncate VF info in IFLA_VFINFO_LIST. Compare the expected number of VFs in IFLA_NUM_VF to how many were found in the list and warn accordingly. Signed-off-by: Edwin Peer <edwin.peer@broadcom.com> --- ip/ipaddress.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)