[CRIU] [PATCH] [RFC] soccr: restore queues from soccr

Andrei Vagin avagin at openvz.org
Thu Dec 8 10:47:03 PST 2016


From: Andrei Vagin <avagin at virtuozzo.com>

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

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/sk-tcp.c | 24 +++++++++++-------------
 soccr/soccr.c | 21 ++++++++++++++++++---
 soccr/soccr.h | 22 ++++------------------
 3 files changed, 33 insertions(+), 34 deletions(-)

diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
index 8179a35..210dc30 100644
--- a/criu/sk-tcp.c
+++ b/criu/sk-tcp.c
@@ -245,7 +245,7 @@ int dump_one_tcp(int fd, struct inet_sk_desc *sk)
 	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)
 {
 	char *buf;
@@ -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)
 		goto err;
 
-	if (libsoccr_set_queue_bytes(sk, data, sizeof(*data), queue, buf))
-		goto err;
+	if (queue == TCP_SEND_QUEUE)
+		data->outq_data = buf;
+	else
+		data->inq_data = buf;
 
-	xfree(buf);
 	return 0;
 
 err:
@@ -268,16 +269,16 @@ err:
 	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;
 
 	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;
 
 	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 0;
@@ -348,8 +349,6 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
 				ii->ie->dst_addr, 0) < 0)
 		goto err_c;
 
-	(void)data;
-
 	/*
 	 * O_NONBLOCK has to be set before libsoccr_set_sk_data_noq(),
 	 * 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_
 	if (restore_prepare_socket(sk))
 		goto err_c;
 
-	if (libsoccr_set_sk_data_noq(socr, &data, sizeof(data)))
-		goto err_c;
-
-	if (restore_tcp_queues(socr, &data, img))
+	if (read_tcp_queues(socr, &data, img))
 		goto err_c;
 
 	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_
 	return 0;
 
 err_c:
+	xfree(data.inq_data);
+	xfree(data.outq_data);
 	tcp_stream_entry__free_unpacked(tse, NULL);
 	close_image(img);
 err:
diff --git a/soccr/soccr.c b/soccr/soccr.c
index 6be8f7d..bdcf709 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -397,7 +397,7 @@ static int set_queue_seq(struct libsoccr_sk *sk, int queue, __u32 seq)
 #define TCPOPT_SACK_PERM TCPOPT_SACK_PERMITTED
 #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)
 {
 	int mstate = 1 << data->state;
@@ -618,11 +618,23 @@ static int restore_fin_in_snd_queue(int sk, int acked)
 	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,
 		struct libsoccr_sk_data *data, unsigned data_size)
 {
 	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) {
 		struct tcp_repair_window wopt = {
 			.snd_wl1 = data->snd_wl1,
@@ -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);
 }
 
-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)
 {
 	if (!data || data_size < SOCR_DATA_MIN_SIZE)
 		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);
+	}
 
 	if (queue == TCP_SEND_QUEUE) {
 		__u32 len, ulen;
diff --git a/soccr/soccr.h b/soccr/soccr.h
index ba12052..8c752af 100644
--- a/soccr/soccr.h
+++ b/soccr/soccr.h
@@ -91,6 +91,9 @@ struct libsoccr_sk_data {
 	__u32	rcv_wnd;
 	__u32	rcv_wup;
 
+	char *inq_data;
+	char *outq_data;
+
 	union libsoccr_addr src_addr;
 	union libsoccr_addr dst_addr;
 };
@@ -183,9 +186,6 @@ char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal);
  * 	h = libsoccr_pause(sk)
  * 	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_resume(h)
@@ -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
- * 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.
+ * Performs restore actions on bind()-ed socket
  */
 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
-- 
2.7.4



More information about the CRIU mailing list