Commit 8ffd3587 authored by Tikhomirov Pavel's avatar Tikhomirov Pavel Committed by Pavel Emelyanov

v2 dedup: make bunched auto-deduplication on restore for shmem

in restore_shmem_content() use open_page_read() to open images
Signed-off-by: 's avatarTikhomirov Pavel <snorcht@gmail.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 670d1ce8
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "pid.h" #include "pid.h"
#include "shmem.h" #include "shmem.h"
#include "image.h" #include "image.h"
#include "cr_options.h"
#include "page-pipe.h" #include "page-pipe.h"
#include "page-xfer.h" #include "page-xfer.h"
#include "rst-malloc.h" #include "rst-malloc.h"
...@@ -106,62 +107,50 @@ static int shmem_wait_and_open(int pid, struct shmem_info *si) ...@@ -106,62 +107,50 @@ static int shmem_wait_and_open(int pid, struct shmem_info *si)
static int restore_shmem_content(void *addr, struct shmem_info *si) static int restore_shmem_content(void *addr, struct shmem_info *si)
{ {
int fd, fd_pg, ret = 0; int ret = 0;
struct page_read pr;
fd = open_image(CR_FD_SHMEM_PAGEMAP, O_RSTR, si->shmid); unsigned long off_real;
if (fd < 0) {
fd_pg = open_image(CR_FD_SHM_PAGES_OLD, O_RSTR, si->shmid); ret = open_page_read(si->shmid, &pr, opts.auto_dedup ? O_RDWR : O_RSTR, true);
if (fd_pg < 0) if (ret)
goto err_unmap; goto err_unmap;
} else {
fd_pg = open_pages_image(O_RSTR, fd);
if (fd_pg < 0)
goto out_close;
}
while (1) { while (1) {
unsigned long vaddr; unsigned long vaddr;
unsigned nr_pages; unsigned nr_pages;
struct iovec iov;
if (fd >= 0) { ret = pr.get_pagemap(&pr, &iov);
PagemapEntry *pe; if (ret <= 0)
break;
ret = pb_read_one_eof(fd, &pe, PB_PAGEMAP);
if (ret <= 0)
break;
vaddr = (unsigned long)decode_pointer(pe->vaddr);
nr_pages = pe->nr_pages;
pagemap_entry__free_unpacked(pe, NULL);
} else {
__u64 img_vaddr;
ret = read_img_eof(fd_pg, &img_vaddr);
if (ret <= 0)
break;
vaddr = (unsigned long)decode_pointer(img_vaddr); vaddr = (unsigned long)iov.iov_base;
nr_pages = 1; nr_pages = iov.iov_len / PAGE_SIZE;
}
if (vaddr + nr_pages * PAGE_SIZE > si->size) if (vaddr + nr_pages * PAGE_SIZE > si->size)
break; break;
ret = read(fd_pg, addr + vaddr, nr_pages * PAGE_SIZE); off_real = lseek(pr.fd_pg, 0, SEEK_CUR);
ret = read(pr.fd_pg, addr + vaddr, nr_pages * PAGE_SIZE);
if (ret != nr_pages * PAGE_SIZE) { if (ret != nr_pages * PAGE_SIZE) {
ret = -1; ret = -1;
break; break;
} }
if (opts.auto_dedup) {
ret = punch_hole(&pr, off_real, nr_pages * PAGE_SIZE, false);
if (ret == -1) {
break;
}
}
if (pr.put_pagemap)
pr.put_pagemap(&pr);
} }
close_safe(&fd_pg); pr.close(&pr);
close_safe(&fd);
return ret; return ret;
out_close:
close_safe(&fd);
err_unmap: err_unmap:
munmap(addr, si->size); munmap(addr, si->size);
return -1; return -1;
......
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