|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 7/7] drbd: implement replicated checkpointing disk
Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
Signed-off-by: Wen Congyang <wency@xxxxxxxxxxxxxx>
---
tools/hotplug/Linux/Makefile | 1 +
tools/hotplug/Linux/block-drbd-probe | 56 ++++++++++++++
tools/libxl/Makefile | 2 +-
tools/libxl/libxl_remus_disk.c | 1 +
tools/libxl/libxl_remus_disk.h | 2 +
tools/libxl/libxl_remus_disk_drbd.c | 132 ++++++++++++++++++++++++++++++++++
6 files changed, 193 insertions(+), 1 deletions(-)
create mode 100755 tools/hotplug/Linux/block-drbd-probe
create mode 100644 tools/libxl/libxl_remus_disk_drbd.c
diff --git a/tools/hotplug/Linux/Makefile b/tools/hotplug/Linux/Makefile
index 6139c1f..b830a8e 100644
--- a/tools/hotplug/Linux/Makefile
+++ b/tools/hotplug/Linux/Makefile
@@ -24,6 +24,7 @@ XEN_SCRIPTS += xen-hotplug-cleanup
XEN_SCRIPTS += external-device-migrate
XEN_SCRIPTS += vscsi
XEN_SCRIPTS += block-iscsi
+XEN_SCRIPTS += block-drbd-probe
XEN_SCRIPTS += $(XEN_SCRIPTS-y)
XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
diff --git a/tools/hotplug/Linux/block-drbd-probe
b/tools/hotplug/Linux/block-drbd-probe
new file mode 100755
index 0000000..432f051
--- /dev/null
+++ b/tools/hotplug/Linux/block-drbd-probe
@@ -0,0 +1,56 @@
+#! /bin/bash
+#
+# Copyright (C) 2014 FUJITSU LIMITED
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Usage:
+# block-drbd-probe devicename
+#
+# Return value:
+# 0: the device is drbd device
+# 1: the device is not drbd device
+
+function get_res_name()
+{
+ local drbd_dev=$1
+ local drbd_dev_list=($(drbdadm sh-dev all))
+ local drbd_res_list=($(drbdadm sh-resource all))
+ local temp_drbd_dev temp_drbd_res
+ local found=0
+
+ for temp_drbd_dev in ${drbd_dev_list[@]}; do
+ if [[ "$temp_drbd_dev" == "$drbd_dev" ]]; then
+ found=1
+ break
+ fi
+ done
+
+ if [[ $found -eq 0 ]]; then
+ return 1
+ fi
+
+ for temp_drbd_res in ${drbd_res_list[@]}; do
+ temp_drbd_dev=$(drbdadm sh-dev $temp_drbd_res)
+ if [[ "$temp_drbd_dev" == "$drbd_dev" ]]; then
+ return 0
+ fi
+ done
+
+ # OOPS
+ return 2
+}
+
+get_res_name $1
+exit $?
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index b040a79..658e1b1 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -53,7 +53,7 @@ LIBXL_OBJS-y += libxl_nonetbuffer.o
endif
LIBXL_OBJS-y += libxl_remus.o
-LIBXL_OBJS-y += libxl_remus_disk.o
+LIBXL_OBJS-y += libxl_remus_disk.o libxl_remus_disk_drbd.o
LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o
LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
diff --git a/tools/libxl/libxl_remus_disk.c b/tools/libxl/libxl_remus_disk.c
index ca3e879..3af43e6 100644
--- a/tools/libxl/libxl_remus_disk.c
+++ b/tools/libxl/libxl_remus_disk.c
@@ -33,6 +33,7 @@ typedef struct libxl__remus_disk_state {
/*** checkpoint disks states and callbacks ***/
static const libxl__remus_disk_type *remus_disk_types[] =
{
+ &drbd_disk_type,
};
int libxl__remus_disk_postsuspend(libxl__remus_state *remus_state)
diff --git a/tools/libxl/libxl_remus_disk.h b/tools/libxl/libxl_remus_disk.h
index 33b0e59..dfd2432 100644
--- a/tools/libxl/libxl_remus_disk.h
+++ b/tools/libxl/libxl_remus_disk.h
@@ -71,4 +71,6 @@ typedef struct libxl__remus_disk_type {
extern void disk_match_script_cb(void *disk_state, int status);
extern void disk_teardown_script_cb(void *disk_state);
+extern const libxl__remus_disk_type drbd_disk_type;
+
#endif
diff --git a/tools/libxl/libxl_remus_disk_drbd.c
b/tools/libxl/libxl_remus_disk_drbd.c
new file mode 100644
index 0000000..719e950
--- /dev/null
+++ b/tools/libxl/libxl_remus_disk_drbd.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2014 FUJITSU LIMITED
+ * Author Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl_osdeps.h" /* must come before any other headers */
+
+#include "libxl_internal.h"
+
+#include "libxl_remus_disk.h"
+
+/*** drbd implementation ***/
+const int DRBD_SEND_CHECKPOINT = 20;
+const int DRBD_WAIT_CHECKPOINT_ACK = 30;
+
+char *drbd_probe_script;
+
+typedef struct libxl__remus_drbd_disk
+{
+ int ctl_fd;
+ int ackwait;
+ const char *path;
+} libxl__remus_drbd_disk;
+
+static int drbd_postsuspend(libxl__remus_disk *remus_disk)
+{
+ struct libxl__remus_drbd_disk *drbd = remus_disk->opaque;
+
+ if (!drbd->ackwait) {
+ if (ioctl(drbd->ctl_fd, DRBD_SEND_CHECKPOINT, 0) <= 0)
+ drbd->ackwait = 1;
+ }
+
+ return 0;
+}
+
+static int drbd_preresume(libxl__remus_disk *remus_disk)
+{
+ struct libxl__remus_drbd_disk *drbd = remus_disk->opaque;
+
+ if (drbd->ackwait) {
+ ioctl(drbd->ctl_fd, DRBD_WAIT_CHECKPOINT_ACK, 0);
+ drbd->ackwait = 0;
+ }
+
+ return 0;
+}
+
+static int drbd_commit(libxl__remus_disk *remus_disk)
+{
+ /* nothing to do, all work are done by DRBD's protocal-D. */
+ return 0;
+}
+
+static int drbd_match(libxl__domain_suspend_state *dss,
+ const libxl_device_disk *disk,
+ libxl_async_exec *async_exec,
+ void *disk_state)
+{
+ int arraysize, nr = 0;
+ STATE_AO_GC(dss->ao);
+
+ if (!drbd_probe_script)
+ drbd_probe_script = GCSPRINTF("%s/block-drbd-probe",
+ libxl__xen_script_dir_path());
+
+ /* setup env & args */
+ arraysize = 1;
+ GCNEW_ARRAY(async_exec->env, arraysize);
+ async_exec->env[nr++] = NULL;
+ assert(nr <= arraysize);
+
+ arraysize = 3;
+ nr = 0;
+ GCNEW_ARRAY(async_exec->args, arraysize);
+ async_exec->args[nr++] = drbd_probe_script;
+ async_exec->args[nr++] = disk->pdev_path;
+ async_exec->args[nr++] = NULL;
+ assert(nr <= arraysize);
+
+ async_exec->finish_cb = disk_match_script_cb;
+ async_exec->opaque = disk_state;
+ async_exec->allow_fail = true;
+ async_exec->timeout = LIBXL_HOTPLUG_TIMEOUT;
+
+ if (libxl_async_exec_script(gc, async_exec))
+ return ERROR_FAIL;
+
+ return 1;
+}
+
+static int drbd_setup(libxl__remus_disk *remus_disk)
+{
+ libxl__remus_drbd_disk *drbd = remus_disk->opaque;
+
+ drbd->path = remus_disk->disk->pdev_path;
+ drbd->ctl_fd = open(drbd->path, O_RDONLY);
+ drbd->ackwait = 0;
+
+ if (drbd->ctl_fd < 0)
+ return ERROR_INVAL;
+
+ return 0;
+}
+
+static int drbd_teardown(libxl__remus_disk *remus_disk, libxl_async_exec
*async_exec)
+{
+ struct libxl__remus_drbd_disk *drbd = remus_disk->opaque;
+
+ close(drbd->ctl_fd);
+ return 0;
+}
+
+const libxl__remus_disk_type drbd_disk_type = {
+ .postsuspend = drbd_postsuspend,
+ .preresume = drbd_preresume,
+ .commit = drbd_commit,
+ .match = drbd_match,
+ .setup = drbd_setup,
+ .teardown = drbd_teardown,
+ .size = sizeof(libxl__remus_drbd_disk),
+};
--
1.7.4.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |