mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-28 12:57:57 +00:00
zdtm/socket-tcpbuf: heartbeat should not read all data
Currently we fill as much as posible data in a socket and then use half of these data to make a flow in the connection. These data is send and recv buffers. When a connection is dumped and restored, it needs time to go back to the normal work. In this time we can reliably fill only send buffers. So at the result the sockets may contain less data than required for heartbeating and the test will block. The test with this patch will monitor actuall size of data in a test socket. Cc: Konstantin Neumoin <kneumoin@parallels.com> Reported-by: Konstantin Neumoin <kneumoin@parallels.com> Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
5676383729
commit
deeea1d221
@ -109,7 +109,7 @@ int main(int argc, char **argv)
|
|||||||
pid_t extpid;
|
pid_t extpid;
|
||||||
int pfd[2];
|
int pfd[2];
|
||||||
int sk_bsize;
|
int sk_bsize;
|
||||||
int ret, snd_size, rcv_size = 0, rcv_size_orig;
|
int ret, snd, snd_size, rcv_size = 0, rcv_buf_size;
|
||||||
|
|
||||||
#ifdef ZDTM_TCP_LOCAL
|
#ifdef ZDTM_TCP_LOCAL
|
||||||
test_init(argc, argv);
|
test_init(argc, argv);
|
||||||
@ -149,27 +149,36 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
write_safe(ctl_fd, &snd_size, sizeof(snd_size));
|
write_safe(ctl_fd, &snd_size, sizeof(snd_size));
|
||||||
|
|
||||||
read_safe(ctl_fd, &rcv_size_orig, sizeof(rcv_size_orig));
|
read_safe(ctl_fd, &rcv_buf_size, sizeof(rcv_buf_size));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
/* heart beat */
|
||||||
read_safe(ctl_fd, &ret, sizeof(ret));
|
read_safe(ctl_fd, &ret, sizeof(ret));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
|
rcv_buf_size += ret;
|
||||||
|
|
||||||
ret = fill_sock_buf(fd);
|
snd = fill_sock_buf(fd);
|
||||||
if (ret < 0)
|
if (snd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
snd_size += ret;
|
snd_size += snd;
|
||||||
|
|
||||||
ret = clean_sk_buf(fd, rcv_size_orig / 2);
|
if (rcv_buf_size / 2) {
|
||||||
if (ret <= 0)
|
ret = clean_sk_buf(fd, rcv_buf_size / 2);
|
||||||
return 1;
|
if (ret <= 0)
|
||||||
|
return 1;
|
||||||
|
} else
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
rcv_buf_size -= ret;
|
||||||
rcv_size += ret;
|
rcv_size += ret;
|
||||||
|
|
||||||
write_safe(ctl_fd, &ret, sizeof(ret));
|
write_safe(ctl_fd, &snd, sizeof(snd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
read_safe(ctl_fd, &ret, sizeof(ret));
|
||||||
|
rcv_buf_size += ret;
|
||||||
|
|
||||||
write_safe(ctl_fd, &snd_size, sizeof(snd_size));
|
write_safe(ctl_fd, &snd_size, sizeof(snd_size));
|
||||||
|
|
||||||
if (read(ctl_fd, &c, 1) != 0) {
|
if (read(ctl_fd, &c, 1) != 0) {
|
||||||
@ -186,6 +195,10 @@ int main(int argc, char **argv)
|
|||||||
if (size < 0)
|
if (size < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
if (size != rcv_buf_size) {
|
||||||
|
fail("the received buffer contains only %d bytes (%d)\n", size, rcv_buf_size);
|
||||||
|
}
|
||||||
|
|
||||||
rcv_size += size;
|
rcv_size += size;
|
||||||
|
|
||||||
write_safe(ctl_fd, &rcv_size, sizeof(rcv_size));
|
write_safe(ctl_fd, &rcv_size, sizeof(rcv_size));
|
||||||
@ -240,30 +253,40 @@ int main(int argc, char **argv)
|
|||||||
if (snd_size <= 0)
|
if (snd_size <= 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
read_safe(ctl_fd, &rcv_size_orig, sizeof(rcv_size_orig));
|
read_safe(ctl_fd, &rcv_buf_size, sizeof(rcv_buf_size));
|
||||||
|
|
||||||
write_safe(ctl_fd, &snd_size, sizeof(snd_size));
|
write_safe(ctl_fd, &snd_size, sizeof(snd_size));
|
||||||
|
|
||||||
test_daemon();
|
test_daemon();
|
||||||
|
|
||||||
|
snd = 0;
|
||||||
while (test_go()) {
|
while (test_go()) {
|
||||||
ret = clean_sk_buf(fd, rcv_size_orig / 2);
|
/* heart beat */
|
||||||
if (ret <= 0)
|
if (rcv_buf_size / 2) {
|
||||||
return 1;
|
ret = clean_sk_buf(fd, rcv_buf_size / 2);
|
||||||
|
if (ret <= 0)
|
||||||
|
return 1;
|
||||||
|
} else
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
rcv_size += ret;
|
rcv_size += ret;
|
||||||
|
rcv_buf_size -= ret;
|
||||||
|
|
||||||
write_safe(ctl_fd, &ret, sizeof(ret));
|
write_safe(ctl_fd, &snd, sizeof(snd));
|
||||||
read_safe(ctl_fd, &ret, sizeof(ret));
|
read_safe(ctl_fd, &ret, sizeof(ret));
|
||||||
|
|
||||||
ret = fill_sock_buf(fd);
|
rcv_buf_size += ret;
|
||||||
if (ret < 0)
|
|
||||||
|
snd = fill_sock_buf(fd);
|
||||||
|
if (snd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
snd_size += ret;
|
snd_size += snd;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
write_safe(ctl_fd, &ret, sizeof(ret));
|
write_safe(ctl_fd, &ret, sizeof(ret));
|
||||||
read_safe(ctl_fd, &rcv_size_orig, sizeof(rcv_size_orig));
|
write_safe(ctl_fd, &snd, sizeof(ret));
|
||||||
|
read_safe(ctl_fd, &snd, sizeof(snd));
|
||||||
|
|
||||||
if (shutdown(ctl_fd, SHUT_WR) == -1) {
|
if (shutdown(ctl_fd, SHUT_WR) == -1) {
|
||||||
err("shutdown");
|
err("shutdown");
|
||||||
@ -275,10 +298,14 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rcv_size += clean_sk_buf(fd, 0);
|
ret = clean_sk_buf(fd, 0);
|
||||||
|
if (ret != rcv_buf_size) {
|
||||||
|
fail("the received buffer contains only %d bytes (%d)\n", ret, rcv_buf_size);
|
||||||
|
}
|
||||||
|
rcv_size += ret;
|
||||||
|
|
||||||
if (rcv_size_orig != rcv_size) {
|
if (snd != rcv_size) {
|
||||||
fail("The child sent %d bytes, but the parent received %d bytes\n", rcv_size_orig, rcv_size);
|
fail("The child sent %d bytes, but the parent received %d bytes\n", rcv_buf_size, rcv_size);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user