From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUaVd-0006nJ-2h for qemu-devel@nongnu.org; Wed, 26 Aug 2015 09:13:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUaVY-00060q-WB for qemu-devel@nongnu.org; Wed, 26 Aug 2015 09:12:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUaVY-00060R-OM for qemu-devel@nongnu.org; Wed, 26 Aug 2015 09:12:52 -0400 Date: Wed, 26 Aug 2015 09:12:49 -0400 From: Jeff Cody Message-ID: <20150826131249.GD11016@localhost.localdomain> References: <1440581349-579-1-git-send-email-namei.unix@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1440581349-579-1-git-send-email-namei.unix@gmail.com> Subject: Re: [Qemu-devel] [PATCH] sheepdog: add reopen support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liu Yuan Cc: Kevin Wolf , sheepdog-ng@googlegroups.com, Stefan Hajnoczi , qemu-devel@nongnu.org On Wed, Aug 26, 2015 at 05:29:09PM +0800, Liu Yuan wrote: > From: Liu Yuan > > 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 > Cc: Kevin Wolf > Cc: Stefan Hajnoczi > Signed-off-by: Liu Yuan > --- > block/sheepdog.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 72 insertions(+) > > diff --git a/block/sheepdog.c b/block/sheepdog.c > index 9585beb..26d09e9 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,64 @@ 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) { > + closesocket(s->fd); > + } > + > + s->fd = re_s->fd; This leaks the AioHandler associated with 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; > + > + if (re_s == NULL) { > + return; > + } > + > + if (re_s->fd) { > + closesocket(re_s->fd); This leaks the AioHandler associated with 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 +2766,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 +2802,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 +2838,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 >