[CRIU] [PATCH 1/3] files: expand slice for parasite_drain_fd dinamically

Andrey Vagin avagin at openvz.org
Mon Apr 4 09:58:06 PDT 2016


From: Andrew Vagin <avagin at virtuozzo.com>

We are going to remove the PARASITE_MAX_FDS limit and
this patch is a preparation for this.

Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 criu/cr-dump.c          | 19 +++++++++++++++----
 criu/include/parasite.h |  2 +-
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index aaa09e3..5163699 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -184,10 +184,11 @@ static int dump_sched_info(int pid, ThreadCoreEntry *tc)
 
 struct cr_imgset *glob_imgset;
 
-static int collect_fds(pid_t pid, struct parasite_drain_fd *dfds)
+static int collect_fds(pid_t pid, struct parasite_drain_fd **dfds)
 {
 	struct dirent *de;
 	DIR *fd_dir;
+	int size = 0;
 	int n;
 
 	pr_info("\n");
@@ -206,10 +207,20 @@ static int collect_fds(pid_t pid, struct parasite_drain_fd *dfds)
 		if (n > PARASITE_MAX_FDS - 1)
 			return -ENOMEM;
 
-		dfds->fds[n++] = atoi(de->d_name);
+		if (sizeof(struct parasite_drain_fd) + sizeof(int) * (n + 1) > size) {
+			struct parasite_drain_fd *t;
+
+			size += PAGE_SIZE;
+			t = xrealloc(*dfds, size);
+			if (!t)
+				return -1;
+			*dfds = t;
+		}
+
+		(*dfds)->fds[n++] = atoi(de->d_name);
 	}
 
-	dfds->nr_fds = n;
+	(*dfds)->nr_fds = n;
 	pr_info("Found %d file descriptors\n", n);
 	pr_info("----------------------------------------\n");
 
@@ -1208,7 +1219,7 @@ static int dump_one_task(struct pstree_item *item)
 		if (!dfds)
 			goto err;
 
-		ret = collect_fds(pid, dfds);
+		ret = collect_fds(pid, &dfds);
 		if (ret) {
 			pr_err("Collect fds (pid: %d) failed with %d\n", pid, ret);
 			goto err;
diff --git a/criu/include/parasite.h b/criu/include/parasite.h
index 341a8e5..417b324 100644
--- a/criu/include/parasite.h
+++ b/criu/include/parasite.h
@@ -226,7 +226,7 @@ static inline void copy_sas(ThreadSasEntry *dst, const stack_t *src)
 
 struct parasite_drain_fd {
 	int	nr_fds;
-	int	fds[PARASITE_MAX_FDS];
+	int	fds[0];
 };
 
 static inline int drain_fds_size(struct parasite_drain_fd *dfds)
-- 
2.5.0



More information about the CRIU mailing list