2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 14:25:49 +00:00

v2 deduplication: add separate function for punch to use on restore

Signed-off-by: Tikhomirov Pavel <snorcht@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Tikhomirov Pavel
2014-02-19 18:56:30 +04:00
committed by Pavel Emelyanov
parent 9b491e5c68
commit a355affd29
2 changed files with 18 additions and 7 deletions

View File

@@ -101,6 +101,19 @@ exit:
return 0;
}
int punch_hole(int fd, unsigned long off, unsigned long len)
{
int ret;
pr_debug("Punch!/%lu/%lu/\n", off, len);
ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
off, len);
if (ret != 0) {
pr_perror("Error punching hole");
return -1;
}
return 0;
}
int dedup_one_iovec(struct page_read *pr, struct iovec *iov)
{
unsigned long off;
@@ -133,14 +146,11 @@ int dedup_one_iovec(struct page_read *pr, struct iovec *iov)
piov_end = (unsigned long)piov.iov_base + piov.iov_len;
off_real = lseek(pr->fd_pg, 0, SEEK_CUR);
if (!pr->pe->in_parent) {
pr_debug("Punch!/%lu/%lu/\n", off_real, min(piov_end, iov_end) - off);
ret = fallocate(pr->fd_pg, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
off_real, min(piov_end, iov_end) - off);
if (ret != 0) {
pr_perror("Error punching hole : %d", errno);
return -1;
}
ret = punch_hole(pr->fd_pg, off_real, min(piov_end, iov_end) - off);
if (ret == -1)
return ret;
}
prp = pr->parent;
if (prp) {
/* recursively */

View File

@@ -73,4 +73,5 @@ extern void pagemap2iovec(PagemapEntry *pe, struct iovec *iov);
extern int seek_pagemap_page(struct page_read *pr, unsigned long vaddr, bool warn);
extern int dedup_one_iovec(struct page_read *pr, struct iovec *iov);
extern int punch_hole(int fd, unsigned long off, unsigned long len);
#endif /* __CR_PAGE_READ_H__ */