[CRIU] [PATCH 2/4] soccr: Introduce flags for memory passing
Pavel Emelyanov
xemul at virtuozzo.com
Wed Dec 14 01:41:14 PST 2016
There will be calls that return objects from inside library
and vice versa -- accept objects from caller. Let's have a
flag controlling who's going to free the mem in question.
Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
criu/sk-tcp.c | 4 ++--
soccr/soccr.c | 8 ++++++--
soccr/soccr.h | 14 +++++++++++++-
3 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
index c20f9bc..f7eef52 100644
--- a/criu/sk-tcp.c
+++ b/criu/sk-tcp.c
@@ -198,7 +198,7 @@ static int dump_tcp_conn_state(struct inet_sk_desc *sk)
if (ret < 0)
goto err_iw;
- buf = libsoccr_get_queue_bytes(socr, TCP_RECV_QUEUE, 1);
+ buf = libsoccr_get_queue_bytes(socr, TCP_RECV_QUEUE, SOCCR_MEM_EXCL);
if (buf) {
ret = write_img_buf(img, buf, tse.inq_len);
if (ret < 0)
@@ -207,7 +207,7 @@ static int dump_tcp_conn_state(struct inet_sk_desc *sk)
xfree(buf);
}
- buf = libsoccr_get_queue_bytes(socr, TCP_SEND_QUEUE, 1);
+ buf = libsoccr_get_queue_bytes(socr, TCP_SEND_QUEUE, SOCCR_MEM_EXCL);
if (buf) {
ret = write_img_buf(img, buf, tse.outq_len);
if (ret < 0)
diff --git a/soccr/soccr.c b/soccr/soccr.c
index fc5e280..d0c8668 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -354,10 +354,14 @@ int libsoccr_save(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigne
return sizeof(struct libsoccr_sk_data);
}
-char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal)
+#define GET_Q_FLAGS (SOCCR_MEM_EXCL)
+char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, unsigned flags)
{
char **p, *ret;
+ if (flags & ~GET_Q_FLAGS)
+ return NULL;
+
switch (queue_id) {
case TCP_RECV_QUEUE:
p = &sk->recv_queue;
@@ -370,7 +374,7 @@ char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal)
}
ret = *p;
- if (steal)
+ if (flags & SOCCR_MEM_EXCL)
*p = NULL;
return ret;
diff --git a/soccr/soccr.h b/soccr/soccr.h
index 3ab7b90..1e4bfb3 100644
--- a/soccr/soccr.h
+++ b/soccr/soccr.h
@@ -131,6 +131,18 @@ struct libsoccr_sk *libsoccr_pause(int fd);
void libsoccr_resume(struct libsoccr_sk *sk);
/*
+ * Flags for calls below
+ */
+
+/*
+ * Memory given to or taken from library is in exclusive ownership
+ * of the resulting owner. I.e. -- when taken by caller from library,
+ * the former will free() one, when given to the library, the latter
+ * is to free() it.
+ */
+#define SOCCR_MEM_EXCL 0x1
+
+/*
* CHECKPOINTING calls
*
* Roughly the checkpoint steps for sockets in supported states are
@@ -172,7 +184,7 @@ int libsoccr_save(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigne
* library and should free() it himself. Otherwise the buffer can
* be claimed again and will be free by library upon _resume call.
*/
-char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal);
+char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, unsigned flags);
/*
* RESTORING calls
--
2.5.0
More information about the CRIU
mailing list