From patchwork Wed Mar 8 21:34:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9612013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DC7AE6016C for ; Wed, 8 Mar 2017 21:37:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC4882862A for ; Wed, 8 Mar 2017 21:37:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCAD128635; Wed, 8 Mar 2017 21:37:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 671462862A for ; Wed, 8 Mar 2017 21:37:56 +0000 (UTC) Received: from localhost ([::1]:58578 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cljHP-0007Ai-Ba for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Mar 2017 16:37:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cljEG-0004c9-Tu for qemu-devel@nongnu.org; Wed, 08 Mar 2017 16:34:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cljEF-0000D7-8Q for qemu-devel@nongnu.org; Wed, 08 Mar 2017 16:34:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34646) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cljEB-0000BZ-C5; Wed, 08 Mar 2017 16:34:35 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8206E3A769C; Wed, 8 Mar 2017 21:34:35 +0000 (UTC) Received: from red.redhat.com (ovpn-124-84.rdu2.redhat.com [10.10.124.84] (may be forged)) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v28LYVl7026773; Wed, 8 Mar 2017 16:34:34 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 8 Mar 2017 15:34:28 -0600 Message-Id: <20170308213429.29244-3-eblake@redhat.com> In-Reply-To: <20170308213429.29244-1-eblake@redhat.com> References: <20170308213429.29244-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 08 Mar 2017 21:34:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/3] vvfat: React to bdrv_is_allocated() errors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP If bdrv_is_allocated() fails, we should react to that failure. For 2 of the 3 callers, reporting the error was easy. But in cluster_was_modified() and its lone caller get_cluster_count_for_direntry(), it's rather invasive to update the logic to pass the error back; so there, I went with merely documenting the issue by changing the return type to bool (in all likelihood, treating the cluster as modified will then trigger a read which will also fail, and eventually get to an error - but given the appalling number of abort() calls in this code, I'm not making it any worse). Signed-off-by: Eric Blake --- block/vvfat.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index aa61c32..af5153d 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1394,7 +1394,13 @@ static int vvfat_read(BlockDriverState *bs, int64_t sector_num, return -1; if (s->qcow) { int n; - if (bdrv_is_allocated(s->qcow->bs, sector_num, nb_sectors-i, &n)) { + int ret; + ret = bdrv_is_allocated(s->qcow->bs, sector_num, + nb_sectors - i, &n); + if (ret < 0) { + return ret; + } + if (ret) { DLOG(fprintf(stderr, "sectors %d+%d allocated\n", (int)sector_num, n)); if (bdrv_read(s->qcow, sector_num, buf + i * 0x200, n)) { @@ -1668,7 +1674,8 @@ static inline uint32_t modified_fat_get(BDRVVVFATState* s, } } -static inline int cluster_was_modified(BDRVVVFATState* s, uint32_t cluster_num) +static inline bool cluster_was_modified(BDRVVVFATState *s, + uint32_t cluster_num) { int was_modified = 0; int i, dummy; @@ -1683,7 +1690,13 @@ static inline int cluster_was_modified(BDRVVVFATState* s, uint32_t cluster_num) 1, &dummy); } - return was_modified; + /* + * Note that this treats failures to learn allocation status the + * same as if an allocation has occurred. It's as safe as + * anything else, given that a failure to learn allocation status + * will probably result in more failures. + */ + return !!was_modified; } static const char* get_basename(const char* path) @@ -1833,6 +1846,9 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s, int res; res = bdrv_is_allocated(s->qcow->bs, offset + i, 1, &dummy); + if (res < 0) { + return -1; + } if (!res) { res = vvfat_read(s->bs, offset, s->cluster_buffer, 1); if (res) {