From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: xen-devel@lists.xen.org
Cc: Ian Campbell <ian.campbell@citrix.com>,
FNST-Wen Congyang <wency@cn.fujitsu.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Jiang Yunhong <yunhong.jiang@intel.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Lai Jiangshan <laijs@cn.fujitsu.com>,
Dong Eddie <eddie.dong@intel.com>,
Shriram Rajagopalan <rshriram@cs.ubc.ca>,
FNST-Yang Hongyang <yanghy@cn.fujitsu.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH 1/2] drbd: implement replicated checkpointing disk
Date: Wed, 16 Apr 2014 10:55:59 +0800 [thread overview]
Message-ID: <1397616960-14566-1-git-send-email-laijs@cn.fujitsu.com> (raw)
In-Reply-To: <1397540297-32184-1-git-send-email-yanghy@cn.fujitsu.com>
Implement remus-drbd-replicated-checkpointing-disk based on
generic remus devices framework.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
tools/hotplug/Linux/Makefile | 1 +
tools/hotplug/Linux/block-drbd-probe | 84 +++++++++++++++++
tools/libxl/Makefile | 2 +-
tools/libxl/libxl_remus_device.c | 1 +
tools/libxl/libxl_remus_device.h | 1 +
tools/libxl/libxl_remus_disk_drbd.c | 164 ++++++++++++++++++++++++++++++++++
6 files changed, 252 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 baaaa41..31d9e00 100644
--- a/tools/hotplug/Linux/Makefile
+++ b/tools/hotplug/Linux/Makefile
@@ -23,6 +23,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..163ad04
--- /dev/null
+++ b/tools/hotplug/Linux/block-drbd-probe
@@ -0,0 +1,84 @@
+#! /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
+# 2: unkown error
+# 3: the drbd device does not use protocol D
+# 4: the drbd device is not ready
+
+drbd_res=
+
+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
+ drbd_res="$temp_drbd_res"
+ return 0
+ fi
+ done
+
+ # OOPS
+ return 2
+}
+
+get_res_name $1
+if [[ $? -ne 0 ]]; then
+ exit $?
+fi
+
+# check protocol
+drbdsetup $1 show | grep -q "protocol D;"
+if [[ $? -ne 0 ]]; then
+ exit 3
+fi
+
+# check connect status
+state=$(drbdadm cstate "$drbd_res")
+if [[ "$state" != "Connected" ]]; then
+ exit 4
+fi
+
+# check role
+role=$(drbdadm role "$drbd_res")
+if [[ "$role" != "Primary/Secondary" ]]; then
+ exit 4
+fi
+
+exit 0
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 8398386..53461ab 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -52,7 +52,7 @@ else
LIBXL_OBJS-y += libxl_nonetbuffer.o
endif
-LIBXL_OBJS-y += libxl_remus.o libxl_remus_device.o
+LIBXL_OBJS-y += libxl_remus.o libxl_remus_device.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_device.c b/tools/libxl/libxl_remus_device.c
index 1564bd1..c323773 100644
--- a/tools/libxl/libxl_remus_device.c
+++ b/tools/libxl/libxl_remus_device.c
@@ -38,6 +38,7 @@ typedef struct libxl__remus_device_state {
static libxl__remus_device_type *device_types[] = {
&remus_device_nic,
+ &remus_device_drbd_disk,
};
int libxl__remus_device_postsuspend(libxl__remus_state *remus_state)
diff --git a/tools/libxl/libxl_remus_device.h b/tools/libxl/libxl_remus_device.h
index 30b368d..4b41021 100644
--- a/tools/libxl/libxl_remus_device.h
+++ b/tools/libxl/libxl_remus_device.h
@@ -95,5 +95,6 @@ struct libxl__remus_device {
};
extern libxl__remus_device_type remus_device_nic;
+extern libxl__remus_device_type remus_device_drbd_disk;
#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..583b8a3
--- /dev/null
+++ b/tools/libxl/libxl_remus_disk_drbd.c
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2014 FUJITSU LIMITED
+ * Author Lai Jiangshan <laijs@cn.fujitsu.com>
+ *
+ * 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_device.h"
+
+/*** drbd implementation ***/
+const int DRBD_SEND_CHECKPOINT = 20;
+const int DRBD_WAIT_CHECKPOINT_ACK = 30;
+
+typedef struct libxl__remus_drbd_disk {
+ libxl__remus_device remus_dev;
+ int ctl_fd;
+ int ackwait;
+ const char *path;
+} libxl__remus_drbd_disk;
+
+typedef struct libxl__remus_drbd_state {
+ char *drbd_probe_script;
+ libxl__ao *ao;
+} libxl__remus_drbd_state;
+
+static int drbd_postsuspend(libxl__remus_device *remus_dev)
+{
+ libxl__remus_drbd_disk *drbd_disk =
+ CONTAINER_OF(remus_dev, *drbd_disk, remus_dev);
+
+ if (!drbd_disk->ackwait) {
+ if (ioctl(drbd_disk->ctl_fd, DRBD_SEND_CHECKPOINT, 0) <= 0)
+ drbd_disk->ackwait = 1;
+ }
+
+ return 0;
+}
+
+static int drbd_preresume(libxl__remus_device *remus_dev)
+{
+ libxl__remus_drbd_disk *drbd_disk =
+ CONTAINER_OF(remus_dev, *drbd_disk, remus_dev);
+
+ if (drbd_disk->ackwait) {
+ ioctl(drbd_disk->ctl_fd, DRBD_WAIT_CHECKPOINT_ACK, 0);
+ drbd_disk->ackwait = 0;
+ }
+
+ return 0;
+}
+
+static int drbd_commit(libxl__remus_device *remus_dev)
+{
+ /* nothing to do, all work are done by DRBD's protocal-D. */
+ return 0;
+}
+
+static int drbd_init(libxl__remus_device_type *self,
+ libxl__remus_state *remus_state)
+{
+ libxl__remus_drbd_state *drbd_state;
+
+ STATE_AO_GC(remus_state->dss->ao);
+
+ GCNEW(drbd_state);
+ self->data = drbd_state;
+ drbd_state->ao = ao;
+ drbd_state->drbd_probe_script = GCSPRINTF("%s/block-drbd-probe",
+ libxl__xen_script_dir_path());
+
+
+ return REMUS_OK;
+}
+
+static void drbd_destroy(libxl__remus_device_type *self)
+{
+ return;
+}
+
+static int drbd_match(const libxl__remus_device_type *self,
+ const void *libxl_device, int device_type,
+ libxl_async_exec *async_exec)
+{
+ int arraysize, nr = 0;
+ const libxl_device_disk *disk = libxl_device;
+ libxl__remus_drbd_state *drbd_state = self->data;
+ STATE_AO_GC(drbd_state->ao);
+
+ if (device_type != REMUS_DISK)
+ return REMUS_NOT_SUPPORT;
+
+ /* 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_state->drbd_probe_script;
+ async_exec->args[nr++] = disk->pdev_path;
+ async_exec->args[nr++] = NULL;
+ assert(nr <= arraysize);
+
+ async_exec->allow_fail = true;
+ async_exec->timeout = LIBXL_HOTPLUG_TIMEOUT;
+
+ if (libxl_async_exec_script(gc, async_exec))
+ return REMUS_FAIL;
+
+ return REMUS_INPROGRESS;
+}
+
+static int drbd_setup(libxl__remus_device *remus_dev,
+ libxl_async_exec *async_exec)
+{
+ libxl__remus_drbd_disk *drbd_disk =
+ CONTAINER_OF(remus_dev, *drbd_disk, remus_dev);
+ const libxl_device_disk *disk = remus_dev->libxl_device;
+
+ drbd_disk->path = disk->pdev_path;
+ drbd_disk->ctl_fd = open(drbd_disk->path, O_RDONLY);
+ drbd_disk->ackwait = 0;
+
+ if (drbd_disk->ctl_fd < 0)
+ return REMUS_FAIL;
+
+ return REMUS_OK;
+}
+
+static int drbd_teardown(libxl__remus_device *remus_dev,
+ libxl_async_exec *async_exec)
+{
+ libxl__remus_drbd_disk *drbd_disk =
+ CONTAINER_OF(remus_dev, *drbd_disk, remus_dev);
+
+ close(drbd_disk->ctl_fd);
+ return REMUS_OK;
+}
+
+libxl__remus_device_type remus_device_drbd_disk = {
+ .init = drbd_init,
+ .destroy = drbd_destroy,
+ .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
next prev parent reply other threads:[~2014-04-16 2:55 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-15 5:38 [PATCH V9 00/12] Remus/Libxl: Network buffering support Yang Hongyang
2014-04-15 5:38 ` [PATCH V9 01/12] introduce an API to async exec scripts Yang Hongyang
2014-04-23 15:44 ` Ian Jackson
2014-04-15 5:38 ` [PATCH V9 02/12] libxl_device: use async exec script api Yang Hongyang
2014-04-23 15:48 ` Ian Jackson
2014-04-15 5:38 ` [PATCH V9 03/12] remus: add libnl3 dependency to autoconf scripts Yang Hongyang
2014-04-15 5:38 ` [PATCH V9 04/12] remus: introduce a function to check whether network buffering is enabled Yang Hongyang
2014-04-23 15:50 ` Ian Jackson
2014-04-23 15:51 ` Shriram Rajagopalan
2014-04-30 14:36 ` Ian Jackson
2014-04-15 5:38 ` [PATCH V9 05/12] remus: remus device core and APIs to setup/teardown Yang Hongyang
2014-04-15 5:38 ` [PATCH V9 06/12] remus: implement the API for checkpoint Yang Hongyang
2014-04-23 16:04 ` Ian Jackson
2014-05-14 1:46 ` Hongyang Yang
2014-04-15 5:38 ` [PATCH V9 07/12] remus: Remus network buffering core and APIs to setup/teardown Yang Hongyang
2014-04-15 5:38 ` [PATCH V9 08/12] remus: implement the API to buffer/release packages Yang Hongyang
2014-04-23 16:10 ` Ian Jackson
2014-04-23 17:04 ` Shriram Rajagopalan
2014-05-02 16:10 ` Ian Jackson
2014-04-15 5:38 ` [PATCH V9 09/12] libxl: use the API to setup/teardown network buffering Yang Hongyang
2014-04-23 16:12 ` Ian Jackson
2014-04-16 2:55 ` Lai Jiangshan [this message]
2014-04-16 2:56 ` [PATCH 2/2] remus: support disk replicated checkpointing Lai Jiangshan
2014-04-23 9:53 ` [PATCH V9 00/12] Remus/Libxl: Network buffering support Hongyang Yang
2014-04-23 15:51 ` Ian Jackson
-- strict thread matches above, loose matches on Subject: below --
2014-04-02 11:04 [PATCH V8 0/8] " Yang Hongyang
2014-04-02 11:04 ` [PATCH V8 1/8] remus: add libnl3 dependency to autoconf scripts Yang Hongyang
2014-04-02 11:04 ` [PATCH V8 2/8] remus: introduce a function to check whether network buffering is enabled Yang Hongyang
2014-04-02 11:04 ` [PATCH V8 3/8] remus: Remus network buffering core and APIs to setup/teardown Yang Hongyang
2014-02-10 9:19 ` [PATCH 00/10 V7] Remus/Libxl: Network buffering support Lai Jiangshan
2014-02-10 9:19 ` [PATCH 01/10 V7] remus: add libnl3 dependency to autoconf scripts Lai Jiangshan
2014-02-10 9:19 ` [PATCH 02/10 V7] tools/libxl: update libxl_domain_remus_info Lai Jiangshan
2014-03-03 16:33 ` Ian Jackson
2014-02-10 9:19 ` [PATCH 03/10 V7] tools/libxl: introduce a new structure libxl__remus_state Lai Jiangshan
2014-03-03 16:38 ` Ian Jackson
2014-02-10 9:19 ` [PATCH 04/10 V7] remus: introduce a function to check whether network buffering is enabled Lai Jiangshan
2014-03-03 16:39 ` Ian Jackson
2014-02-10 9:19 ` [PATCH 05/10 V7] remus: Remus network buffering core and APIs to setup/teardown Lai Jiangshan
2014-03-03 17:44 ` Ian Jackson
2014-04-03 14:06 ` [PATCH 05/10 V7] remus: Remus network buffering core and APIs to setup/teardown [and 1 more messages] Ian Jackson
2014-02-10 9:19 ` [PATCH 06/10 V7] remus: implement the API to buffer/release packages Lai Jiangshan
2014-03-03 17:48 ` Ian Jackson
2014-02-10 9:19 ` [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering Lai Jiangshan
2014-03-03 17:51 ` Ian Jackson
2014-04-23 16:02 ` [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages] Ian Jackson
2014-04-23 16:55 ` Shriram Rajagopalan
2014-05-02 16:08 ` Ian Jackson
2014-05-02 21:59 ` Shriram Rajagopalan
2014-05-07 5:42 ` Hongyang Yang
2014-05-07 13:12 ` Shriram Rajagopalan
2014-05-12 13:18 ` Ian Jackson
2014-05-13 1:41 ` Hongyang Yang
2014-02-10 9:19 ` [PATCH 08/10 V7] libxl: rename remus_failover_cb() to remus_replication_failure_cb() Lai Jiangshan
2014-03-03 17:52 ` Ian Jackson
2014-02-10 9:19 ` [PATCH 09/10 V7] libxl: control network buffering in remus callbacks Lai Jiangshan
2014-03-03 17:54 ` Ian Jackson
2014-02-10 9:19 ` [PATCH 10/10 V7] libxl: network buffering cmdline switch Lai Jiangshan
2014-03-03 17:58 ` Ian Jackson
2014-02-26 2:31 ` [PATCH 00/10 V7] Remus/Libxl: Network buffering support Lai Jiangshan
2014-02-26 2:53 ` [PATCH RFC] remus: implement remus replicated checkpointing disk Lai Jiangshan
2014-03-10 11:28 ` Ian Jackson
2014-03-10 12:34 ` Lai Jiangshan
2014-03-10 16:19 ` Ian Jackson
2014-03-11 18:10 ` Shriram Rajagopalan
2014-03-12 2:35 ` Lai Jiangshan
2014-03-12 6:23 ` Shriram Rajagopalan
2014-03-12 10:07 ` Ian Campbell
2014-03-12 11:57 ` Lai Jiangshan
2014-03-12 12:17 ` Ian Campbell
2014-03-12 12:28 ` Lai Jiangshan
2014-03-12 10:06 ` Ian Campbell
2014-03-12 12:21 ` Lai Jiangshan
2014-04-02 11:04 ` [PATCH V8 4/8] remus: implement the API to buffer/release packages Yang Hongyang
2014-04-02 11:04 ` [PATCH V8 5/8] libxl: use the API to setup/teardown network buffering Yang Hongyang
2014-04-02 11:04 ` [PATCH V8 6/8] libxl: rename remus_failover_cb() to remus_replication_failure_cb() Yang Hongyang
2014-04-02 11:04 ` [PATCH V8 7/8] libxl: control network buffering in remus callbacks Yang Hongyang
2014-04-02 11:04 ` [PATCH V8 8/8] libxl: network buffering cmdline switch Yang Hongyang
2014-04-03 12:22 ` [PATCH 1/7] introduce a new function libxl__remus_netbuf_setup_done() Lai Jiangshan
2014-04-03 12:22 ` [PATCH 2/7] introduce a new function libxl__remus_netbuf_teardown_done() Lai Jiangshan
2014-04-03 12:22 ` [PATCH 3/7] introduce an API to async exec scripts Lai Jiangshan
2014-04-03 12:22 ` [PATCH 4/7] netbuffer: use async exec API to exec the netbuffer script Lai Jiangshan
2014-04-03 12:22 ` [PATCH 5/7] netbuf: move dev_id from remus_state to netbuf_state Lai Jiangshan
2014-04-03 12:22 ` [PATCH 6/7] remus: implement remus replicated checkpointing disk Lai Jiangshan
2014-04-03 16:41 ` Shriram Rajagopalan
2014-04-04 3:04 ` Lai Jiangshan
2014-04-03 12:22 ` [PATCH 7/7] drbd: implement " Lai Jiangshan
2014-04-03 16:07 ` Shriram Rajagopalan
2014-04-03 14:08 ` [PATCH 1/7] introduce a new function libxl__remus_netbuf_setup_done() Ian Jackson
2014-04-04 8:53 ` Hongyang Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1397616960-14566-1-git-send-email-laijs@cn.fujitsu.com \
--to=laijs@cn.fujitsu.com \
--cc=andrew.cooper3@citrix.com \
--cc=eddie.dong@intel.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=roger.pau@citrix.com \
--cc=rshriram@cs.ubc.ca \
--cc=stefano.stabellini@eu.citrix.com \
--cc=wency@cn.fujitsu.com \
--cc=xen-devel@lists.xen.org \
--cc=yanghy@cn.fujitsu.com \
--cc=yunhong.jiang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).