[CRIU] [PATCHv0 04/12] gc: implement link remaps show

Eugene Batalov eabatalov89 at gmail.com
Sun Jul 24 11:58:06 PDT 2016


Signed-off-by: Eugene Batalov <eabatalov89 at gmail.com>
---
 criu/cr-gc.c             | 13 +++++++++++--
 criu/files-reg.c         | 27 +++++++++++++++++++++++++++
 criu/include/files-reg.h |  1 +
 3 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/criu/cr-gc.c b/criu/cr-gc.c
index d6b4ad1..2879365 100644
--- a/criu/cr-gc.c
+++ b/criu/cr-gc.c
@@ -68,6 +68,13 @@ static int gc_cleanup_mntns(void)
 	return ret;
 }
 
+static int gc_show(void)
+{
+	show_link_remaps();
+
+	return 0;
+}
+
 static int gc_do(void)
 {
 	if (gc_link_remaps() < 0)
@@ -115,8 +122,10 @@ int cr_gc(void)
 		goto exit;
 	}
 
-	if (gc_do())
-		ret = -1;
+	if (opts.show)
+		ret = gc_show();
+	else
+		ret = gc_do();
 
 exit:
 	if (gc_cleanup_mntns())
diff --git a/criu/files-reg.c b/criu/files-reg.c
index 8a0ec1d..7bed79c 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -749,6 +749,33 @@ int gc_link_remaps(void)
 	return 0;
 }
 
+void show_link_remaps(void)
+{
+	struct remap_info *ri;
+
+	if (list_empty(&remaps))
+		return;
+
+	list_for_each_entry(ri, &remaps, list) {
+		if (ri->rfe->remap_type != REMAP_TYPE__LINKED)
+			continue;
+
+		/* Don't print " (deleted)" suffix if it exists */
+		const char DELETED_SUFFIX[] = " (deleted)";
+		size_t path_size = strlen(ri->rfi->path) + 1;
+
+		if (path_size >= sizeof(DELETED_SUFFIX)) {
+			char *path_no_suffix = ri->rfi->path + path_size
+				- sizeof(DELETED_SUFFIX);
+			if (!strcmp(path_no_suffix, DELETED_SUFFIX))
+				path_size -= sizeof(DELETED_SUFFIX) - 1;
+		}
+
+		pr_msg("Link remap: /%s -> /%.*s\n",
+					ri->rfi->remap->rpath, (int)path_size - 1, ri->rfi->path);
+	}
+}
+
 static int create_link_remap(char *path, int len, int lfd,
 				u32 *idp, struct ns_id *nsid)
 {
diff --git a/criu/include/files-reg.h b/criu/include/files-reg.h
index ff54303..f567127 100644
--- a/criu/include/files-reg.h
+++ b/criu/include/files-reg.h
@@ -53,6 +53,7 @@ extern void free_link_remaps(void);
 extern int prepare_remaps(void);
 extern void try_clean_remaps(void);
 extern int gc_link_remaps(void);
+extern void show_link_remaps(void);
 
 extern int strip_deleted(struct fd_link *link);
 
-- 
1.9.1



More information about the CRIU mailing list