Skip to contentSkip to conversation

Log-dirty shared memory between stubdom-dm and xc_save

PATCH In review Yosuke Iwamatsu 1 participant 1 message Dec 16, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 2/4 Log-dirty shared memory between stubdom-dm and xc_save

Allocate the log-dirty shared memory segment in the stubdom-dm and map the memory region into the xc_save process by using grant table interface.

Thanks,
-----------------------
Yosuke Iwamatsu
NEC Corporation

Create log-dirty shared memory between stubdom-dm and xc_save. Allocate the log-dirty shared memory segment in the stubdom-dm and map the memory region into the xc_save process by using grant table interface.

extras/mini-os/logdirty.c new file +135 -0
diff -r 6595393a3d28 extras/mini-os/logdirty.c
@@ -0,0 +1,135 @@
+/******************************************************************************
+ * logdirty.c
+ * 
+ * Log-dirty bitmap allocator for Mini-OS.
+ * 
+ * Copyright (c) 2008, NEC Corporation.
+ *      Yosuke Iwamatsu <y-iwamatsu at ab jp nec com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <os.h>
+#include <xenbus.h>
+#include <gnttab.h>
+#include <lib.h>
+#include <xen/io/logdirty.h>
+
+#define GRANT_INVALID_REF 0
+
+static grant_ref_t ring_ref = GRANT_INVALID_REF;
+static struct logdirty_shared_info *sh_info = NULL;
+static void *seg = NULL;
+
+static void free_logdirty_bitmap(void)
+{
+    int i;
+
+    if (ring_ref == GRANT_INVALID_REF)
+        return;
+
+    if (!sh_info)
+        goto end_ring_access;
+
+    if (!seg)
+        goto free_sh_info;
+
+    for (i = 0; i < sh_info->count; i++)
+        gnttab_end_access(sh_info->gref[i]);
+    free_pages(seg, sh_info->count);
+    seg = NULL;
+
+  free_sh_info:
+    free_page(sh_info);
+    sh_info = NULL;
+
+  end_ring_access:
+    gnttab_end_access(ring_ref);
+    ring_ref = GRANT_INVALID_REF;
+}
+
+void *init_logdirty_bitmap(char *_nodename, unsigned long size, domid_t backend)
+{
+    unsigned int page_count;
+    int i;
+    xenbus_transaction_t xbt;
+    char *err;
+    char *message = NULL;
+    int retry = 0;
+
+    printk("Initialising logdirty bitmap\n");
+
+    page_count = ((2 * size - 1) >> PAGE_SHIFT) + 1;
+    if (page_count > LOGDIRTY_MAX_PAGE_COUNT) {
+        printk("Log dirty bitmap size too large: %u", size);
+        goto error;
+    }
+    
+    sh_info = (struct logdirty_shared_info *)alloc_page();
+    memset(sh_info, 0, PAGE_SIZE);
+    sh_info->count = page_count;
+
+    seg = (void *)alloc_pages(get_order(2 * size));
+    memset(seg, 0, sh_info->count * PAGE_SIZE);
+    for (i = 0; i < sh_info->count; i++)
+        sh_info->gref[i] =
+            gnttab_grant_access(backend,
+                                virt_to_mfn((char *)seg + i * PAGE_SIZE),
+                                0);
+
+    ring_ref = gnttab_grant_access(backend, virt_to_mfn(sh_info), 0);
+ 
+ again:
+    err = xenbus_transaction_start(&xbt);
+    if (err) {
+        printk("starting transaction\n");
+    }
+
+    err = xenbus_printf(xbt, _nodename, "ring-ref", "%u", ring_ref);
+    if (err) {
+        message = "writing ring-ref";
+        goto abort_transaction;
+    }
+
+    err = xenbus_printf(xbt, _nodename, "domid", "%u", xenbus_get_self_id());
+    if (err) {
+        message = "writing domid";
+        goto abort_transaction;
+    }
+
+    err = xenbus_transaction_end(xbt, 0, &retry);
+    if (retry) {
+            goto again;
+        printk("completing transaction\n");
+    }
+
+    goto done;
+
+ abort_transaction:
+    xenbus_transaction_end(xbt, 1, &retry);
+    goto error;
+
+ done:
+    return seg;
+
+ error:
+    free_logdirty_bitmap();
+    return NULL;
+}
+
tools/libxc/xenguest.h +1 -0
diff -r 6595393a3d28 tools/libxc/xenguest.h
@@ -13,6 +13,7 @@
 #define XCFLAGS_DEBUG     2
 #define XCFLAGS_HVM       4
 #define XCFLAGS_STDVGA    8
+#define XCFLAGS_STUBDOM  16
 
 
 /**
tools/xcutils/xc_save.c +144 -2

190 lines not on this page · raw message

xen/include/public/io/logdirty.h new file +52 -0

52 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel