diff mbox series

[RFC,v3,15/45] multi-process: add support of device id to communication channel

Message ID a7e4930166f395ba424e174386eb8742dee86a49.1567534653.git.jag.raman@oracle.com (mailing list archive)
State New, archived
Headers show
Series Initial support of multi-process qemu | expand

Commit Message

Jag Raman Sept. 3, 2019, 8:37 p.m. UTC
From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 New patch in v3

 include/io/proxy-link.h |  3 +++
 io/proxy-link.c         | 37 ++++++++++++++++++++++++++++++++-----
 2 files changed, 35 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h
index 159c787..0785394 100644
--- a/include/io/proxy-link.h
+++ b/include/io/proxy-link.h
@@ -88,6 +88,7 @@  typedef struct {
     proc_cmd_t cmd;
     int bytestream;
     size_t size;
+    size_t size_id;
 
     union {
         uint64_t u64;
@@ -98,6 +99,8 @@  typedef struct {
     int num_fds;
 
     uint8_t *data2;
+    uint8_t *id;
+
 } ProcMsg;
 
 struct conf_data_msg {
diff --git a/io/proxy-link.c b/io/proxy-link.c
index 381a38e..6f60117 100644
--- a/io/proxy-link.c
+++ b/io/proxy-link.c
@@ -81,7 +81,7 @@  void proxy_link_finalize(ProxyLinkState *s)
 void proxy_proc_send(ProxyLinkState *s, ProcMsg *msg, ProcChannel *chan)
 {
     int rc;
-    uint8_t *data;
+    uint8_t *data, *buf = NULL;
     union {
         char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))];
         struct cmsghdr align;
@@ -140,10 +140,19 @@  void proxy_proc_send(ProxyLinkState *s, ProcMsg *msg, ProcChannel *chan)
         data = (uint8_t *)msg + PROC_HDR_SIZE;
     }
 
+    if (msg->size_id > 0) {
+        buf = calloc(1, msg->size + msg->size_id);
+        assert(buf);
+        memcpy(buf, data, msg->size);
+        memcpy(buf + msg->size, msg->id, msg->size_id);
+        data = buf;
+    }
     do {
-        rc = write(sock, data, msg->size);
+        rc = write(sock, data, msg->size + msg->size_id);
     } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
 
+    free(buf);
+
     qemu_mutex_unlock(lock);
 }
 
@@ -151,7 +160,7 @@  void proxy_proc_send(ProxyLinkState *s, ProcMsg *msg, ProcChannel *chan)
 int proxy_proc_recv(ProxyLinkState *s, ProcMsg *msg, ProcChannel *chan)
 {
     int rc;
-    uint8_t *data;
+    uint8_t *data, *buf = NULL;
     union {
         char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))];
         struct cmsghdr align;
@@ -207,10 +216,28 @@  int proxy_proc_recv(ProxyLinkState *s, ProcMsg *msg, ProcChannel *chan)
         data = (uint8_t *)&msg->data1;
     }
 
-    if (msg->size) {
+     if (msg->size) {
+        if (msg->size_id > 0) {
+            buf = calloc(1, msg->size + msg->size_id);
+            data = buf;
+        }
         do {
-            rc = read(sock, data, msg->size);
+            rc = read(sock, data, msg->size + msg->size_id);
         } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+        if (rc < 0) {
+            fprintf(stderr, "Read sock is an error!\n");
+            return rc;
+        }
+    }
+    if (msg->size && msg->bytestream) {
+        memcpy(msg->data2, data, msg->size);
+    } else {
+        memcpy((uint8_t *)&msg->data1, data, msg->size);
+    }
+
+    if (msg->size_id > 0) {
+        msg->id = calloc(1, msg->size_id);
+        memcpy(msg->id, data + msg->size, msg->size_id);
     }
 
     qemu_mutex_unlock(lock);