]> xenbits.xensource.com Git - people/dwmw2/xen.git/commitdiff
Add lu_stream_{open,close,append}_record()
authorDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 27 Jan 2020 23:46:19 +0000 (23:46 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Fri, 31 Jan 2020 16:47:09 +0000 (16:47 +0000)
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
xen/common/lu/stream.c
xen/include/xen/lu.h

index 8c44a4eb376a21962ffc6d157604a6a1cf10c3dc..2ee870e80ad6b4bbb5f8a17d6d468aa7590c49b9 100644 (file)
@@ -33,6 +33,7 @@
 #include <xen/types.h>
 #include <xen/vmap.h>
 #include <xen/lu.h>
+#include <public/migration_stream.h>
 
 static int lu_stream_extend(struct lu_stream *stream, int nr_pages)
 {
@@ -105,6 +106,55 @@ int lu_stream_append(struct lu_stream *stream, const void *data, size_t size)
     return 0;
 }
 
+int lu_stream_open_record(struct lu_stream *stream, unsigned int type)
+{
+    struct mr_rhdr *hdr;
+
+    stream->last_hdr = stream->len;
+
+    hdr = lu_stream_reserve(stream, sizeof(hdr));
+    if (!hdr)
+        return -ENOMEM;
+
+    hdr->type = type;
+    hdr->length = 0;
+
+    lu_stream_end_reservation(stream, sizeof(*hdr));
+
+    return 0;
+}
+
+int lu_stream_close_record(struct lu_stream *stream)
+{
+    uint64_t zeroes = 0;
+    struct mr_rhdr *hdr;
+    int rc = 0;
+
+    hdr = (struct mr_rhdr *)(stream->data + stream->last_hdr);
+
+    hdr->length = stream->len - stream->last_hdr - sizeof(*hdr);
+
+    if (stream->len & 7)
+        rc = lu_stream_append(stream, &zeroes, 8 - (stream->len & 7));
+
+    return rc;
+}
+
+int lu_stream_append_record(struct lu_stream *stream, unsigned int type,
+                            void *rec, size_t len)
+{
+    int rc;
+
+
+    rc = lu_stream_open_record(stream, type);
+    if (!rc && len)
+        rc = lu_stream_append(stream, rec, len);
+    if (!rc)
+        rc = lu_stream_close_record(stream);
+
+    return 0;
+}
+
 void lu_stream_free(struct lu_stream *stream)
 {
     unsigned int order = get_order_from_bytes((stream->nr_pages + 1) * sizeof(mfn_t));
index 21abace1309468c936ee62366ec34b7ed213d986..c02268e4145123ec570f906a8a2dc334c47f1f6a 100644 (file)
@@ -9,6 +9,7 @@
 
 struct lu_stream {
     mfn_t *pagelist;
+    size_t last_hdr;
     size_t len;
     int nr_pages;
     char *data;
@@ -17,6 +18,10 @@ struct lu_stream {
 void *lu_stream_reserve(struct lu_stream *stream, size_t size);
 void lu_stream_end_reservation(struct lu_stream *stream, size_t size);
 int lu_stream_append(struct lu_stream *stream, const void *data, size_t size);
+int lu_stream_open_record(struct lu_stream *stream, unsigned int type);
+int lu_stream_close_record(struct lu_stream *stream);
+int lu_stream_append_record(struct lu_stream *stream, unsigned int type,
+                            void *rec, size_t len);
 void lu_stream_free(struct lu_stream *stream);
 
 struct kexec_image;