[CRIU] [PATCH 2/3] soccr: Move queue pointers from _data
Andrey Vagin
avagin at virtuozzo.com
Tue Dec 13 16:33:22 PST 2016
On Tue, Dec 13, 2016 at 05:32:00PM +0300, Pavel Emelyanov wrote:
>
> Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
> ---
> criu/sk-tcp.c | 9 +--------
> soccr/soccr.c | 25 +++++++++++++++++++++----
> soccr/soccr.h | 11 ++++++++---
> 3 files changed, 30 insertions(+), 15 deletions(-)
>
> diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
> index c20f9bc..c8d4069 100644
> --- a/criu/sk-tcp.c
> +++ b/criu/sk-tcp.c
> @@ -257,12 +257,7 @@ static int read_tcp_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data,
> if (read_img_buf(img, buf, len) < 0)
> goto err;
>
> - if (queue == TCP_SEND_QUEUE)
> - data->outq_data = buf;
> - else
> - data->inq_data = buf;
> -
> - return 0;
> + return libsoccr_set_queue_bytes(sk, queue, buf);
>
> err:
> xfree(buf);
> @@ -379,8 +374,6 @@ 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);
someone has to release these buffers...
> tcp_stream_entry__free_unpacked(tse, NULL);
> close_image(img);
> err:
> diff --git a/soccr/soccr.c b/soccr/soccr.c
> index fc5e280..e6d0692 100644
> --- a/soccr/soccr.c
> +++ b/soccr/soccr.c
> @@ -619,7 +619,7 @@ 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,
> +static int libsoccr_restore_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size,
> int queue, char *buf);
>
> int libsoccr_restore(struct libsoccr_sk *sk,
> @@ -630,10 +630,10 @@ int libsoccr_restore(struct libsoccr_sk *sk,
> 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))
> + if (libsoccr_restore_queue(sk, data, sizeof(*data), TCP_RECV_QUEUE, sk->recv_queue))
> return -1;
>
> - if (libsoccr_set_queue_bytes(sk, data, sizeof(*data), TCP_SEND_QUEUE, data->outq_data))
> + if (libsoccr_restore_queue(sk, data, sizeof(*data), TCP_SEND_QUEUE, sk->send_queue))
> return -1;
>
> if (data->flags & SOCCR_FLAGS_WINDOW) {
> @@ -745,9 +745,12 @@ static int send_queue(struct libsoccr_sk *sk, int queue, char *buf, __u32 len)
> return __send_queue(sk, queue, buf, len);
> }
>
> -static int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size,
> +static int libsoccr_restore_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size,
> int queue, char *buf)
> {
> + if (!buf)
> + return 0;
> +
> if (!data || data_size < SOCR_DATA_MIN_SIZE)
> return -1;
>
> @@ -789,3 +792,17 @@ static int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, struct libsoccr_sk_d
>
> return -5;
> }
> +
> +int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, int queue_id, char *bytes)
> +{
> + switch (queue_id) {
> + case TCP_RECV_QUEUE:
> + sk->recv_queue = bytes;
> + return 0;
> + case TCP_SEND_QUEUE:
> + sk->send_queue = bytes;
> + return 0;
> + }
> +
> + return -1;
> +}
> diff --git a/soccr/soccr.h b/soccr/soccr.h
> index 3ab7b90..36043ae 100644
> --- a/soccr/soccr.h
> +++ b/soccr/soccr.h
> @@ -91,9 +91,6 @@ 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;
> };
> @@ -184,6 +181,8 @@ char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal);
> * sk = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
> *
> * h = libsoccr_pause(sk)
> + * libsoccr_set_queue_bytes(h, TCP_SEND_QUEUE, outq);
> + * libsoccr_set_queue_bytes(h, TCP_RECV_QUEUE, inq);
> * libsoccr_restore(h, &data, sizeof(data))
> *
> * libsoccr_resume(h)
> @@ -193,6 +192,12 @@ char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal);
> */
>
> /*
> + * Set a pointer on the send/recv queue data. The buffer is stolen by
> + * the library and is free()-ed after libsoccr_resume().
> + */
> +int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, int queue_id, char *bytes);
> +
> +/*
> * Performs restore actions on bind()-ed socket
> */
> int libsoccr_restore(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size);
> --
> 2.5.0
>
More information about the CRIU
mailing list