[2/2] net: sockets -- Don't spam log with known errors

Submitted by Cyrill Gorcunov on Sept. 27, 2018, 10:51 a.m.

Details

Message ID 20180927105137.31366-3-gorcunov@gmail.com
State New
Series "sockets: Placate logger when diag modules are missing"
Headers show

Commit Message

Cyrill Gorcunov Sept. 27, 2018, 10:51 a.m.
For example if diag module is not built then we should
not spam with error message but we will print an error
if only a particular socket is really used.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 criu/include/libnetlink.h |  2 +-
 criu/libnetlink.c         | 10 +++---
 criu/sockets.c            | 72 ++++++++++++++++++++++-----------------
 3 files changed, 46 insertions(+), 38 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/include/libnetlink.h b/criu/include/libnetlink.h
index bf2eb24740b0..f21a0e750337 100644
--- a/criu/include/libnetlink.h
+++ b/criu/include/libnetlink.h
@@ -6,7 +6,7 @@ 
 struct ns_id;
 extern int do_rtnl_req(int nl, void *req, int size,
 		int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *),
-		int (*error_callback)(int err, void *), struct ns_id *ns, void *);
+		int (*error_callback)(int err, struct ns_id *ns, void *), struct ns_id *ns, void *);
 
 extern int addattr_l(struct nlmsghdr *n, int maxlen, int type,
 		const void *data, int alen);
