From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ab6y3-0005nL-TR for qemu-devel@nongnu.org; Wed, 02 Mar 2016 08:37:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ab6y3-0005El-2j for qemu-devel@nongnu.org; Wed, 02 Mar 2016 08:37:31 -0500 Date: Wed, 2 Mar 2016 08:37:23 -0500 From: Jeff Cody Message-ID: <20160302133723.GB30203@localhost.localdomain> References: <1456918021-30086-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1456918021-30086-1-git-send-email-kwolf@redhat.com> Subject: Re: [Qemu-devel] [PATCH] blockdev: Snapshotting must not open second instance of old top List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: armbru@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org On Wed, Mar 02, 2016 at 12:27:01PM +0100, Kevin Wolf wrote: > Calling bdrv_img_create() with a size of -1 means that it determines the > size automatically by opening the backing file. However, in the case of > live snapshots, the backing file is already opened and we must avoid > opening the same image twice at the same time. Apart from that, just > getting the size from the already existing BDS is a lot less overhead > than opening a new instance. > > Signed-off-by: Kevin Wolf > --- > blockdev.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/blockdev.c b/blockdev.c > index 151b800..3abfd0d 100644 > --- a/blockdev.c > +++ b/blockdev.c > @@ -1739,10 +1739,15 @@ static void external_snapshot_prepare(BlkActionState *common, > /* create new image w/backing file */ > mode = s->has_mode ? s->mode : NEW_IMAGE_MODE_ABSOLUTE_PATHS; > if (mode != NEW_IMAGE_MODE_EXISTING) { > + int64_t size = bdrv_getlength(state->old_bs); > + if (size < 0) { > + error_setg_errno(errp, -size, "bdrv_getlength failed"); > + return; > + } > bdrv_img_create(new_image_file, format, > state->old_bs->filename, > state->old_bs->drv->format_name, > - NULL, -1, flags, &local_err, false); > + NULL, size, flags, &local_err, false); > if (local_err) { > error_propagate(errp, local_err); > return; > -- > 1.8.3.1 > Reviewed-by: Jeff Cody