[08/12] soccr/tcp: Restore socket's info before binding it

Submitted by Pavel Emelianov on Aug. 5, 2016, 3:01 p.m.

Details

Message ID 57A4AA56.4090009@virtuozzo.com
State Accepted
Series "Introduce library for socket C/R"
Commit 2da14278ba5890c2da3f5a8bd3793a1fe5e4f6d1
Headers show

Commit Message

Pavel Emelianov Aug. 5, 2016, 3:01 p.m.
In TCP repair some stuff should be restored before calling
connect/bind on socker and some -- after it.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/sk-tcp.c | 31 +------------------------------
 soccr/soccr.c | 34 ++++++++++++++++++++++++++++++++++
 soccr/soccr.h |  1 +
 3 files changed, 36 insertions(+), 30 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
index eaaf165..4161339 100644
--- a/criu/sk-tcp.c
+++ b/criu/sk-tcp.c
@@ -286,35 +286,6 @@  int dump_one_tcp(int fd, struct inet_sk_desc *sk)
 	return 0;
 }
 
-static int set_tcp_queue_seq(int sk, int queue, u32 seq)
-{
-	pr_debug("\tSetting %d queue seq to %u\n", queue, seq);
-
-	if (setsockopt(sk, SOL_TCP, TCP_REPAIR_QUEUE, &queue, sizeof(queue)) < 0) {
-		pr_perror("Can't set repair queue");
-		return -1;
-	}
-
-	if (setsockopt(sk, SOL_TCP, TCP_QUEUE_SEQ, &seq, sizeof(seq)) < 0) {
-		pr_perror("Can't set queue seq");
-		return -1;
-	}
-
-	return 0;
-}
-
-static int restore_tcp_seqs(int sk, TcpStreamEntry *tse)
-{
-	if (set_tcp_queue_seq(sk, TCP_RECV_QUEUE,
-				tse->inq_seq - tse->inq_len))
-		return -1;
-	if (set_tcp_queue_seq(sk, TCP_SEND_QUEUE,
-				tse->outq_seq - tse->outq_len))
-		return -1;
-
-	return 0;
-}
-
 static int __send_tcp_queue(int sk, int queue, u32 len, struct cr_img *img)
 {
 	int ret, err = -1, max_chunk;
@@ -549,7 +520,7 @@  static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
 
 	(void)data;
 
-	if (restore_tcp_seqs(sk, tse))
+	if (libsoccr_set_sk_data_unbound(socr, &data, sizeof(data)))
 		goto err_c;
 
 	if (inet_bind(sk, ii))
diff --git a/soccr/soccr.c b/soccr/soccr.c
index d157032..6eeb368 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -315,3 +315,37 @@  char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal)
 
 	return ret;
 }
+
+static int set_queue_seq(struct libsoccr_sk *sk, int queue, __u32 seq)
+{
+	logd("\tSetting %d queue seq to %u\n", queue, seq);
+
+	if (setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_QUEUE, &queue, sizeof(queue)) < 0) {
+		loge("Can't set repair queue");
+		return -1;
+	}
+
+	if (setsockopt(sk->fd, SOL_TCP, TCP_QUEUE_SEQ, &seq, sizeof(seq)) < 0) {
+		loge("Can't set queue seq");
+		return -1;
+	}
+
+	return 0;
+}
+
+int libsoccr_set_sk_data_unbound(struct libsoccr_sk *sk,
+		struct libsoccr_sk_data *data, unsigned data_size)
+{
+	if (!data || data_size < SOCR_DATA_MIN_SIZE)
+		return -1;
+
+	if (set_queue_seq(sk, TCP_RECV_QUEUE,
+				data->inq_seq - data->inq_len))
+		return -2;
+	if (set_queue_seq(sk, TCP_SEND_QUEUE,
+				data->outq_seq - data->outq_len))
+		return -3;
+
+	return 0;
+}
+
diff --git a/soccr/soccr.h b/soccr/soccr.h
index f6c54bd..3458a1b 100644
--- a/soccr/soccr.h
+++ b/soccr/soccr.h
@@ -53,4 +53,5 @@  void libsoccr_resume(struct libsoccr_sk *sk);
 int libsoccr_get_sk_data(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size);
 char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal);
 
+int libsoccr_set_sk_data_unbound(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size);
 #endif