From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60258) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aryEL-0003Ri-UP for qemu-devel@nongnu.org; Sun, 17 Apr 2016 21:44:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aryEK-0004Ki-TS for qemu-devel@nongnu.org; Sun, 17 Apr 2016 21:44:01 -0400 Date: Mon, 18 Apr 2016 09:43:52 +0800 From: Fam Zheng Message-ID: <20160418014352.GE18893@ad-mail.usersys.redhat.com> References: <1460690887-32751-1-git-send-email-famz@redhat.com> <1460690887-32751-5-git-send-email-famz@redhat.com> <57123CB3.9070803@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57123CB3.9070803@openvz.org> Subject: Re: [Qemu-devel] [PATCH for-2.7 v2 04/17] block: Introduce image file locking List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Denis V. Lunev" Cc: qemu-devel@nongnu.org, Kevin Wolf , Max Reitz , Jeff Cody , Markus Armbruster , Eric Blake , John Snow , qemu-block@nongnu.org, berrange@redhat.com, pbonzini@redhat.com On Sat, 04/16 16:22, Denis V. Lunev wrote: > On 04/15/2016 06:27 AM, Fam Zheng wrote: > >Block drivers can implement this new operation .bdrv_lockf to actually lock the > >image in the protocol specific way. > > > >Signed-off-by: Fam Zheng > >--- > > block.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > > include/block/block_int.h | 12 ++++++++++++ > > 2 files changed, 54 insertions(+) > > > >diff --git a/block.c b/block.c > >index 1c575e4..7971a25 100644 > >--- a/block.c > >+++ b/block.c > >@@ -846,6 +846,34 @@ out: > > g_free(gen_node_name); > > } > >+static int bdrv_lock_unlock_image_do(BlockDriverState *bs, bool lock_image) > >+{ > >+ int cmd = BDRV_LOCKF_UNLOCK; > >+ > >+ if (bs->image_locked == lock_image) { > >+ return 0; > >+ } else if (!bs->drv) { > >+ return -ENOMEDIUM; > >+ } else if (!bs->drv->bdrv_lockf) { > >+ return 0; > >+ } > >+ if (lock_image) { > >+ cmd = bs->open_flags & BDRV_O_RDWR ? BDRV_LOCKF_RWLOCK : > >+ BDRV_LOCKF_ROLOCK; > >+ } > >+ return bs->drv->bdrv_lockf(bs, cmd); > should we handle ENOTSUP specially? > f.e. this would fire with raw-posix.c on a filesystem which does not support > locking. > > from my POW this situations is equivalent to the absence of > bs->drv->bdrv_lockf Yes, that's right. Will fix. > > >+} > >+ > >+static int bdrv_lock_image(BlockDriverState *bs) > >+{ > >+ return bdrv_lock_unlock_image_do(bs, true); > >+} > >+ > >+static int bdrv_unlock_image(BlockDriverState *bs) > >+{ > >+ return bdrv_lock_unlock_image_do(bs, false); > >+} > >+ > > static QemuOptsList bdrv_runtime_opts = { > > .name = "bdrv_common", > > .head = QTAILQ_HEAD_INITIALIZER(bdrv_runtime_opts.head), > >@@ -995,6 +1023,14 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file, > > goto free_and_fail; > > } > >+ if (!(open_flags & (BDRV_O_NO_LOCK | BDRV_O_INACTIVE))) { > >+ ret = bdrv_lock_image(bs); > >+ if (ret) { > >+ error_setg(errp, "Failed to lock image"); > >+ goto free_and_fail; > >+ } > >+ } > >+ > > ret = refresh_total_sectors(bs, bs->total_sectors); > > if (ret < 0) { > > error_setg_errno(errp, -ret, "Could not refresh total sector count"); > >@@ -2144,6 +2180,7 @@ static void bdrv_close(BlockDriverState *bs) > > if (bs->drv) { > > BdrvChild *child, *next; > >+ bdrv_unlock_image(bs); > > bs->drv->bdrv_close(bs); > > bs->drv = NULL; > >@@ -3230,6 +3267,9 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) > > error_setg_errno(errp, -ret, "Could not refresh total sector count"); > > return; > > } > >+ if (!(bs->open_flags & BDRV_O_NO_LOCK)) { > >+ bdrv_lock_image(bs); > >+ } > > } > > void bdrv_invalidate_cache_all(Error **errp) > >@@ -3262,6 +3302,7 @@ static int bdrv_inactivate(BlockDriverState *bs) > > } > > bs->open_flags |= BDRV_O_INACTIVE; > >+ ret = bdrv_unlock_image(bs); > I'd better move unlock a line above. > Though this is personal. This could be useful > for debugging purposes. OK, I can move it. > > > > return 0; > > } > >@@ -3981,3 +4022,4 @@ void bdrv_refresh_filename(BlockDriverState *bs) > > QDECREF(json); > > } > > } > >+ > this hunk is extra Will remove. Thanks, Fam