From patchwork Wed Sep 9 18:59:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 305770 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E63BC43461 for ; Wed, 9 Sep 2020 19:02:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 995AA20C09 for ; Wed, 9 Sep 2020 19:02:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="LtVr7vhs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 995AA20C09 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kG5MU-0002gX-Ly for qemu-devel@archiver.kernel.org; Wed, 09 Sep 2020 15:02:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kG5KO-0007Yo-0G; Wed, 09 Sep 2020 15:00:20 -0400 Received: from mail-eopbgr00097.outbound.protection.outlook.com ([40.107.0.97]:61422 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kG5KL-0001PE-PE; Wed, 09 Sep 2020 15:00:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZZm/VUc2KPxvoCBKdr9ACzI1DUYNnXfQjFH8ywRXmM7Re2xeMiSSTah+tFHrEBCxfCUzdK4LGRpWGWDEYlTBS38Va/1xv8mCma7eE0bsMlUjZjjhVE4rsYLTgyfDP/ZOuonFUyT/eiHgSPA4zKpeqtwnzWTIY2yLsJOHUNAJ3nedGUQBJrSEluuZo25k7vkS8Y+slGArEY7U1HUnUWWp8cZV4mUfgjx+uj9IFJ5nRx1Yfq7BOkhfAllOuvpbtJiNkNlflstybSaONyUOE6mglvPMcECitfqZvItT/GxgSXKyEshbtU4H8Io44w14n/4yj9hJoBpOqX1wLR9U/Lv2xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bW2/WkivF3vOmxkzI1RyH7oao8JzwpLgWj6EDb7QXD0=; b=geN1O/wtBXJ3KyqQ17JCnVpdy4SSlqtvhXJZJjeL/Ok9xlLbM4Azl/0j4nLWLX9AO63NrKuP07bxZ3PO2h+XmS3IsTL0oDmnePCC3dn90YQeG+CqijF5ptZSQIRuNt4G3LxnbswZDdmfCNWIHK1NR4jfrsTE/YEG1Jo1N8kxlI/XfatmAazW7YVITl21V4EKRrtA8kJB0WpCRJ+o0DKyjH0VFk7zJD5+gPi0cCvIiwZEzcyuH4UXmftz3YLxquAW0nR88vmSmqvIMcMBXXtgGE2eH+/MoTkibl7PY5wMY86t4ZNunDKk4StTgW3h/ugWr51IAn3CvwferuRn4wH0bQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bW2/WkivF3vOmxkzI1RyH7oao8JzwpLgWj6EDb7QXD0=; b=LtVr7vhsP/AySx6m8PU5TJsE3iXMA/W2QJmUmzI566+yxWz3UW0dJbVsI+MoTrj6oJZT37ihFGjr9jtxcJALKpv5KQzXrfvhnKP0mhtr6ZvYYNlADm6ddPQmAXhVbW2PytmBT9B+/1Hoz245joBuY9G05Df63BD6XqbKuo1GR0I= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4070.eurprd08.prod.outlook.com (2603:10a6:20b:a3::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Wed, 9 Sep 2020 19:00:06 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692%7]) with mapi id 15.20.3348.019; Wed, 9 Sep 2020 19:00:06 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com, eblake@redhat.com, jsnow@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, pavel.dovgaluk@ispras.ru, ari@tuxera.com, mreitz@redhat.com, kwolf@redhat.com, groug@kaod.org Subject: [PATCH 14/14] block/qed: bdrv_qed_do_open: deal with errp Date: Wed, 9 Sep 2020 21:59:30 +0300 Message-Id: <20200909185930.26524-15-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200909185930.26524-1-vsementsov@virtuozzo.com> References: <20200909185930.26524-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM3PR07CA0054.eurprd07.prod.outlook.com (2603:10a6:207:4::12) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.136) by AM3PR07CA0054.eurprd07.prod.outlook.com (2603:10a6:207:4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.5 via Frontend Transport; Wed, 9 Sep 2020 19:00:05 +0000 X-Mailer: git-send-email 2.21.3 X-Originating-IP: [185.215.60.136] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 15dd97a0-b510-44d7-113c-08d854f290aa X-MS-TrafficTypeDiagnostic: AM6PR08MB4070: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HkCqIiP77lRgw1y7g4HshAtXNdvWbnfxYBrN0N/RWaq56QtsdUQSc+FYUQkdCvcibfeGTYswg8EIbfDmixXAaXYlunCbrXw6ozqQzuFY95mwvkVA9u5B8WKvU4qI86v4z3SNFUCVQa/HtnaZi14/eKxr381HEb4MjyYvK84dhjLdFEOiv85JX0RGpX4jwgcmP3gaaxqqQCqdAkKHsQiNlQ2DqunN1O8K9mE4daRHx2fgco/7RJVvAZKg2NXywtVl5smgTZT1Au0eNwqvBxEbzuciH+T4X9p6gIXKMBSF4KK7RNfFTn1NpmQe41K4UUPjlP2kwbBOoYxodVzGLW5RUA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39840400004)(396003)(136003)(376002)(346002)(26005)(316002)(8936002)(8676002)(16526019)(186003)(478600001)(5660300002)(6506007)(7416002)(6512007)(83380400001)(6666004)(4326008)(36756003)(52116002)(2906002)(6486002)(66556008)(66476007)(956004)(6916009)(2616005)(86362001)(1076003)(66946007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: ZaSLHbt3H+pJlffezedGq4wyoWxVOVdvcKzCUqIbv4yXTZwZplRobqnjlh13rUMmFFu92REScXguhfZAnyKi8qtS6+47dBI9IAFkxlVL9ldn8u8E5MUorgfMZTIPL4wS2cYhjpgsugtrUYjyizkRugGYuuHbDb5Y7KOHGHDmUcM4F1OuFxccR97GM7dH4StmjkeCqIOyZdQ4WuHKrh5RpGCzxpZPBCDItvltuq85wyN9k4QsGLo7KxRiNB9gMkPhC1YsXIIVgsu4dPkT4IzNRUr+z19BvmqWHh3s0ttsyrU9vFq9iaQ7x/fd6z+eqC6umWpd0zFVkHFRzc/U5TimLIyszwTLHeIcgVjjPKvIKb4p/l6DP5z8p0BkZE1TzCjYmGkXCrBuuQVe8A58sQlQxU7m7343Sqb0aRQF6C55xAViCalbkZWRJEYXEktOkKg6BfHpoHqMXYfPUm2Df/s+bztjJyDrL8mE1VGH3/Geyph43aNO3n1w/9gWUl7CSfxNohgSoeJCSrXmJ7pyb6LiTAZP96obt1MAPgfMwlPIbXCK0Wm4rdG9Wq+s/uO4s4IT6elRko0ILXxVD9dACsrNBfHQHz/yB7CxqvAsUYkFA5IcQSPS58n95RDg6764lhe5FQsiKAlepqObEYAVsxujEA== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15dd97a0-b510-44d7-113c-08d854f290aa X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2020 19:00:06.0421 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Yd1sBXB05WMcDiJk/Vp6B/gWiBx8EYcPwacmXHHPEepuS+57qUGVNkbYweoVYyM0EB8nv5gAuBBNJIqWbyJDwgfYshBXiTyH+EQM3/fiNWQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4070 Received-SPF: pass client-ip=40.107.0.97; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/09 15:00:04 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Set errp always on failure. Generic bdrv_open_driver supports driver functions which can return negative value and forget to set errp. That's a strange thing.. Let's improve bdrv_qed_do_open to not behave this way. This allows to simplify code in bdrv_qed_co_invalidate_cache(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- block/qed.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/block/qed.c b/block/qed.c index b27e7546ca..f45c640513 100644 --- a/block/qed.c +++ b/block/qed.c @@ -393,6 +393,7 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options, ret = bdrv_pread(bs->file, 0, &le_header, sizeof(le_header)); if (ret < 0) { + error_setg(errp, "Failed to read QED header"); return ret; } qed_header_le_to_cpu(&le_header, &s->header); @@ -408,25 +409,30 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options, return -ENOTSUP; } if (!qed_is_cluster_size_valid(s->header.cluster_size)) { + error_setg(errp, "QED cluster size is invalid"); return -EINVAL; } /* Round down file size to the last cluster */ file_size = bdrv_getlength(bs->file->bs); if (file_size < 0) { + error_setg(errp, "Failed to get file length"); return file_size; } s->file_size = qed_start_of_cluster(s, file_size); if (!qed_is_table_size_valid(s->header.table_size)) { + error_setg(errp, "QED table size is invalid"); return -EINVAL; } if (!qed_is_image_size_valid(s->header.image_size, s->header.cluster_size, s->header.table_size)) { + error_setg(errp, "QED image size is invalid"); return -EINVAL; } if (!qed_check_table_offset(s, s->header.l1_table_offset)) { + error_setg(errp, "QED table offset is invalid"); return -EINVAL; } @@ -438,6 +444,7 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options, /* Header size calculation must not overflow uint32_t */ if (s->header.header_size > UINT32_MAX / s->header.cluster_size) { + error_setg(errp, "QED header size is too large"); return -EINVAL; } @@ -445,6 +452,7 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options, if ((uint64_t)s->header.backing_filename_offset + s->header.backing_filename_size > s->header.cluster_size * s->header.header_size) { + error_setg(errp, "QED backing filename offset is invalid"); return -EINVAL; } @@ -453,6 +461,7 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options, bs->auto_backing_file, sizeof(bs->auto_backing_file)); if (ret < 0) { + error_setg(errp, "Failed to read backing filename"); return ret; } pstrcpy(bs->backing_file, sizeof(bs->backing_file), @@ -475,6 +484,7 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options, ret = qed_write_header_sync(s); if (ret) { + error_setg(errp, "Failed to update header"); return ret; } @@ -487,6 +497,7 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options, ret = qed_read_l1_table_sync(s); if (ret) { + error_setg(errp, "Failed to read L1 table"); goto out; } @@ -503,6 +514,7 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options, ret = qed_check(s, &result, true); if (ret) { + error_setg(errp, "Image corrupted"); goto out; } } @@ -1537,22 +1549,16 @@ static void coroutine_fn bdrv_qed_co_invalidate_cache(BlockDriverState *bs, Error **errp) { BDRVQEDState *s = bs->opaque; - Error *local_err = NULL; int ret; bdrv_qed_close(bs); bdrv_qed_init_state(bs); qemu_co_mutex_lock(&s->table_lock); - ret = bdrv_qed_do_open(bs, NULL, bs->open_flags, &local_err); + ret = bdrv_qed_do_open(bs, NULL, bs->open_flags, errp); qemu_co_mutex_unlock(&s->table_lock); - if (local_err) { - error_propagate_prepend(errp, local_err, - "Could not reopen qed layer: "); - return; - } else if (ret < 0) { - error_setg_errno(errp, -ret, "Could not reopen qed layer"); - return; + if (ret < 0) { + error_prepend(errp, "Could not reopen qed layer: "); } }