From patchwork Thu Jul 25 14:23:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 261717 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8A84D2C00C2 for ; Fri, 26 Jul 2013 00:27:54 +1000 (EST) Received: from localhost ([::1]:50050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2MWG-00007t-KT for incoming@patchwork.ozlabs.org; Thu, 25 Jul 2013 10:27:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2MSi-0003GF-3e for qemu-devel@nongnu.org; Thu, 25 Jul 2013 10:24:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2MSd-0007tO-TE for qemu-devel@nongnu.org; Thu, 25 Jul 2013 10:24:12 -0400 Received: from mail-yh0-x230.google.com ([2607:f8b0:4002:c01::230]:59854) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2MSd-0007tK-PB; Thu, 25 Jul 2013 10:24:07 -0400 Received: by mail-yh0-f48.google.com with SMTP id b20so573235yha.35 for ; Thu, 25 Jul 2013 07:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=XieeQyY59H51cYX/cOwA5us+rYfsJrib5wJoTsCpZ2w=; b=RjNdcslasyqYDvQW7PRQbppUncK/tpOkv2JSzIdnM8ylyNdGnZKu/nZbeFMECp2RDw AK1AW0LRzQCEwPbz9PRbwbcTau6CMOGewdGK8gnO0cUcWRXpa0VQq/ubQUsIQTI9mBUe Zxgipir6dQ4YVnLxP9bmxyGB0kBh91n6TKwIBZbxNDf6Lb8OQwIaeCzuHq4AAKEkVKE6 9Mh6t0mCGdsLoOKSm3zqcD3VsJaUh77BV/CnbDrCxzjV78QaKlkHoDPhnc+m8ll2+Uf/ 5e6TtCtXinZUIgw7+evtONzbmVe4vqhvefoCRj7b1Ynx+onSOplFBTlnajRnoEEt/lYl Zh7A== X-Received: by 10.236.102.201 with SMTP id d49mr19320673yhg.242.1374762247427; Thu, 25 Jul 2013 07:24:07 -0700 (PDT) Received: from yakj.usersys.redhat.com (net-2-39-8-162.cust.dsl.vodafone.it. [2.39.8.162]) by mx.google.com with ESMTPSA id b48sm58469338yhc.8.2013.07.25.07.24.04 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 25 Jul 2013 07:24:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 25 Jul 2013 16:23:05 +0200 Message-Id: <1374762197-7261-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1374762197-7261-1-git-send-email-pbonzini@redhat.com> References: <1374762197-7261-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4002:c01::230 Cc: kwolf@redhat.com, pl@kamp.de, qemu-stable@nongnu.org, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v3 07/19] block: expect errors from bdrv_co_is_allocated 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Some bdrv_is_allocated callers do not expect errors, but the fallback in qcow2.c might make other callers trip on assertion failures or infinite loops. Fix the callers to always look for errors. Cc: qemu-stable@nongnu.org Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- block/qcow2.c | 4 +--- block/stream.c | 2 +- qemu-img.c | 5 +++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 0eceefe..e2b4202 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -648,13 +648,11 @@ static int coroutine_fn qcow2_co_is_allocated(BlockDriverState *bs, int ret; *pnum = nb_sectors; - /* FIXME We can get errors here, but the bdrv_co_is_allocated interface - * can't pass them on today */ qemu_co_mutex_lock(&s->lock); ret = qcow2_get_cluster_offset(bs, sector_num << 9, pnum, &cluster_offset); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { - *pnum = 0; + return ret; } return (cluster_offset != 0) || (ret == QCOW2_CLUSTER_ZERO); diff --git a/block/stream.c b/block/stream.c index 60136fb..1579cd3 100644 --- a/block/stream.c +++ b/block/stream.c @@ -120,7 +120,7 @@ wait: if (ret == 1) { /* Allocated in the top, no need to copy. */ copy = false; - } else { + } else if (ret >= 0) { /* Copy if allocated in the intermediate images. Limit to the * known-unallocated area [sector_num, sector_num+n). */ ret = bdrv_is_allocated_above(bs->backing_hd, base, diff --git a/qemu-img.c b/qemu-img.c index c55ca5c..a4957eb 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2073,6 +2073,11 @@ static int img_rebase(int argc, char **argv) /* If the cluster is allocated, we don't need to take action */ ret = bdrv_is_allocated(bs, sector, n, &n); + if (ret < 0) { + error_report("error while reading image metadata: %s", + strerror(-ret)); + goto out; + } if (ret) { continue; }