[CRIU] [PATCH v2 6/9] show: UNIX sockets queue support

Kinsbursky Stanislav skinsbursky at openvz.org
Wed Feb 29 08:07:11 EST 2012


Based on xemul@ patches.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>

---
 cr-show.c         |   54 ++++++++++++++++++++++++++++++++---------------------
 include/sockets.h |    1 +
 sockets.c         |   29 +++++++++++++++++++++++++++-
 3 files changed, 61 insertions(+), 23 deletions(-)

diff --git a/cr-show.c b/cr-show.c
index dd3cb2f..e1977fc 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -5,6 +5,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <string.h>
+#include <ctype.h>
 
 #include <fcntl.h>
 
@@ -30,7 +31,7 @@
 
 
 #define PR_SYMBOL(sym)				\
-	((sym < 32 || sym > 126) ? '.' : sym)
+	(isprint(sym) ? sym : '.')
 
 #define pr_regs4(s, n1, n2, n3, n4)	\
 	pr_info("%8s: %16lx "		\
@@ -148,6 +149,29 @@ static void show_vma(int fd_vma)
 	}
 }
 
+void print_data(unsigned long addr, unsigned char *data, size_t size)
+{
+	int i, j;
+
+	for (i = 0; i < size; i+= 16) {
+		pr_info("%16lx: ", addr + i);
+		for (j = 0; j < 8; j++)
+			pr_info("%02x ", data[i +  j]);
+		pr_info(" ");
+		for (j = 8; j < 16; j++)
+			pr_info("%02x ", data[i +  j]);
+
+		pr_info(" |");
+		for (j = 0; j < 8; j++)
+			pr_info("%c ", PR_SYMBOL(data[i + j]));
+		pr_info(" ");
+		for (j = 8; j < 16; j++)
+			pr_info("%c ", PR_SYMBOL(data[i + j]));
+
+		pr_info("|\n");
+	}
+}
+
 static void show_pages(int fd_pages, bool show_content)
 {
 	pr_img_head(CR_FD_PAGES);
@@ -155,32 +179,13 @@ static void show_pages(int fd_pages, bool show_content)
 	if (show_content) {
 		while (1) {
 			struct page_entry e;
-			unsigned long addr;
-			int i, j;
 
 			if (read_img(fd_pages, &e) < 0)
 				break;
 			if (final_page_entry(&e))
 				break;
 
-			addr = e.va;
-			for (i = 0; i < PAGE_IMAGE_SIZE; i+= 16) {
-				pr_info("%16lx: ", addr + i);
-				for (j = 0; j < 8; j++)
-					pr_info("%02x ", e.data[i +  j]);
-				pr_info(" ");
-				for (j = 8; j < 16; j++)
-					pr_info("%02x ", e.data[i +  j]);
-
-				pr_info(" |");
-				for (j = 0; j < 8; j++)
-					pr_info("%c ", PR_SYMBOL(e.data[i + j]));
-				pr_info(" ");
-				for (j = 8; j < 16; j++)
-					pr_info("%c ", PR_SYMBOL(e.data[i + j]));
-
-				pr_info("|\n");
-			}
+			print_data(e.va, e.data, PAGE_IMAGE_SIZE);
 			pr_info("\n                  --- End of page ---\n\n");
 		}
 	} else {
@@ -504,6 +509,9 @@ static int cr_parse_file(struct cr_options *opts)
 	case INETSK_MAGIC:
 		show_inetsk(fd);
 		break;
+	case SK_QUEUES_MAGIC:
+		show_sk_queues(fd);
+		break;
 	case ITIMERS_MAGIC:
 		show_itimers(fd);
 		break;
@@ -551,6 +559,10 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
 	if (ret)
 		goto out;
 
+	ret = show_sk_queues(cr_fdset->fds[CR_FD_SK_QUEUES]);
+	if (ret)
+		goto out;
+
 	close_cr_fdset(&cr_fdset);
 
 	ret = try_show_namespaces(pid);
diff --git a/include/sockets.h b/include/sockets.h
index f9f6690..960b918 100644
--- a/include/sockets.h
+++ b/include/sockets.h
@@ -29,5 +29,6 @@ extern int collect_sockets(void);
 extern int prepare_sockets(int pid);
 extern void show_unixsk(int fd);
 extern void show_inetsk(int fd);
+extern int show_sk_queues(int fd);
 
 #endif /* CR_SOCKETS_H__ */
diff --git a/sockets.c b/sockets.c
index a8e58b0..c2cbbd6 100644
--- a/sockets.c
+++ b/sockets.c
@@ -196,8 +196,8 @@ static void show_one_unix(char *act, const struct unix_sk_desc *sk)
 
 static void show_one_unix_img(const char *act, const struct unix_sk_entry *e)
 {
-	pr_debug("\t%s: fd %d type %d state %d name %d bytes\n",
-		act, e->fd, e->type, e->state, e->namelen);
+	pr_info("\t%s: id %u fd %d type %d state %d name %d bytes\n",
+		act, e->id, e->fd, e->type, e->state, e->namelen);
 }
 
 static int can_dump_inet_sk(const struct inet_sk_desc *sk)
@@ -1282,3 +1282,28 @@ out:
 	pr_img_tail(CR_FD_UNIXSK);
 }
 
+extern void print_data(unsigned long addr, unsigned char *data, size_t size);
+
+int show_sk_queues(int fd)
+{
+	struct sk_packet_entry pe;
+	int ret;
+
+	pr_img_head(CR_FD_SK_QUEUES);
+	while (1) {
+		ret = read_img_eof(fd, &pe);
+		if (ret <= 0)
+			break;
+
+		pr_info("pkt for %u length %u bytes\n",
+				pe.id_for, pe.length);
+
+		ret = read_img_buf(fd, (unsigned char *)buf, pe.length);
+		if (ret < 0)
+			return ret;
+
+		print_data(0, (unsigned char *)buf, pe.length);
+	}
+	pr_img_tail(CR_FD_SK_QUEUES);
+	return ret;
+}



More information about the CRIU mailing list