[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Xen-devel] [PATCH 17/17] HACK: libxl/remus: setup and control disk replication for blktap2 backends
On Oct 13, 2014 10:15 PM, "Wen Congyang" <wency@xxxxxxxxxxxxxx> wrote:
>
> Just for test
What do you mean? You would like these to be reviewed but not committed?
>
> Signed-off-by: Wen Congyang <wency@xxxxxxxxxxxxxx>
> ---
> Âtools/libxl/Makefile         | Â2 +-
> Âtools/libxl/libxl_create.c      | Â8 ++
> Âtools/libxl/libxl_internal.h     | Â2 +
> Âtools/libxl/libxl_remus_device.c   | Â6 +
> Âtools/libxl/libxl_remus_disk_blktap.c | 209 ++++++++++++++++++++++++++++++++++
> Â5 files changed, 226 insertions(+), 1 deletion(-)
> Âcreate mode 100644 tools/libxl/libxl_remus_disk_blktap.c
>
> diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
> index 0bf666f..b58c2ff 100644
> --- a/tools/libxl/Makefile
> +++ b/tools/libxl/Makefile
> @@ -56,7 +56,7 @@ else
> ÂLIBXL_OBJS-y += libxl_nonetbuffer.o
> Âendif
>
> -LIBXL_OBJS-y += libxl_remus_device.o libxl_remus_disk_drbd.o
> +LIBXL_OBJS-y += libxl_remus_device.o libxl_remus_disk_drbd.o libxl_remus_disk_blktap.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_create.c b/tools/libxl/libxl_create.c
> index 8b82584..e634694 100644
> --- a/tools/libxl/libxl_create.c
> +++ b/tools/libxl/libxl_create.c
> @@ -853,6 +853,14 @@ static void initiate_domain_create(libxl__egc *egc,
> Â Â Âfor (i = 0; i < d_config->num_disks; i++) {
> Â Â Â Â Âret = libxl__device_disk_setdefault(gc, &d_config->disks[i]);
> Â Â Â Â Âif (ret) goto error_out;
> +
> +Â Â Â Â /* TODO: cleanup it when destroying the domain */
> +Â Â Â Â if (d_config->disks[i].backend == LIBXL_DISK_BACKEND_TAP &&
> +Â Â Â Â Â Â d_config->disks[i].filter)
> +Â Â Â Â Â Â libxl__blktap_devpath(gc, d_config->disks[i].pdev_path,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â d_config->disks[i].format,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â d_config->disks[i].filter,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â d_config->disks[i].filter_params);
> Â Â Â}
>
> Â Â Âdcs->bl.ao = ao;
> diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
> index 282b03f..a7c2334 100644
> --- a/tools/libxl/libxl_internal.h
> +++ b/tools/libxl/libxl_internal.h
> @@ -2672,6 +2672,8 @@ int init_subkind_nic(libxl__remus_devices_state *rds);
> Âvoid cleanup_subkind_nic(libxl__remus_devices_state *rds);
> Âint init_subkind_drbd_disk(libxl__remus_devices_state *rds);
> Âvoid cleanup_subkind_drbd_disk(libxl__remus_devices_state *rds);
> +int init_subkind_blktap_disk(libxl__remus_devices_state *rds);
> +void cleanup_subkind_blktap_disk(libxl__remus_devices_state *rds);
>
> Âtypedef void libxl__remus_callback(libxl__egc *,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â libxl__remus_devices_state *, int rc);
> diff --git a/tools/libxl/libxl_remus_device.c b/tools/libxl/libxl_remus_device.c
> index a6cb7f6..ef272ac 100644
> --- a/tools/libxl/libxl_remus_device.c
> +++ b/tools/libxl/libxl_remus_device.c
> @@ -19,9 +19,11 @@
>
> Âextern const libxl__remus_device_instance_ops remus_device_nic;
> Âextern const libxl__remus_device_instance_ops remus_device_drbd_disk;
> +extern const libxl__remus_device_instance_ops remus_device_blktap2_disk;
> Âstatic const libxl__remus_device_instance_ops *remus_ops[] = {
> Â Â Â&remus_device_nic,
> Â Â Â&remus_device_drbd_disk,
> +Â Â &remus_device_blktap2_disk,
> Â Â ÂNULL,
> Â};
>
> @@ -41,6 +43,9 @@ static int init_device_subkind(libxl__remus_devices_state *rds)
> Â Â Ârc = init_subkind_drbd_disk(rds);
> Â Â Âif (rc) goto out;
>
> +Â Â rc = init_subkind_blktap_disk(rds);
> +Â Â if (rc) goto out;
> +
> Â Â Ârc = 0;
> Âout:
> Â Â Âreturn rc;
> @@ -55,6 +60,7 @@ static void cleanup_device_subkind(libxl__remus_devices_state *rds)
> Â Â Â Â Âcleanup_subkind_nic(rds);
>
> Â Â Âcleanup_subkind_drbd_disk(rds);
> +Â Â cleanup_subkind_blktap_disk(rds);
> Â}
>
> Â/*----- setup() and teardown() -----*/
> diff --git a/tools/libxl/libxl_remus_disk_blktap.c b/tools/libxl/libxl_remus_disk_blktap.c
> new file mode 100644
> index 0000000..3ae77d6
> --- /dev/null
> +++ b/tools/libxl/libxl_remus_disk_blktap.c
> @@ -0,0 +1,209 @@
> +/*
> + * Copyright (C) 2014 FUJITSU LIMITED
> + * Author Wen Congyang <wency@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 <string.h>
> +#include <sys/un.h>
> +
> +#define  ÂBLKTAP2_REQUEST  Â"flush"
> +#define  ÂBLKTAP2_RESPONSE  "done"
> +#define  ÂBLKTAP_CTRL_DIR  Â"/var/run/tap"
> +
> +typedef struct libxl__remus_blktap2_disk {
> +Â Â char *name;
> +Â Â char *ctl_fifo_path;
> +Â Â char *msg_fifo_path;
> +Â Â int ctl_fd;
> +Â Â int msg_fd;
> +Â Â libxl__ev_fd ev;
> +Â Â libxl__remus_device *dev;
> +}libxl__remus_blktap2_disk;
> +
> +int init_subkind_blktap_disk(libxl__remus_devices_state *rds)
> +{
> +Â Â return 0;
> +}
> +
> +void cleanup_subkind_blktap_disk(libxl__remus_devices_state *rds)
> +{
> +Â Â return;
> +}
> +/* ========== setup() and teardown() ========== */
> +static void blktap2_remus_setup(libxl__egc *egc, libxl__remus_device *dev)
> +{
> +Â Â const libxl_device_disk *disk = dev->backend_dev;
> +Â Â libxl__remus_blktap2_disk *blktap2_disk;
> +Â Â int rc;
> +Â Â int i, l;
> +
> +Â Â STATE_AO_GC(dev->rds->ao);
> +
> +Â Â if (disk->backend != LIBXL_DISK_BACKEND_TAP ||
> +Â Â Â Â !disk->filter ||
> +Â Â Â Â strcmp(disk->filter, "remus")) {
> +Â Â Â Â rc = ERROR_REMUS_DEVOPS_DOES_NOT_MATCH;
> +Â Â Â Â goto out;
> +Â Â }
> +
> +Â Â dev->matched = 1;
> +Â Â GCNEW(blktap2_disk);
> +Â Â dev->concrete_data = blktap2_disk;
> +Â Â blktap2_disk->ctl_fd = -1;
> +Â Â blktap2_disk->msg_fd = -1;
> +Â Â blktap2_disk->dev = dev;
> +
> +Â Â blktap2_disk->name = libxl__strdup(gc, disk->filter_params);
> +Â Â blktap2_disk->ctl_fifo_path = GCSPRINTF("%s/remus_%s",
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â BLKTAP_CTRL_DIR,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â blktap2_disk->name);
> +Â Â /* scrub fifo pathname */
> +Â Â l = strlen(blktap2_disk->ctl_fifo_path);
> +Â Â for (i = strlen(BLKTAP_CTRL_DIR) + 1; i < l; i++) {
> +Â Â Â Â if (strchr(":/", blktap2_disk->ctl_fifo_path[i]))
> +Â Â Â Â Â Â blktap2_disk->ctl_fifo_path[i] = '_';
> +Â Â }
> +Â Â blktap2_disk->msg_fifo_path = GCSPRINTF("%s.msg",
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â blktap2_disk->ctl_fifo_path);
> +
> +Â Â blktap2_disk->ctl_fd = open(blktap2_disk->ctl_fifo_path, O_WRONLY);
> +Â Â blktap2_disk->msg_fd = open(blktap2_disk->msg_fifo_path, O_RDONLY);
> +Â Â if (blktap2_disk->ctl_fd < 0 || blktap2_disk->msg_fd < 0) {
> +Â Â Â Â rc = ERROR_FAIL;
> +Â Â Â Â goto out;
> +Â Â }
> +
> +Â Â libxl__ev_fd_init(&blktap2_disk->ev);
> +
> +Â Â rc = 0;
> +
> +out:
> +Â Â dev->aodev.rc = rc;
> +Â Â dev->aodev.callback(egc, &dev->aodev);
> +}
> +
> +static void blktap2_remus_teardown(libxl__egc *egc,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âlibxl__remus_device *dev)
> +{
> +Â Â libxl__remus_blktap2_disk *blktap2_disk = dev->concrete_data;
> +
> +Â Â if (blktap2_disk->ctl_fd > 0) {
> +Â Â Â Â close(blktap2_disk->ctl_fd);
> +Â Â Â Â blktap2_disk->ctl_fd = -1;
> +Â Â }
> +
> +Â Â if (blktap2_disk->msg_fd > 0) {
> +Â Â Â Â close(blktap2_disk->msg_fd);
> +Â Â Â Â blktap2_disk->msg_fd = -1;
> +Â Â }
> +
> +Â Â dev->aodev.rc = 0;
> +Â Â dev->aodev.callback(egc, &dev->aodev);
> +}
> +
> +/* ========== checkpointing APIs ========== */
> +/*
> + * When a new checkpoint is triggered, we do the following thing:
> + *Â 1. send BLKTAP2_REQUEST to tapdisk2
> + *Â 2. tapdisk2 send "creq"
> + *Â 3. secondary vm's tapdisk2 reply "done"
> + *Â 4. tapdisk2 writes BLKTAP2_RESPONSE to the socket
> + *Â 5. read BLKTAP2_RESPONSE from the socket
> + * Step1 and 5 are implemented here.
> + */
> +static void blktap2_control_readable(libxl__egc *egc, libxl__ev_fd *ev,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âint fd, short events, short revents);
> +
> +static void blktap2_remus_postsuspend(libxl__egc *egc,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â libxl__remus_device *dev)
> +{
> +Â Â int ret;
> +Â Â libxl__remus_blktap2_disk *blktap2_disk = dev->concrete_data;
> +Â Â int rc = 0;
> +
> +Â Â /* fifo fd, and not block */
> +Â Â ret = write(blktap2_disk->ctl_fd, BLKTAP2_REQUEST, strlen(BLKTAP2_REQUEST));
> +Â Â if (ret < strlen(BLKTAP2_REQUEST))
> +Â Â Â Â rc = ERROR_FAIL;
> +
> +Â Â dev->aodev.rc = rc;
> +Â Â dev->aodev.callback(egc, &dev->aodev);
> +}
> +
> +static void blktap2_remus_commit(libxl__egc *egc,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âlibxl__remus_device *dev)
> +{
> +Â Â libxl__remus_blktap2_disk *blktap2_disk = dev->concrete_data;
> +Â Â int rc;
> +
> +Â Â /* Convenience aliases */
> +Â Â const int fd = blktap2_disk->msg_fd;
> +Â Â libxl__ev_fd *const ev = &blktap2_disk->ev;
> +
> +Â Â STATE_AO_GC(dev->rds->ao);
> +
> +Â Â rc = libxl__ev_fd_register(gc, ev, blktap2_control_readable, fd, POLLIN);
> +Â Â if (rc) {
> +Â Â Â Â dev->aodev.rc = rc;
> +Â Â Â Â dev->aodev.callback(egc, &dev->aodev);
> +Â Â }
> +}
> +
> +static void blktap2_control_readable(libxl__egc *egc, libxl__ev_fd *ev,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âint fd, short events, short revents)
> +{
> +Â Â libxl__remus_blktap2_disk *blktap2_disk =
> +Â Â Â Â Â Â Â Â CONTAINER_OF(ev, *blktap2_disk, ev);
> +Â Â int rc = 0, ret;
> +Â Â char response[5];
> +
> +Â Â /* Convenience aliases */
> +Â Â libxl__remus_device *const dev = blktap2_disk->dev;
> +
> +Â Â EGC_GC;
> +
> +Â Â libxl__ev_fd_deregister(gc, ev);
> +
> +Â Â if (revents & ~POLLIN) {
> +Â Â Â Â LOG(ERROR, "unexpected poll event 0x%x (should be POLLIN)", revents);
> +Â Â Â Â rc = ERROR_FAIL;
> +Â Â Â Â goto out;
> +Â Â }
> +
> +Â Â ret = read(fd, response, sizeof(response) - 1);
> +Â Â if (ret < sizeof(response) - 1) {
> +Â Â Â Â rc = ERROR_FAIL;
> +Â Â Â Â goto out;
> +Â Â }
> +
> +Â Â response[4] = '\0';
> +Â Â if (strcmp(response, BLKTAP2_RESPONSE))
> +Â Â Â Â rc = ERROR_FAIL;
> +
> +out:
> +Â Â dev->aodev.rc = rc;
> +Â Â dev->aodev.callback(egc, &dev->aodev);
> +}
> +
> +
> +const libxl__remus_device_instance_ops remus_device_blktap2_disk = {
> +Â Â .kind = LIBXL__DEVICE_KIND_VBD,
> +Â Â .setup = blktap2_remus_setup,
> +Â Â .teardown = blktap2_remus_teardown,
> +Â Â .postsuspend = blktap2_remus_postsuspend,
> +Â Â .commit = blktap2_remus_commit,
> +};
> --
> 1.9.3
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@xxxxxxxxxxxxx
> http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|