Commit 4b9b56b2 authored by Pavel Emelyanov's avatar Pavel Emelyanov

soccr: Introduce flags for memory passing

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: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Acked-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 332b945f
...@@ -198,7 +198,7 @@ static int dump_tcp_conn_state(struct inet_sk_desc *sk) ...@@ -198,7 +198,7 @@ static int dump_tcp_conn_state(struct inet_sk_desc *sk)
if (ret < 0) if (ret < 0)
goto err_iw; 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) { if (buf) {
ret = write_img_buf(img, buf, tse.inq_len); ret = write_img_buf(img, buf, tse.inq_len);
if (ret < 0) if (ret < 0)
...@@ -207,7 +207,7 @@ static int dump_tcp_conn_state(struct inet_sk_desc *sk) ...@@ -207,7 +207,7 @@ static int dump_tcp_conn_state(struct inet_sk_desc *sk)
xfree(buf); 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) { if (buf) {
ret = write_img_buf(img, buf, tse.outq_len); ret = write_img_buf(img, buf, tse.outq_len);
if (ret < 0) if (ret < 0)
......
...@@ -354,10 +354,14 @@ int libsoccr_save(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigne ...@@ -354,10 +354,14 @@ int libsoccr_save(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigne
return sizeof(struct libsoccr_sk_data); 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; char **p, *ret;
if (flags & ~GET_Q_FLAGS)
return NULL;
switch (queue_id) { switch (queue_id) {
case TCP_RECV_QUEUE: case TCP_RECV_QUEUE:
p = &sk->recv_queue; p = &sk->recv_queue;
...@@ -370,7 +374,7 @@ char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal) ...@@ -370,7 +374,7 @@ char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal)
} }
ret = *p; ret = *p;
if (steal) if (flags & SOCCR_MEM_EXCL)
*p = NULL; *p = NULL;
return ret; return ret;
......
...@@ -130,6 +130,18 @@ struct libsoccr_sk_data { ...@@ -130,6 +130,18 @@ struct libsoccr_sk_data {
struct libsoccr_sk *libsoccr_pause(int fd); struct libsoccr_sk *libsoccr_pause(int fd);
void libsoccr_resume(struct libsoccr_sk *sk); 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 * CHECKPOINTING calls
* *
...@@ -172,7 +184,7 @@ int libsoccr_save(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigne ...@@ -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 * library and should free() it himself. Otherwise the buffer can
* be claimed again and will be free by library upon _resume call. * 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 * RESTORING calls
......
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