mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-03 15:55:53 +00:00
util: Copy file w/o sendfile
This is the case when the in/out files are image cache/proxy sockets. Signed-off-by: Rodrigo Bruno <rbruno@gsd.inesc-id.pt> Signed-off-by: Katerina Koukiou <k.koukiou@gmail.com> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
committed by
Andrei Vagin
parent
d3ac1f40b8
commit
81ae3efbf2
29
criu/util.c
29
criu/util.c
@@ -564,29 +564,46 @@ int copy_file(int fd_in, int fd_out, size_t bytes)
|
|||||||
{
|
{
|
||||||
ssize_t written = 0;
|
ssize_t written = 0;
|
||||||
size_t chunk = bytes ? bytes : 4096;
|
size_t chunk = bytes ? bytes : 4096;
|
||||||
|
char *buffer = (char*) malloc(chunk);
|
||||||
while (1) {
|
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if (false) {
|
||||||
|
ret = read(fd_in, buffer, chunk);
|
||||||
|
if (ret < 0) {
|
||||||
|
pr_perror("Can't read from fd_in\n");
|
||||||
|
ret = -1;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
if (write(fd_out, buffer, ret) != ret) {
|
||||||
|
pr_perror("Couldn't write all read bytes\n");
|
||||||
|
ret = -1;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
} else
|
||||||
ret = sendfile(fd_out, fd_in, NULL, chunk);
|
ret = sendfile(fd_out, fd_in, NULL, chunk);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
pr_perror("Can't send data to ghost file");
|
pr_perror("Can't send data to ghost file");
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
if (bytes && (written != bytes)) {
|
if (bytes && (written != bytes)) {
|
||||||
pr_err("Ghost file size mismatch %zu/%zu\n",
|
pr_err("Ghost file size mismatch %zu/%zu\n",
|
||||||
written, bytes);
|
written, bytes);
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
written += ret;
|
written += ret;
|
||||||
}
|
}
|
||||||
|
err:
|
||||||
return 0;
|
free(buffer);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_fd_link(int lfd, char *buf, size_t size)
|
int read_fd_link(int lfd, char *buf, size_t size)
|
||||||
|
Reference in New Issue
Block a user