Commit 10b338c5 authored by Pavel Emelyanov's avatar Pavel Emelyanov

fdt: Move shared-fdt structure preparation into separate fn

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 6045ca0e
......@@ -646,3 +646,30 @@ int get_filemap_fd(int pid, VmaEntry *vma_entry)
{
return open_reg_by_id(vma_entry->shmid);
}
int shared_fdt_prepare(struct pstree_item *item)
{
struct pstree_item *parent = item->parent;
struct fdt *fdt;
if (!parent->rst->fdt) {
fdt = shmalloc(sizeof(*item->rst->fdt));
if (fdt == NULL)
return -1;
parent->rst->fdt = fdt;
futex_init(&fdt->fdt_lock);
fdt->nr = 1;
fdt->pid = parent->pid.virt;
} else
fdt = parent->rst->fdt;
item->rst->fdt = fdt;
item->rst->service_fd_id = fdt->nr;
fdt->nr++;
if (fdt->pid > item->pid.virt)
fdt->pid = item->pid.virt;
return 0;
}
......@@ -101,4 +101,6 @@ extern int close_old_fds(struct pstree_item *me);
#define LREMAP_PARAM "link-remap"
int shared_fdt_prepare(struct pstree_item *item);
#endif /* __CR_FILES_H__ */
......@@ -7,6 +7,7 @@
#include "util.h"
#include "lock.h"
#include "namespaces.h"
#include "files.h"
#include "protobuf.h"
#include "protobuf/pstree.pb-c.h"
......@@ -446,7 +447,6 @@ static int prepare_pstree_kobj_ids(void)
/* Find a process with minimal pid for shared fd tables */
for_each_pstree_item(item) {
struct pstree_item *parent = item->parent;
struct fdt *fdt;
if (item->state == TASK_HELPER)
continue;
......@@ -457,27 +457,13 @@ static int prepare_pstree_kobj_ids(void)
if (parent == NULL)
continue;
if (!shared_fdtable(item))
continue;
if (!parent->rst->fdt) {
fdt = shmalloc(sizeof(*item->rst->fdt));
if (fdt == NULL)
return -1;
parent->rst->fdt = fdt;
futex_init(&fdt->fdt_lock);
fdt->nr = 1;
fdt->pid = parent->pid.virt;
} else
fdt = parent->rst->fdt;
if (shared_fdtable(item)) {
int ret;
item->rst->fdt = fdt;
item->rst->service_fd_id = fdt->nr;
fdt->nr++;
if (fdt->pid > item->pid.virt)
fdt->pid = item->pid.virt;
ret = shared_fdt_prepare(item);
if (ret)
return ret;
}
}
return 0;
......
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