mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-03 07:45:17 +00:00
rst: Formalize the shared resource restore order
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
7
files.c
7
files.c
@@ -443,10 +443,9 @@ static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
|
||||
return -1;
|
||||
}
|
||||
|
||||
list_for_each_entry(le, &fdesc->fd_info_head, desc_list) {
|
||||
if (le->pid > new_le->pid)
|
||||
list_for_each_entry(le, &fdesc->fd_info_head, desc_list)
|
||||
if (pid_rst_prio(new_le->pid, le->pid))
|
||||
break;
|
||||
}
|
||||
|
||||
list_add_tail(&new_le->desc_list, &le->desc_list);
|
||||
new_le->desc = fdesc;
|
||||
@@ -972,7 +971,7 @@ int shared_fdt_prepare(struct pstree_item *item)
|
||||
item->rst->fdt = fdt;
|
||||
item->rst->service_fd_id = fdt->nr;
|
||||
fdt->nr++;
|
||||
if (fdt->pid > item->pid.virt)
|
||||
if (pid_rst_prio(item->pid.virt, fdt->pid))
|
||||
fdt->pid = item->pid.virt;
|
||||
|
||||
return 0;
|
||||
|
@@ -189,4 +189,14 @@ static inline int in_vma_area(struct vma_area *vma, unsigned long addr)
|
||||
addr < (unsigned long)vma->vma.end;
|
||||
}
|
||||
|
||||
/*
|
||||
* When we have to restore a shared resource, we mush select which
|
||||
* task should do it, and make other(s) wait for it. In order to
|
||||
* avoid deadlocks, always make task with lower pid be the restorer.
|
||||
*/
|
||||
static inline bool pid_rst_prio(unsigned pid_a, unsigned pid_b)
|
||||
{
|
||||
return pid_a < pid_b;
|
||||
}
|
||||
|
||||
#endif /* __CR_CRTOOLS_H__ */
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "lock.h"
|
||||
#include "list.h"
|
||||
#include "image.h"
|
||||
#include "crtools.h"
|
||||
|
||||
#include "protobuf/fdinfo.pb-c.h"
|
||||
#include "protobuf/fown.pb-c.h"
|
||||
@@ -69,7 +70,8 @@ struct fdinfo_list_entry {
|
||||
/* reports whether fd_a takes prio over fd_b */
|
||||
static inline int fdinfo_rst_prio(struct fdinfo_list_entry *fd_a, struct fdinfo_list_entry *fd_b)
|
||||
{
|
||||
return (fd_a->pid < fd_b->pid) || ((fd_a->pid == fd_b->pid) && (fd_a->fe->fd < fd_b->fe->fd));
|
||||
return pid_rst_prio(fd_a->pid, fd_b->pid) ||
|
||||
((fd_a->pid == fd_b->pid) && (fd_a->fe->fd < fd_b->fe->fd));
|
||||
}
|
||||
|
||||
struct file_desc_ops {
|
||||
|
Reference in New Issue
Block a user