From patchwork Wed Mar 2 11:27:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8480231 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1E6349F314 for ; Wed, 2 Mar 2016 11:27:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 846A3202B8 for ; Wed, 2 Mar 2016 11:27:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D4734201F4 for ; Wed, 2 Mar 2016 11:27:23 +0000 (UTC) Received: from localhost ([::1]:55720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ab4w5-0005oq-2c for patchwork-qemu-devel@patchwork.kernel.org; Wed, 02 Mar 2016 06:27:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ab4vx-0005np-Lr for qemu-devel@nongnu.org; Wed, 02 Mar 2016 06:27:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ab4vw-0000nL-Mx for qemu-devel@nongnu.org; Wed, 02 Mar 2016 06:27:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57490) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ab4vr-0000mh-7R; Wed, 02 Mar 2016 06:27:07 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 31F4778224; Wed, 2 Mar 2016 11:27:06 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-57.ams2.redhat.com [10.36.116.57]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u22BR3Ip030743; Wed, 2 Mar 2016 06:27:04 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 2 Mar 2016 12:27:01 +0100 Message-Id: <1456918021-30086-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, jcody@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] blockdev: Snapshotting must not open second instance of old top X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Jeff Cody --- 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;