diff --git a/criu/libnetlink.c b/criu/libnetlink.c
index 2ce4a38262d4..60e98e3460dc 100644
--- a/criu/libnetlink.c
+++ b/criu/libnetlink.c
@@ -12,7 +12,7 @@ 
 
 static int nlmsg_receive(char *buf, int len,
 		int (*cb)(struct nlmsghdr *, struct ns_id *ns, void *),
-		int (*err_cb)(int, void *), struct ns_id *ns, void *arg)
+		int (*err_cb)(int, struct ns_id *, void *), struct ns_id *ns, void *arg)
 {
 	struct nlmsghdr *hdr;
 
@@ -22,7 +22,7 @@  static int nlmsg_receive(char *buf, int len,
 		if (hdr->nlmsg_type == NLMSG_DONE) {
 			int *len = (int *)NLMSG_DATA(hdr);
 			if (*len < 0)
-				return err_cb(*len, arg);
+				return err_cb(*len, ns, arg);
 			return 0;
 		}
 		if (hdr->nlmsg_type == NLMSG_ERROR) {
@@ -36,7 +36,7 @@  static int nlmsg_receive(char *buf, int len,
 			if (err->error == 0)
 				return 0;
 
-			return err_cb(err->error, arg);
+			return err_cb(err->error, ns, arg);
 		}
 		if (cb(hdr, ns, arg))
 			return -1;
@@ -45,7 +45,7 @@  static int nlmsg_receive(char *buf, int len,
 	return 1;
 }
 
-static int rtnl_return_err(int err, void *arg)
+static int rtnl_return_err(int err, struct ns_id *ns, void *arg)
 {
 	errno = -err;
 	pr_perror("ERROR %d reported by netlink", err);
@@ -54,7 +54,7 @@  static int rtnl_return_err(int err, void *arg)
 
 int do_rtnl_req(int nl, void *req, int size,
 		int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *),
-		int (*error_callback)(int err, void *), struct ns_id *ns, void *arg)
+		int (*error_callback)(int err, struct ns_id *ns, void *arg), struct ns_id *ns, void *arg)
 {
 	struct msghdr msg;
 	struct sockaddr_nl nladdr;
diff --git a/criu/sockets.c b/criu/sockets.c
index 510b84f6621a..a75beecea500 100644
--- a/criu/sockets.c
+++ b/criu/sockets.c
@@ -212,7 +212,7 @@  static int probe_recv_one(struct nlmsghdr *h, struct ns_id *ns, void *arg)
 	return -1;
 }
 
-static int probe_err(int err, void *arg)
+static int probe_err(int err, struct ns_id *ns, void *arg)
 {
 	int expected_err = *(int *)arg;
 
@@ -716,6 +716,7 @@  static int inet_receive_one(struct nlmsghdr *h, struct ns_id *ns, void *arg)
 
 static int do_collect_req(int nl, struct sock_diag_req *req, int size,
 		int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *),
+		int (*error_callback)(int err, struct ns_id *ns, void *),
 		struct ns_id *ns, void *arg)
 {
 	int tmp;
@@ -728,6 +729,25 @@  static int do_collect_req(int nl, struct sock_diag_req *req, int size,
 	return tmp;
 }
 
+static int collect_err(int err, struct ns_id *ns, void *arg)
+{
+	struct sock_diag_greq *gr = arg;
+	char family[32], proto[32];
+
+	/* Fedora 19 hack */
+	if (gr->family == AF_PACKET || gr->family == AF_NETLINK) {
+		if (ns->ns_pid != 0 || err == -ENOENT)
+			return 0;
+	}
+
+	pr_info("Sockects collect procedure family %s proto %s: %s\n",
+		socket_family_name(gr->family, family, sizeof(family)),
+		socket_proto_name(gr->protocol, proto, sizeof(proto)),
+		strerror(-err));
+
+	return err;
+}
+
 int collect_sockets(struct ns_id *ns)
 {
 	int err = 0, tmp;
@@ -746,7 +766,7 @@  int collect_sockets(struct ns_id *ns)
 	req.r.u.udiag_show	= UDIAG_SHOW_NAME | UDIAG_SHOW_VFS |
 				  UDIAG_SHOW_PEER | UDIAG_SHOW_ICONS |
 				  UDIAG_SHOW_RQLEN;
-	tmp = do_collect_req(nl, &req, sizeof(req), unix_receive_one, ns, NULL);
+	tmp = do_collect_req(nl, &req, sizeof(req), unix_receive_one, collect_err, ns, &req.r.u);
 	if (tmp)
 		err = tmp;
 
@@ -759,7 +779,7 @@  int collect_sockets(struct ns_id *ns)
 					(1 << TCP_FIN_WAIT1) | (1 << TCP_FIN_WAIT2) |
 					(1 << TCP_CLOSE_WAIT) | (1 << TCP_LAST_ACK) |
 					(1 << TCP_CLOSING) | (1 << TCP_SYN_SENT);
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
 	if (tmp)
 		err = tmp;
 
@@ -768,7 +788,7 @@  int collect_sockets(struct ns_id *ns)
 	req.r.i.sdiag_protocol	= IPPROTO_UDP;
 	req.r.i.idiag_ext	= 0;
 	req.r.i.idiag_states	= -1; /* All */
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
 	if (tmp)
 		err = tmp;
 
@@ -777,7 +797,7 @@  int collect_sockets(struct ns_id *ns)
 	req.r.i.sdiag_protocol	= IPPROTO_UDPLITE;
 	req.r.i.idiag_ext	= 0;
 	req.r.i.idiag_states	= -1; /* All */
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
 	if (tmp)
 		err = tmp;
 
@@ -786,12 +806,9 @@  int collect_sockets(struct ns_id *ns)
 	req.r.i.sdiag_protocol	= IPPROTO_RAW;
 	req.r.i.idiag_ext	= 0;
 	req.r.i.idiag_states	= -1; /* All */
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
-	if (tmp) {
-		pr_warn("The current kernel doesn't support ipv4 raw_diag module\n");
-		if (tmp != -ENOENT)
-			err = tmp;
-	}
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
+	if (tmp)
+		err = tmp;
 
 	/* Collect IPv6 TCP sockets */
 	req.r.i.sdiag_family	= AF_INET6;
@@ -802,7 +819,7 @@  int collect_sockets(struct ns_id *ns)
 					(1 << TCP_FIN_WAIT1) | (1 << TCP_FIN_WAIT2) |
 					(1 << TCP_CLOSE_WAIT) | (1 << TCP_LAST_ACK) |
 					(1 << TCP_CLOSING) | (1 << TCP_SYN_SENT);
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
 	if (tmp)
 		err = tmp;
 
@@ -811,7 +828,7 @@  int collect_sockets(struct ns_id *ns)
 	req.r.i.sdiag_protocol	= IPPROTO_UDP;
 	req.r.i.idiag_ext	= 0;
 	req.r.i.idiag_states	= -1; /* All */
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
 	if (tmp)
 		err = tmp;
 
@@ -820,7 +837,7 @@  int collect_sockets(struct ns_id *ns)
 	req.r.i.sdiag_protocol	= IPPROTO_UDPLITE;
 	req.r.i.idiag_ext	= 0;
 	req.r.i.idiag_states	= -1; /* All */
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
 	if (tmp)
 		err = tmp;
 
@@ -829,33 +846,24 @@  int collect_sockets(struct ns_id *ns)
 	req.r.i.sdiag_protocol	= IPPROTO_RAW;
 	req.r.i.idiag_ext	= 0;
 	req.r.i.idiag_states	= -1; /* All */
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
-	if (tmp) {
-		pr_warn("The current kernel doesn't support ipv6 raw_diag module\n");
-		if (tmp != -ENOENT)
-			err = tmp;
-	}
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
+	if (tmp)
+		err = tmp;
 
 	req.r.p.sdiag_family	= AF_PACKET;
 	req.r.p.sdiag_protocol	= 0;
 	req.r.p.pdiag_show	= PACKET_SHOW_INFO | PACKET_SHOW_MCLIST |
 					PACKET_SHOW_FANOUT | PACKET_SHOW_RING_CFG;
-	tmp = do_collect_req(nl, &req, sizeof(req), packet_receive_one, ns, NULL);
-	if (tmp) {
-		pr_warn("The current kernel doesn't support packet_diag\n");
-		if (ns->ns_pid == 0 || tmp != -ENOENT) /* Fedora 19 */
-			err = tmp;
-	}
+	tmp = do_collect_req(nl, &req, sizeof(req), packet_receive_one, collect_err, ns, &req.r.p);
+	if (tmp)
+		err = tmp;
 
 	req.r.n.sdiag_family	= AF_NETLINK;
 	req.r.n.sdiag_protocol	= NDIAG_PROTO_ALL;
 	req.r.n.ndiag_show	= NDIAG_SHOW_GROUPS;
-	tmp = do_collect_req(nl, &req, sizeof(req), netlink_receive_one, ns, NULL);
-	if (tmp) {
-		pr_warn("The current kernel doesn't support netlink_diag\n");
-		if (ns->ns_pid == 0 || tmp != -ENOENT) /* Fedora 19 */
-			err = tmp;
-	}
+	tmp = do_collect_req(nl, &req, sizeof(req), netlink_receive_one, collect_err, ns, &req.r.n);
+	if (tmp)
+		err = tmp;
 
 	/* don't need anymore */
 	close(nl);