]> xenbits.xensource.com Git - people/liuw/qemu.git/commitdiff
fsdev: 9p-marshal: introduce V9fsBlob
authorWei Liu <wei.liu2@citrix.com>
Mon, 30 Nov 2015 15:37:12 +0000 (15:37 +0000)
committerWei Liu <wei.liu2@citrix.com>
Mon, 11 Jan 2016 08:22:14 +0000 (08:22 +0000)
Introduce a concept of blob. It will be used to pack / unpack xattr
value.

With this change there is no need to expose v9fs_pack to device code
anymore.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v3: use 'd' to encode / decode blob size

fsdev/9p-iov-marshal.c
fsdev/9p-marshal.c
fsdev/9p-marshal.h

index 08d783ca1172c6ec397469cdf21c1f3e3422ad09..1f9edf3510ba17924c196595f147772d78fa2245 100644 (file)
@@ -140,6 +140,21 @@ ssize_t v9fs_iov_vunmarshal(struct iovec *out_sg, int out_num, size_t offset,
             }
             break;
         }
+        case 'B': {
+            V9fsBlob *blob = va_arg(ap, V9fsBlob *);
+            copied = v9fs_iov_unmarshal(out_sg, out_num, offset, bswap,
+                                        "d", &blob->size);
+            if (copied > 0) {
+                offset += copied;
+                blob->data = g_malloc(blob->size);
+                copied = v9fs_unpack(blob->data, out_sg, out_num, offset,
+                                     blob->size);
+                if (copied < 0) {
+                    v9fs_blob_free(blob);
+                }
+            }
+            break;
+        }
         case 'Q': {
             V9fsQID *qidp = va_arg(ap, V9fsQID *);
             copied = v9fs_iov_unmarshal(out_sg, out_num, offset, bswap,
@@ -253,6 +268,17 @@ ssize_t v9fs_iov_vmarshal(struct iovec *in_sg, int in_num, size_t offset,
             }
             break;
         }
+        case 'B': {
+            V9fsBlob *blob = va_arg(ap, V9fsBlob *);
+            copied = v9fs_iov_marshal(in_sg, in_num, offset, bswap,
+                                      "d", blob->size);
+            if (copied > 0) {
+                offset += copied;
+                copied = v9fs_pack(in_sg, in_num, offset, blob->data,
+                                   blob->size);
+            }
+            break;
+        }
         case 'Q': {
             V9fsQID *qidp = va_arg(ap, V9fsQID *);
             copied = v9fs_iov_marshal(in_sg, in_num, offset, bswap, "bdq",
index 991e35d24280d70539325b471ec968f0762fb055..a9142445b56b1f2b42bd8e9e414a31ceacaf779e 100644 (file)
@@ -54,3 +54,10 @@ void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs)
     v9fs_string_free(lhs);
     v9fs_string_sprintf(lhs, "%s", rhs->data);
 }
+
+void v9fs_blob_free(V9fsBlob *blob)
+{
+    g_free(blob->data);
+    blob->data = NULL;
+    blob->size = 0;
+}
index e91b24e9ca6918d845f52412b66426179275c9d0..54148f46f56fff63db997eea9dbe45221438507d 100644 (file)
@@ -7,6 +7,12 @@ typedef struct V9fsString
     char *data;
 } V9fsString;
 
+typedef struct V9fsBlob
+{
+    uint32_t size;
+    void *data;
+} V9fsBlob;
+
 typedef struct V9fsQID
 {
     int8_t type;
@@ -81,4 +87,12 @@ extern void v9fs_string_null(V9fsString *str);
 extern void v9fs_string_sprintf(V9fsString *str, const char *fmt, ...);
 extern void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs);
 
+static inline void v9fs_blob_init(V9fsBlob *blob)
+{
+    blob->data = NULL;
+    blob->size = 0;
+}
+
+extern void v9fs_blob_free(V9fsBlob *blob);
+
 #endif