Commit f3e3958b authored by Andrei Vagin's avatar Andrei Vagin Committed by Pavel Emelyanov

soccr: restore queues from soccr

Looks like it is internal logic too, so it may be better to move into the library too.

travis-ci: success for soccr: restore queues from soccr
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent a35e84d8
...@@ -245,7 +245,7 @@ int dump_one_tcp(int fd, struct inet_sk_desc *sk) ...@@ -245,7 +245,7 @@ int dump_one_tcp(int fd, struct inet_sk_desc *sk)
return 0; return 0;
} }
static int send_tcp_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, static int read_tcp_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data,
int queue, u32 len, struct cr_img *img) int queue, u32 len, struct cr_img *img)
{ {
char *buf; char *buf;
...@@ -257,10 +257,11 @@ static int send_tcp_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, ...@@ -257,10 +257,11 @@ static int send_tcp_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data,
if (read_img_buf(img, buf, len) < 0) if (read_img_buf(img, buf, len) < 0)
goto err; goto err;
if (libsoccr_set_queue_bytes(sk, data, sizeof(*data), queue, buf)) if (queue == TCP_SEND_QUEUE)
goto err; data->outq_data = buf;
else
data->inq_data = buf;
xfree(buf);
return 0; return 0;
err: err:
...@@ -268,16 +269,16 @@ err: ...@@ -268,16 +269,16 @@ err:
return -1; return -1;
} }
static int restore_tcp_queues(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, struct cr_img *img) static int read_tcp_queues(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, struct cr_img *img)
{ {
u32 len; u32 len;
len = data->inq_len; len = data->inq_len;
if (len && send_tcp_queue(sk, data, TCP_RECV_QUEUE, len, img)) if (len && read_tcp_queue(sk, data, TCP_RECV_QUEUE, len, img))
return -1; return -1;
len = data->outq_len; len = data->outq_len;
if (len && send_tcp_queue(sk, data, TCP_SEND_QUEUE, len, img)) if (len && read_tcp_queue(sk, data, TCP_SEND_QUEUE, len, img))
return -1; return -1;
return 0; return 0;
...@@ -348,8 +349,6 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_ ...@@ -348,8 +349,6 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
ii->ie->dst_addr, 0) < 0) ii->ie->dst_addr, 0) < 0)
goto err_c; goto err_c;
(void)data;
/* /*
* O_NONBLOCK has to be set before libsoccr_set_sk_data_noq(), * O_NONBLOCK has to be set before libsoccr_set_sk_data_noq(),
* it is required to restore syn-sent sockets. * it is required to restore syn-sent sockets.
...@@ -357,10 +356,7 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_ ...@@ -357,10 +356,7 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
if (restore_prepare_socket(sk)) if (restore_prepare_socket(sk))
goto err_c; goto err_c;
if (libsoccr_set_sk_data_noq(socr, &data, sizeof(data))) if (read_tcp_queues(socr, &data, img))
goto err_c;
if (restore_tcp_queues(socr, &data, img))
goto err_c; goto err_c;
if (libsoccr_set_sk_data(socr, &data, sizeof(data))) if (libsoccr_set_sk_data(socr, &data, sizeof(data)))
...@@ -383,6 +379,8 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_ ...@@ -383,6 +379,8 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
return 0; return 0;
err_c: err_c:
xfree(data.inq_data);
xfree(data.outq_data);
tcp_stream_entry__free_unpacked(tse, NULL); tcp_stream_entry__free_unpacked(tse, NULL);
close_image(img); close_image(img);
err: err:
......
...@@ -397,7 +397,7 @@ static int set_queue_seq(struct libsoccr_sk *sk, int queue, __u32 seq) ...@@ -397,7 +397,7 @@ static int set_queue_seq(struct libsoccr_sk *sk, int queue, __u32 seq)
#define TCPOPT_SACK_PERM TCPOPT_SACK_PERMITTED #define TCPOPT_SACK_PERM TCPOPT_SACK_PERMITTED
#endif #endif
int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk, static int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk,
struct libsoccr_sk_data *data, unsigned data_size) struct libsoccr_sk_data *data, unsigned data_size)
{ {
int mstate = 1 << data->state; int mstate = 1 << data->state;
...@@ -618,11 +618,23 @@ static int restore_fin_in_snd_queue(int sk, int acked) ...@@ -618,11 +618,23 @@ static int restore_fin_in_snd_queue(int sk, int acked)
return ret; return ret;
} }
static int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size,
int queue, char *buf);
int libsoccr_set_sk_data(struct libsoccr_sk *sk, int libsoccr_set_sk_data(struct libsoccr_sk *sk,
struct libsoccr_sk_data *data, unsigned data_size) struct libsoccr_sk_data *data, unsigned data_size)
{ {
int mstate = 1 << data->state; int mstate = 1 << data->state;
if (libsoccr_set_sk_data_noq(sk, data, data_size))
return -1;
if (libsoccr_set_queue_bytes(sk, data, sizeof(*data), TCP_RECV_QUEUE, data->inq_data))
return -1;
if (libsoccr_set_queue_bytes(sk, data, sizeof(*data), TCP_SEND_QUEUE, data->outq_data))
return -1;
if (data->flags & SOCCR_FLAGS_WINDOW) { if (data->flags & SOCCR_FLAGS_WINDOW) {
struct tcp_repair_window wopt = { struct tcp_repair_window wopt = {
.snd_wl1 = data->snd_wl1, .snd_wl1 = data->snd_wl1,
...@@ -732,14 +744,17 @@ static int send_queue(struct libsoccr_sk *sk, int queue, char *buf, __u32 len) ...@@ -732,14 +744,17 @@ static int send_queue(struct libsoccr_sk *sk, int queue, char *buf, __u32 len)
return __send_queue(sk, queue, buf, len); return __send_queue(sk, queue, buf, len);
} }
int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size, static int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size,
int queue, char *buf) int queue, char *buf)
{ {
if (!data || data_size < SOCR_DATA_MIN_SIZE) if (!data || data_size < SOCR_DATA_MIN_SIZE)
return -1; return -1;
if (queue == TCP_RECV_QUEUE) if (queue == TCP_RECV_QUEUE) {
if (!data->inq_len)
return 0;
return send_queue(sk, TCP_RECV_QUEUE, buf, data->inq_len); return send_queue(sk, TCP_RECV_QUEUE, buf, data->inq_len);
}
if (queue == TCP_SEND_QUEUE) { if (queue == TCP_SEND_QUEUE) {
__u32 len, ulen; __u32 len, ulen;
......
...@@ -91,6 +91,9 @@ struct libsoccr_sk_data { ...@@ -91,6 +91,9 @@ struct libsoccr_sk_data {
__u32 rcv_wnd; __u32 rcv_wnd;
__u32 rcv_wup; __u32 rcv_wup;
char *inq_data;
char *outq_data;
union libsoccr_addr src_addr; union libsoccr_addr src_addr;
union libsoccr_addr dst_addr; union libsoccr_addr dst_addr;
}; };
...@@ -183,9 +186,6 @@ char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal); ...@@ -183,9 +186,6 @@ char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal);
* h = libsoccr_pause(sk) * h = libsoccr_pause(sk)
* bind(sk, &name, ...) * bind(sk, &name, ...)
* *
* libsoccr_set_sk_data_noq(h, &data, sizeof(data))
* libsoccr_set_queue_bytes(h, &data, sizeof(data), TCP_RECV_QUEUE, inq)
* libsoccr_set_queue_bytes(h, &data, sizeof(data), TCP_SEND_QUEUE, outq)
* libsoccr_set_sk_data(h, &data, sizeof(data)) * libsoccr_set_sk_data(h, &data, sizeof(data))
* *
* libsoccr_resume(h) * libsoccr_resume(h)
...@@ -195,22 +195,8 @@ char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal); ...@@ -195,22 +195,8 @@ char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal);
*/ */
/* /*
* Performs additional restore actions on bind()-ed and connect()-ed * Performs restore actions on bind()-ed socket
* socket, but without queues restored.
*/
int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size);
/*
* Performs final restore action after queues restoration.
*/ */
int libsoccr_set_sk_data(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size); int libsoccr_set_sk_data(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size);
/*
* Restores the data in queues. The amount of data in *buf should
* match the _len-s from data as in the _get_queue_bytes case.
*
* Called after the _set_sk_data().
*/
int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size,
int queue, char *buf);
#endif #endif
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