mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 14:25:49 +00:00
uffd.c: move code into subfunctions
uffd_listen() is a rather large function and this starts to move code into subfunctions. Signed-off-by: Adrian Reber <areber@redhat.com> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
committed by
Andrei Vagin
parent
c3abfff0ad
commit
048b31b24c
67
criu/uffd.c
67
criu/uffd.c
@@ -394,15 +394,16 @@ static int handle_regular_pages(int uffd, struct list_head *uffd_list, void *des
|
|||||||
/*
|
/*
|
||||||
* Setting up criu infrastructure and scan for VMAs.
|
* Setting up criu infrastructure and scan for VMAs.
|
||||||
*/
|
*/
|
||||||
static int find_vmas()
|
static int find_vmas(struct list_head *uffd_list)
|
||||||
{
|
{
|
||||||
struct cr_img *img;
|
struct cr_img *img;
|
||||||
int ret;
|
int ret;
|
||||||
struct vm_area_list vmas;
|
struct vm_area_list vmas;
|
||||||
int vn = 0;
|
int vn = 0;
|
||||||
struct rst_info *ri;
|
struct rst_info *ri;
|
||||||
|
struct page_read pr;
|
||||||
|
struct uffd_pages_struct *uffd_pages;
|
||||||
|
|
||||||
LIST_HEAD(uffd_list);
|
|
||||||
|
|
||||||
if (check_img_inventory() == -1)
|
if (check_img_inventory() == -1)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -437,7 +438,7 @@ static int find_vmas()
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
vma = alloc_vma_area();
|
vma = alloc_vma_area();
|
||||||
if (!vma)
|
if (!vma)
|
||||||
break;
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
ri->vmas.nr++;
|
ri->vmas.nr++;
|
||||||
@@ -454,6 +455,34 @@ static int find_vmas()
|
|||||||
pr_info("vma 0x%"PRIx64" 0x%"PRIx64"\n", vma->e->start, vma->e->end);
|
pr_info("vma 0x%"PRIx64" 0x%"PRIx64"\n", vma->e->start, vma->e->end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = open_page_read(pid, &pr, PR_TASK);
|
||||||
|
if (ret <= 0) {
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* This puts all pages which should be handled by userfaultfd
|
||||||
|
* in the list uffd_list. This list is later used to detect if
|
||||||
|
* a page has already been transferred or if it needs to be
|
||||||
|
* pushed into the process using userfaultfd.
|
||||||
|
*/
|
||||||
|
do {
|
||||||
|
ret = collect_uffd_pages(&pr, uffd_list);
|
||||||
|
if (ret == -1) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
} while (ret);
|
||||||
|
|
||||||
|
if (pr.close)
|
||||||
|
pr.close(&pr);
|
||||||
|
|
||||||
|
/* Count detected pages */
|
||||||
|
list_for_each_entry(uffd_pages, uffd_list, list)
|
||||||
|
ret++;
|
||||||
|
|
||||||
|
pr_debug("Found %d pages to be handled by UFFD\n", ret);
|
||||||
|
|
||||||
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,7 +492,6 @@ int uffd_listen()
|
|||||||
void *dest;
|
void *dest;
|
||||||
__u64 flags;
|
__u64 flags;
|
||||||
struct uffd_msg msg;
|
struct uffd_msg msg;
|
||||||
struct page_read pr;
|
|
||||||
unsigned long ps;
|
unsigned long ps;
|
||||||
int rc;
|
int rc;
|
||||||
fd_set set;
|
fd_set set;
|
||||||
@@ -496,7 +524,7 @@ int uffd_listen()
|
|||||||
* Find the memory pages belonging to the restored process
|
* Find the memory pages belonging to the restored process
|
||||||
* so that it is trackable when all pages have been transferred.
|
* so that it is trackable when all pages have been transferred.
|
||||||
*/
|
*/
|
||||||
if (find_vmas() == -1)
|
if ((total_pages = find_vmas(&uffd_list)) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Initialize FD sets for read() with timeouts (using select()) */
|
/* Initialize FD sets for read() with timeouts (using select()) */
|
||||||
@@ -509,35 +537,6 @@ int uffd_listen()
|
|||||||
if (!dest)
|
if (!dest)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
rc = open_page_read(pid, &pr, PR_TASK);
|
|
||||||
if (rc <= 0) {
|
|
||||||
rc = 1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* This puts all pages which should be handled by userfaultfd
|
|
||||||
* in the list uffd_list. This list is later used to detect if
|
|
||||||
* a page has already been transferred or if it needs to be
|
|
||||||
* pushed into the process using userfaultfd.
|
|
||||||
*/
|
|
||||||
do {
|
|
||||||
rc = collect_uffd_pages(&pr, &uffd_list);
|
|
||||||
if (rc == -1) {
|
|
||||||
rc = 1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
} while (rc);
|
|
||||||
|
|
||||||
if (pr.close)
|
|
||||||
pr.close(&pr);
|
|
||||||
|
|
||||||
|
|
||||||
/* Count detected pages */
|
|
||||||
list_for_each_entry(uffd_pages, &uffd_list, list)
|
|
||||||
total_pages++;
|
|
||||||
|
|
||||||
pr_debug("Found %ld pages to be handled by UFFD\n", total_pages);
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
bool page_sent = false;
|
bool page_sent = false;
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user