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