* [Qemu-devel] [PATCH v2] sheepdog: add reopen support
@ 2015-08-27 2:54 Liu Yuan
2015-08-27 19:00 ` Jeff Cody
0 siblings, 1 reply; 3+ messages in thread
From: Liu Yuan @ 2015-08-27 2:54 UTC (permalink / raw)
To: sheepdog-ng; +Cc: Kevin Wolf, Jeff Cody, qemu-devel, Stefan Hajnoczi
From: Liu Yuan <liuyuan@cmss.chinamobile.com>
With reopen supported, block-commit (and offline commit) is now supported for
image files whose base image uses the Sheepdog protocol driver.
Cc: qemu-devel@nongnu.org
Cc: Jeff Cody <jcody@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Liu Yuan <liuyuan@cmss.chinamobile.com>
---
v2:
- free AioHandler [Jeff Cody]
block/sheepdog.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 9585beb..e54add4 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -377,6 +377,11 @@ typedef struct BDRVSheepdogState {
QLIST_HEAD(inflight_aiocb_head, SheepdogAIOCB) inflight_aiocb_head;
} BDRVSheepdogState;
+typedef struct BDRVSheepdogReopenState {
+ int fd;
+ int cache_flags;
+} BDRVSheepdogReopenState;
+
static const char * sd_strerror(int err)
{
int i;
@@ -1486,6 +1491,67 @@ out:
return ret;
}
+static int sd_reopen_prepare(BDRVReopenState *state, BlockReopenQueue *queue,
+ Error **errp)
+{
+ BDRVSheepdogState *s = state->bs->opaque;
+ BDRVSheepdogReopenState *re_s;
+ int ret = 0;
+
+ re_s = state->opaque = g_new0(BDRVSheepdogReopenState, 1);
+
+ if (state->flags & BDRV_O_NOCACHE) {
+ re_s->cache_flags = SD_FLAG_CMD_DIRECT;
+ }
+
+ re_s->fd = get_sheep_fd(s, errp);
+ if (re_s->fd < 0) {
+ ret = re_s->fd;
+ return ret;
+ }
+
+ return ret;
+}
+
+static void sd_reopen_commit(BDRVReopenState *state)
+{
+ BDRVSheepdogReopenState *re_s = state->opaque;
+ BDRVSheepdogState *s = state->bs->opaque;
+
+ if (s->fd) {
+ aio_set_fd_handler(s->aio_context, s->fd, NULL, NULL, NULL);
+ closesocket(s->fd);
+ }
+
+ s->fd = re_s->fd;
+ s->cache_flags = re_s->cache_flags;
+
+ g_free(state->opaque);
+ state->opaque = NULL;
+
+ return;
+}
+
+static void sd_reopen_abort(BDRVReopenState *state)
+{
+ BDRVSheepdogReopenState *re_s = state->opaque;
+ BDRVSheepdogState *s = state->bs->opaque;
+
+ if (re_s == NULL) {
+ return;
+ }
+
+ if (re_s->fd) {
+ aio_set_fd_handler(s->aio_context, re_s->fd, NULL, NULL, NULL);
+ closesocket(re_s->fd);
+ }
+
+ g_free(state->opaque);
+ state->opaque = NULL;
+
+ return;
+}
+
static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot,
Error **errp)
{
@@ -2703,6 +2769,9 @@ static BlockDriver bdrv_sheepdog = {
.instance_size = sizeof(BDRVSheepdogState),
.bdrv_needs_filename = true,
.bdrv_file_open = sd_open,
+ .bdrv_reopen_prepare = sd_reopen_prepare,
+ .bdrv_reopen_commit = sd_reopen_commit,
+ .bdrv_reopen_abort = sd_reopen_abort,
.bdrv_close = sd_close,
.bdrv_create = sd_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
@@ -2736,6 +2805,9 @@ static BlockDriver bdrv_sheepdog_tcp = {
.instance_size = sizeof(BDRVSheepdogState),
.bdrv_needs_filename = true,
.bdrv_file_open = sd_open,
+ .bdrv_reopen_prepare = sd_reopen_prepare,
+ .bdrv_reopen_commit = sd_reopen_commit,
+ .bdrv_reopen_abort = sd_reopen_abort,
.bdrv_close = sd_close,
.bdrv_create = sd_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
@@ -2769,6 +2841,9 @@ static BlockDriver bdrv_sheepdog_unix = {
.instance_size = sizeof(BDRVSheepdogState),
.bdrv_needs_filename = true,
.bdrv_file_open = sd_open,
+ .bdrv_reopen_prepare = sd_reopen_prepare,
+ .bdrv_reopen_commit = sd_reopen_commit,
+ .bdrv_reopen_abort = sd_reopen_abort,
.bdrv_close = sd_close,
.bdrv_create = sd_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] sheepdog: add reopen support
2015-08-27 2:54 [Qemu-devel] [PATCH v2] sheepdog: add reopen support Liu Yuan
@ 2015-08-27 19:00 ` Jeff Cody
2015-08-28 1:47 ` Liu Yuan
0 siblings, 1 reply; 3+ messages in thread
From: Jeff Cody @ 2015-08-27 19:00 UTC (permalink / raw)
To: Liu Yuan; +Cc: Kevin Wolf, sheepdog-ng, Stefan Hajnoczi, qemu-devel
On Thu, Aug 27, 2015 at 10:54:01AM +0800, Liu Yuan wrote:
> From: Liu Yuan <liuyuan@cmss.chinamobile.com>
>
> With reopen supported, block-commit (and offline commit) is now supported for
> image files whose base image uses the Sheepdog protocol driver.
>
> Cc: qemu-devel@nongnu.org
> Cc: Jeff Cody <jcody@redhat.com>
> Cc: Kevin Wolf <kwolf@redhat.com>
> Cc: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Liu Yuan <liuyuan@cmss.chinamobile.com>
> ---
> v2:
> - free AioHandler [Jeff Cody]
>
> block/sheepdog.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 75 insertions(+)
>
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index 9585beb..e54add4 100644
> --- a/block/sheepdog.c
> +++ b/block/sheepdog.c
> @@ -377,6 +377,11 @@ typedef struct BDRVSheepdogState {
> QLIST_HEAD(inflight_aiocb_head, SheepdogAIOCB) inflight_aiocb_head;
> } BDRVSheepdogState;
>
> +typedef struct BDRVSheepdogReopenState {
> + int fd;
> + int cache_flags;
> +} BDRVSheepdogReopenState;
> +
> static const char * sd_strerror(int err)
> {
> int i;
> @@ -1486,6 +1491,67 @@ out:
> return ret;
> }
>
> +static int sd_reopen_prepare(BDRVReopenState *state, BlockReopenQueue *queue,
> + Error **errp)
> +{
> + BDRVSheepdogState *s = state->bs->opaque;
> + BDRVSheepdogReopenState *re_s;
> + int ret = 0;
> +
> + re_s = state->opaque = g_new0(BDRVSheepdogReopenState, 1);
> +
> + if (state->flags & BDRV_O_NOCACHE) {
> + re_s->cache_flags = SD_FLAG_CMD_DIRECT;
> + }
In sd_open(), the s->cache_flag is set to SD_FLAG_CMD_CACHE by
default, and then overwritten if BDRV_O_NOCACHE is set. Do we want
that same behavior here?
(Sorry I didn't ask this the first time around)
> +
> + re_s->fd = get_sheep_fd(s, errp);
> + if (re_s->fd < 0) {
> + ret = re_s->fd;
> + return ret;
> + }
> +
> + return ret;
> +}
> +
> +static void sd_reopen_commit(BDRVReopenState *state)
> +{
> + BDRVSheepdogReopenState *re_s = state->opaque;
> + BDRVSheepdogState *s = state->bs->opaque;
> +
> + if (s->fd) {
> + aio_set_fd_handler(s->aio_context, s->fd, NULL, NULL, NULL);
> + closesocket(s->fd);
> + }
> +
> + s->fd = re_s->fd;
> + s->cache_flags = re_s->cache_flags;
> +
> + g_free(state->opaque);
> + state->opaque = NULL;
> +
> + return;
> +}
> +
> +static void sd_reopen_abort(BDRVReopenState *state)
> +{
> + BDRVSheepdogReopenState *re_s = state->opaque;
> + BDRVSheepdogState *s = state->bs->opaque;
> +
> + if (re_s == NULL) {
> + return;
> + }
> +
> + if (re_s->fd) {
> + aio_set_fd_handler(s->aio_context, re_s->fd, NULL, NULL, NULL);
> + closesocket(re_s->fd);
> + }
> +
> + g_free(state->opaque);
> + state->opaque = NULL;
> +
> + return;
> +}
> +
> static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot,
> Error **errp)
> {
> @@ -2703,6 +2769,9 @@ static BlockDriver bdrv_sheepdog = {
> .instance_size = sizeof(BDRVSheepdogState),
> .bdrv_needs_filename = true,
> .bdrv_file_open = sd_open,
> + .bdrv_reopen_prepare = sd_reopen_prepare,
> + .bdrv_reopen_commit = sd_reopen_commit,
> + .bdrv_reopen_abort = sd_reopen_abort,
> .bdrv_close = sd_close,
> .bdrv_create = sd_create,
> .bdrv_has_zero_init = bdrv_has_zero_init_1,
> @@ -2736,6 +2805,9 @@ static BlockDriver bdrv_sheepdog_tcp = {
> .instance_size = sizeof(BDRVSheepdogState),
> .bdrv_needs_filename = true,
> .bdrv_file_open = sd_open,
> + .bdrv_reopen_prepare = sd_reopen_prepare,
> + .bdrv_reopen_commit = sd_reopen_commit,
> + .bdrv_reopen_abort = sd_reopen_abort,
> .bdrv_close = sd_close,
> .bdrv_create = sd_create,
> .bdrv_has_zero_init = bdrv_has_zero_init_1,
> @@ -2769,6 +2841,9 @@ static BlockDriver bdrv_sheepdog_unix = {
> .instance_size = sizeof(BDRVSheepdogState),
> .bdrv_needs_filename = true,
> .bdrv_file_open = sd_open,
> + .bdrv_reopen_prepare = sd_reopen_prepare,
> + .bdrv_reopen_commit = sd_reopen_commit,
> + .bdrv_reopen_abort = sd_reopen_abort,
> .bdrv_close = sd_close,
> .bdrv_create = sd_create,
> .bdrv_has_zero_init = bdrv_has_zero_init_1,
> --
> 1.9.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] sheepdog: add reopen support
2015-08-27 19:00 ` Jeff Cody
@ 2015-08-28 1:47 ` Liu Yuan
0 siblings, 0 replies; 3+ messages in thread
From: Liu Yuan @ 2015-08-28 1:47 UTC (permalink / raw)
To: Jeff Cody; +Cc: Kevin Wolf, sheepdog-ng, Stefan Hajnoczi, qemu-devel
On Thu, Aug 27, 2015 at 03:00:32PM -0400, Jeff Cody wrote:
> On Thu, Aug 27, 2015 at 10:54:01AM +0800, Liu Yuan wrote:
> > From: Liu Yuan <liuyuan@cmss.chinamobile.com>
> >
> > With reopen supported, block-commit (and offline commit) is now supported for
> > image files whose base image uses the Sheepdog protocol driver.
> >
> > Cc: qemu-devel@nongnu.org
> > Cc: Jeff Cody <jcody@redhat.com>
> > Cc: Kevin Wolf <kwolf@redhat.com>
> > Cc: Stefan Hajnoczi <stefanha@redhat.com>
> > Signed-off-by: Liu Yuan <liuyuan@cmss.chinamobile.com>
> > ---
> > v2:
> > - free AioHandler [Jeff Cody]
> >
> > block/sheepdog.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 75 insertions(+)
> >
> > diff --git a/block/sheepdog.c b/block/sheepdog.c
> > index 9585beb..e54add4 100644
> > --- a/block/sheepdog.c
> > +++ b/block/sheepdog.c
> > @@ -377,6 +377,11 @@ typedef struct BDRVSheepdogState {
> > QLIST_HEAD(inflight_aiocb_head, SheepdogAIOCB) inflight_aiocb_head;
> > } BDRVSheepdogState;
> >
> > +typedef struct BDRVSheepdogReopenState {
> > + int fd;
> > + int cache_flags;
> > +} BDRVSheepdogReopenState;
> > +
> > static const char * sd_strerror(int err)
> > {
> > int i;
> > @@ -1486,6 +1491,67 @@ out:
> > return ret;
> > }
> >
> > +static int sd_reopen_prepare(BDRVReopenState *state, BlockReopenQueue *queue,
> > + Error **errp)
> > +{
> > + BDRVSheepdogState *s = state->bs->opaque;
> > + BDRVSheepdogReopenState *re_s;
> > + int ret = 0;
> > +
> > + re_s = state->opaque = g_new0(BDRVSheepdogReopenState, 1);
> > +
> > + if (state->flags & BDRV_O_NOCACHE) {
> > + re_s->cache_flags = SD_FLAG_CMD_DIRECT;
> > + }
>
> In sd_open(), the s->cache_flag is set to SD_FLAG_CMD_CACHE by
> default, and then overwritten if BDRV_O_NOCACHE is set. Do we want
> that same behavior here?
>
> (Sorry I didn't ask this the first time around)
As far as I understood, sd_open() was called before sd_reopen, so I thought
s->cache_flags = SD_FLAG_CMD_CACHE was duplicated in sd_reopen. But for a second
thought, if the reopen indicates a complete flags reparsing, I'd agree with you.
I'll prepare the third version of the patch.
Thanks,
Yuan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-28 1:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-27 2:54 [Qemu-devel] [PATCH v2] sheepdog: add reopen support Liu Yuan
2015-08-27 19:00 ` Jeff Cody
2015-08-28 1:47 ` Liu Yuan
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).