Commit a249869d authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

files: expand slice for parasite_drain_fd dinamically

We are going to remove the PARASITE_MAX_FDS limit and
this patch is a preparation for this.
Signed-off-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 3b70d9a1
...@@ -184,10 +184,11 @@ static int dump_sched_info(int pid, ThreadCoreEntry *tc) ...@@ -184,10 +184,11 @@ static int dump_sched_info(int pid, ThreadCoreEntry *tc)
struct cr_imgset *glob_imgset; 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; struct dirent *de;
DIR *fd_dir; DIR *fd_dir;
int size = 0;
int n; int n;
pr_info("\n"); pr_info("\n");
...@@ -206,10 +207,20 @@ static int collect_fds(pid_t pid, struct parasite_drain_fd *dfds) ...@@ -206,10 +207,20 @@ static int collect_fds(pid_t pid, struct parasite_drain_fd *dfds)
if (n > PARASITE_MAX_FDS - 1) if (n > PARASITE_MAX_FDS - 1)
return -ENOMEM; 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("Found %d file descriptors\n", n);
pr_info("----------------------------------------\n"); pr_info("----------------------------------------\n");
...@@ -1208,7 +1219,7 @@ static int dump_one_task(struct pstree_item *item) ...@@ -1208,7 +1219,7 @@ static int dump_one_task(struct pstree_item *item)
if (!dfds) if (!dfds)
goto err; goto err;
ret = collect_fds(pid, dfds); ret = collect_fds(pid, &dfds);
if (ret) { if (ret) {
pr_err("Collect fds (pid: %d) failed with %d\n", pid, ret); pr_err("Collect fds (pid: %d) failed with %d\n", pid, ret);
goto err; goto err;
......
...@@ -226,7 +226,7 @@ static inline void copy_sas(ThreadSasEntry *dst, const stack_t *src) ...@@ -226,7 +226,7 @@ static inline void copy_sas(ThreadSasEntry *dst, const stack_t *src)
struct parasite_drain_fd { struct parasite_drain_fd {
int nr_fds; int nr_fds;
int fds[PARASITE_MAX_FDS]; int fds[0];
}; };
static inline int drain_fds_size(struct parasite_drain_fd *dfds) static inline int drain_fds_size(struct parasite_drain_fd *dfds)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment