[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 14/17] block-remus: switch to unprotected mode before closing



On Oct 13, 2014 10:13 PM, "Wen Congyang" <wency@xxxxxxxxxxxxxx> wrote:
>
> If the user wants to stop tapdisk2, he will do
> the following thing:
> 1. close the image
> 2. detach from blktap device
>
> If there is some pending I/O request, close will
> fail. But the I/O request is pended in remus until
> the connection is established. Introduce a new
> callback td_pre_close() to flush these I/O requests.
>
> Signed-off-by: Wen Congyang <wency@xxxxxxxxxxxxxx>
> Cc: Shriram Rajagopalan <rshriram@xxxxxxxxx>
> ---
> Âtools/blktap2/drivers/block-remus.c   Â| 14 ++++++++++++++
> Âtools/blktap2/drivers/block-replication.h |Â 1 +
> Âtools/blktap2/drivers/tapdisk-control.c Â| 6 ++++++
> Âtools/blktap2/drivers/tapdisk-interface.c | 18 ++++++++++++++++++
> Âtools/blktap2/drivers/tapdisk-interface.h |Â 1 +
> Âtools/blktap2/drivers/tapdisk-vbd.c   Â| 9 +++++++++
> Âtools/blktap2/drivers/tapdisk-vbd.h   Â| 1 +
> Âtools/blktap2/drivers/tapdisk.h     Â| 1 +
> Â8 files changed, 51 insertions(+)
>
> diff --git a/tools/blktap2/drivers/block-remus.c b/tools/blktap2/drivers/block-remus.c
> index a2b9f62..09dc46f 100644
> --- a/tools/blktap2/drivers/block-remus.c
> +++ b/tools/blktap2/drivers/block-remus.c
> @@ -752,6 +752,8 @@ static void primary_failed(struct tdremus_state *s, int rc)
> Â Â Â Â td_replication_connect_kill(&s->t);
> Â Â Â Â if (rc == ERROR_INTERNAL)
> Â Â Â Â Â Â Â Â RPRINTF("switch to unprotected mode due to internal error");
> +Â Â Â Âif (rc == ERROR_CLOSE)
> +Â Â Â Â Â Â Â ÂRPRINTF("switch to unprotected mode before closing");
> Â Â Â Â UNREGISTER_EVENT(s->stream_fd.id);
> Â Â Â Â switch_mode(s->tdremus_driver, mode_unprotected);
> Â}
> @@ -1500,6 +1502,17 @@ static int tdremus_open(td_driver_t *driver, td_image_t *image, td_uuid_t uuid)
> Â Â Â Â return -EIO;
> Â}
>
> +static int tdremus_pre_close(td_driver_t *driver)
> +{
> +Â Â Â Âstruct tdremus_state *s = (struct tdremus_state *)driver->data;
> +
> +Â Â Â Âif (s->mode != mode_primary)
> +Â Â Â Â Â Â Â Âreturn 0;
> +
> +Â Â Â Âprimary_failed(s, ERROR_CLOSE);
> +Â Â Â Âreturn 0;
> +}
> +
> Âstatic int tdremus_close(td_driver_t *driver)
> Â{
> Â Â Â Â struct tdremus_state *s = (struct tdremus_state *)driver->data;
> @@ -1533,6 +1546,7 @@ struct tap_disk tapdisk_remus = {
>     .td_open      = tdremus_open,
>     .td_queue_read   = unprotected_queue_read,
>     .td_queue_write  Â= unprotected_queue_write,
> +   Â.td_pre_close   Â= tdremus_pre_close,
>     .td_close     Â= tdremus_close,
>     .td_get_parent_id Â= tdremus_get_parent_id,
> Â Â Â Â .td_validate_parent = tdremus_validate_parent,
> diff --git a/tools/blktap2/drivers/block-replication.h b/tools/blktap2/drivers/block-replication.h
> index 07fd630..358c08b 100644
> --- a/tools/blktap2/drivers/block-replication.h
> +++ b/tools/blktap2/drivers/block-replication.h
> @@ -49,6 +49,7 @@ enum {
> Â Â Â Â ERROR_INTERNAL = -1,
> Â Â Â Â ERROR_CONNECTION = -2,
> Â Â Â Â ERROR_IO = -3,
> +Â Â Â ÂERROR_CLOSE = -4,
> Â};
>
> Âtypedef struct td_replication_connect td_replication_connect_t;
> diff --git a/tools/blktap2/drivers/tapdisk-control.c b/tools/blktap2/drivers/tapdisk-control.c
> index 4e5f748..2fa4cbe 100644
> --- a/tools/blktap2/drivers/tapdisk-control.c
> +++ b/tools/blktap2/drivers/tapdisk-control.c
> @@ -508,6 +508,12 @@ tapdisk_control_close_image(struct tapdisk_control_connection *connection,
> Â Â Â Â Â Â Â Â goto out;
> Â Â Â Â }
>
> +Â Â Â Â/*
> +Â Â Â Â * Some I/O requests are pended in the driver, and
> +Â Â Â Â * flush these requests first.
> +Â Â Â Â */
> +Â Â Â Âtapdisk_vbd_pre_close_vdi(vbd);
> +
> Â Â Â Â if (!list_empty(&vbd->pending_requests)) {
> Â Â Â Â Â Â Â Â err = -EAGAIN;
> Â Â Â Â Â Â Â Â goto out;
> diff --git a/tools/blktap2/drivers/tapdisk-interface.c b/tools/blktap2/drivers/tapdisk-interface.c
> index a29de64..ed92e12 100644
> --- a/tools/blktap2/drivers/tapdisk-interface.c
> +++ b/tools/blktap2/drivers/tapdisk-interface.c
> @@ -105,6 +105,24 @@ td_open(td_image_t *image)
> Â}
>
> Âint
> +td_pre_close(td_image_t *image)
> +{
> +Â Â Â Âtd_driver_t *driver;
> +
> +Â Â Â Âdriver = image->driver;
> +Â Â Â Âif (!driver)
> +Â Â Â Â Â Â Â Âreturn -ENODEV;
> +
> +Â Â Â Âif (!driver->ops->td_pre_close)
> +Â Â Â Â Â Â Â Âreturn 0;
> +
> +Â Â Â Âif (driver->refcnt && td_flag_test(driver->state, TD_DRIVER_OPEN))
> +Â Â Â Â Â Â Â Âdriver->ops->td_pre_close(driver);
> +
> +Â Â Â Âreturn 0;
> +}
> +
> +int
> Âtd_close(td_image_t *image)
> Â{
> Â Â Â Â td_driver_t *driver;
> diff --git a/tools/blktap2/drivers/tapdisk-interface.h b/tools/blktap2/drivers/tapdisk-interface.h
> index adc4376..ba9b3ea 100644
> --- a/tools/blktap2/drivers/tapdisk-interface.h
> +++ b/tools/blktap2/drivers/tapdisk-interface.h
> @@ -34,6 +34,7 @@
> Âint td_open(td_image_t *);
> Âint __td_open(td_image_t *, td_disk_info_t *);
> Âint td_load(td_image_t *);
> +int td_pre_close(td_image_t *);
> Âint td_close(td_image_t *);
> Âint td_get_parent_id(td_image_t *, td_disk_id_t *);
> Âint td_validate_parent(td_image_t *, td_image_t *);
> diff --git a/tools/blktap2/drivers/tapdisk-vbd.c b/tools/blktap2/drivers/tapdisk-vbd.c
> index c665f27..aba545b 100644
> --- a/tools/blktap2/drivers/tapdisk-vbd.c
> +++ b/tools/blktap2/drivers/tapdisk-vbd.c
> @@ -180,6 +180,15 @@ tapdisk_vbd_validate_chain(td_vbd_t *vbd)
> Â}
>
> Âvoid
> +tapdisk_vbd_pre_close_vdi(td_vbd_t *vbd)
> +{
> +Â Â Â Âtd_image_t *image, *tmp;
> +
> +Â Â Â Âtapdisk_vbd_for_each_image(vbd, image, tmp)
> +Â Â Â Â Â Â Â Âtd_pre_close(image);
> +}
> +
> +void
> Âtapdisk_vbd_close_vdi(td_vbd_t *vbd)
> Â{
> Â Â Â Â td_image_t *image, *tmp;
> diff --git a/tools/blktap2/drivers/tapdisk-vbd.h b/tools/blktap2/drivers/tapdisk-vbd.h
> index be084b2..040f2b8 100644
> --- a/tools/blktap2/drivers/tapdisk-vbd.h
> +++ b/tools/blktap2/drivers/tapdisk-vbd.h
> @@ -181,6 +181,7 @@ void tapdisk_vbd_free_stack(td_vbd_t *);
> Âint tapdisk_vbd_open_stack(td_vbd_t *, uint16_t, td_flag_t);
> Âint tapdisk_vbd_open_vdi(td_vbd_t *, const char *,
> Â Â Â Â Â Â Â Â Â Â Â Â Âuint16_t, uint16_t, td_flag_t);
> +void tapdisk_vbd_pre_close_vdi(td_vbd_t *);
> Âvoid tapdisk_vbd_close_vdi(td_vbd_t *);
>
> Âint tapdisk_vbd_attach(td_vbd_t *, const char *, int);
> diff --git a/tools/blktap2/drivers/tapdisk.h b/tools/blktap2/drivers/tapdisk.h
> index 3c3b51d..16efd07 100644
> --- a/tools/blktap2/drivers/tapdisk.h
> +++ b/tools/blktap2/drivers/tapdisk.h
> @@ -158,6 +158,7 @@ struct tap_disk {
>     td_flag_t          flags;
>     int             private_data_size;
> Â Â Â Â int (*td_open)Â Â Â Â Â Â Â Â(td_driver_t *, td_image_t *, td_uuid_t);
> +Â Â Â Âint (*td_pre_close)Â Â Â Â Â (td_driver_t *);
> Â Â Â Â int (*td_close)Â Â Â Â Â Â Â (td_driver_t *);
> Â Â Â Â int (*td_get_parent_id)Â Â Â (td_driver_t *, td_disk_id_t *);
> Â Â Â Â int (*td_validate_parent)Â Â (td_driver_t *, td_driver_t *, td_flag_t);
> --
> 1.9.3
>

Acked-by: Shriram Rajagopalan <rshriram@xxxxxxxxx>

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.