From nobody Sun Feb 8 22:07:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1570815123; cv=none; d=zoho.com; s=zohoarc; b=khp92QXuhURDmqDpFk5dx1jkIGaSCLGkXnWCDbkDJ6oaJvCbALg3Mmrbne+LBF9+tvQUzs9TawZDqzfE2dr8E7no81gnNlRPDbSAvWMFT69q9COs8LxSljqGl03PuEVrE82kLE8QJDOBlFyakSx/yGqywvDEoLfXI3vwtkfeJw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570815123; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VKbZgotb9ciiMEsyyfT+ZNB73AEL70Fj1vfthPTEMNM=; b=KpaCXT2Ct7lcagQ2RvCUIwN7hT2V7sBIzvk0XfUxHqTeDOp0JdFm3gf7aQiM3CMOGgRQVfBASfjs0ztg4Tmilxvh7hFshpNpVcbeH8IoY4KiFYRCBahCtaL8DEYJx31W+pfxorNIZTYYu78OBjOkXWUGbUEz/+tw5YbTbnkJ974= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157081512344953.56180268773346; Fri, 11 Oct 2019 10:32:03 -0700 (PDT) Received: from localhost ([::1]:54694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIyli-0002Ly-8y for importer@patchew.org; Fri, 11 Oct 2019 13:31:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41483) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIxln-0007G5-Vz for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:28:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIxll-0002cq-RZ for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:27:59 -0400 Received: from relay.sw.ru ([185.231.240.75]:49832) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iIxlj-0002cf-VN; Fri, 11 Oct 2019 12:27:56 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iIxR7-0003XG-49; Fri, 11 Oct 2019 19:06:37 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [RFC v5 112/126] qcow2: introduce ERRP_AUTO_PROPAGATE Date: Fri, 11 Oct 2019 19:05:38 +0300 Message-Id: <20191011160552.22907-113-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191011160552.22907-1-vsementsov@virtuozzo.com> References: <20191011160552.22907-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, qemu-block@nongnu.org, armbru@redhat.com, Max Reitz , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp =3D=3D &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases. If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are: 1. No need of explicit error_propagate call 2. No need of explicit local_err variable: use errp directly 3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit (together with its neighbors) was generated by for f in $(git grep -l errp \*.[ch]); do \ spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \ done; then fix a bit of compilation problems: coccinelle for some reason leaves several f() { ... goto out; ... out: } patterns, with "out:" at function end. then ./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)" (auto-msg was a file with this commit message) Still, for backporting it may be more comfortable to use only the first command and then do one huge commit. Reported-by: Kevin Wolf Reported-by: Greg Kurz Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-bitmap.c | 9 ++-- block/qcow2.c | 98 +++++++++++++++++++------------------------- 2 files changed, 48 insertions(+), 59 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index b2487101ed..b060911faa 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1447,6 +1447,7 @@ fail: =20 void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **er= rp) { + ERRP_AUTO_PROPAGATE(); BdrvDirtyBitmap *bitmap; BDRVQcow2State *s =3D bs->opaque; uint32_t new_nb_bitmaps =3D s->nb_bitmaps; @@ -1593,12 +1594,11 @@ fail: =20 int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp) { + ERRP_AUTO_PROPAGATE(); BdrvDirtyBitmap *bitmap; - Error *local_err =3D NULL; =20 - qcow2_store_persistent_dirty_bitmaps(bs, &local_err); - if (local_err !=3D NULL) { - error_propagate(errp, local_err); + qcow2_store_persistent_dirty_bitmaps(bs, errp); + if (*errp) { return -EINVAL; } =20 @@ -1618,6 +1618,7 @@ bool qcow2_can_store_new_dirty_bitmap(BlockDriverStat= e *bs, uint32_t granularity, Error **errp) { + ERRP_AUTO_PROPAGATE(); BDRVQcow2State *s =3D bs->opaque; bool found; Qcow2BitmapList *bm_list; diff --git a/block/qcow2.c b/block/qcow2.c index 4d16393e61..7555e526af 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -923,6 +923,7 @@ static int qcow2_update_options_prepare(BlockDriverStat= e *bs, QDict *options, int flags, Error **errp) { + ERRP_AUTO_PROPAGATE(); BDRVQcow2State *s =3D bs->opaque; QemuOpts *opts =3D NULL; const char *opt_overlap_check, *opt_overlap_check_template; @@ -931,25 +932,22 @@ static int qcow2_update_options_prepare(BlockDriverSt= ate *bs, int i; const char *encryptfmt; QDict *encryptopts =3D NULL; - Error *local_err =3D NULL; int ret; =20 qdict_extract_subqdict(options, &encryptopts, "encrypt."); encryptfmt =3D qdict_get_try_str(encryptopts, "format"); =20 opts =3D qemu_opts_create(&qcow2_runtime_opts, NULL, 0, &error_abort); - qemu_opts_absorb_qdict(opts, options, &local_err); - if (local_err) { - error_propagate(errp, local_err); + qemu_opts_absorb_qdict(opts, options, errp); + if (*errp) { ret =3D -EINVAL; goto fail; } =20 /* get L2 table/refcount block cache size from command line options */ read_cache_sizes(bs, opts, &l2_cache_size, &l2_cache_entry_size, - &refcount_cache_size, &local_err); - if (local_err) { - error_propagate(errp, local_err); + &refcount_cache_size, errp); + if (*errp) { ret =3D -EINVAL; goto fail; } @@ -1207,11 +1205,11 @@ static int qcow2_update_options(BlockDriverState *b= s, QDict *options, static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { + ERRP_AUTO_PROPAGATE(); BDRVQcow2State *s =3D bs->opaque; unsigned int len, i; int ret =3D 0; QCowHeader header; - Error *local_err =3D NULL; uint64_t ext_end; uint64_t l1_vm_state_index; bool update_header =3D false; @@ -1486,17 +1484,15 @@ static int coroutine_fn qcow2_do_open(BlockDriverSt= ate *bs, QDict *options, =20 /* read qcow2 extensions */ if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL, - flags, &update_header, &local_err)) { - error_propagate(errp, local_err); + flags, &update_header, errp)) { ret =3D -EINVAL; goto fail; } =20 /* Open external data file */ s->data_file =3D bdrv_open_child(NULL, options, "data-file", bs, &chil= d_file, - true, &local_err); - if (local_err) { - error_propagate(errp, local_err); + true, errp); + if (*errp) { ret =3D -EINVAL; goto fail; } @@ -1657,12 +1653,11 @@ static int coroutine_fn qcow2_do_open(BlockDriverSt= ate *bs, QDict *options, =20 if (!(bdrv_get_flags(bs) & BDRV_O_INACTIVE)) { /* It's case 1, 2 or 3.2. Or 3.1 which is BUG in management layer.= */ - bool header_updated =3D qcow2_load_dirty_bitmaps(bs, &local_err); + bool header_updated =3D qcow2_load_dirty_bitmaps(bs, errp); =20 update_header =3D update_header && !header_updated; } - if (local_err !=3D NULL) { - error_propagate(errp, local_err); + if (*errp) { ret =3D -EINVAL; goto fail; } @@ -2424,11 +2419,11 @@ static void qcow2_close(BlockDriverState *bs) static void coroutine_fn qcow2_co_invalidate_cache(BlockDriverState *bs, Error **errp) { + ERRP_AUTO_PROPAGATE(); BDRVQcow2State *s =3D bs->opaque; int flags =3D s->flags; QCryptoBlock *crypto =3D NULL; QDict *options; - Error *local_err =3D NULL; int ret; =20 /* @@ -2446,11 +2441,11 @@ static void coroutine_fn qcow2_co_invalidate_cache(= BlockDriverState *bs, =20 flags &=3D ~BDRV_O_INACTIVE; qemu_co_mutex_lock(&s->lock); - ret =3D qcow2_do_open(bs, options, flags, &local_err); + ret =3D qcow2_do_open(bs, options, flags, errp); qemu_co_mutex_unlock(&s->lock); qobject_unref(options); - if (local_err) { - error_propagate_prepend(errp, local_err, + if (*errp) { + error_prepend(errp, "Could not reopen qcow2 layer: "); bs->drv =3D NULL; return; @@ -3036,6 +3031,7 @@ static uint64_t qcow2_opt_get_refcount_bits_del(QemuO= pts *opts, int version, static int coroutine_fn qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp) { + ERRP_AUTO_PROPAGATE(); BlockdevCreateOptionsQcow2 *qcow2_opts; QDict *options; =20 @@ -3059,7 +3055,6 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) int version; int refcount_order; uint64_t* refcount_table; - Error *local_err =3D NULL; int ret; =20 assert(create_options->driver =3D=3D BLOCKDEV_DRIVER_QCOW2); @@ -3258,9 +3253,8 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) } blk =3D blk_new_open(NULL, NULL, options, BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_NO_FLUSH, - &local_err); + errp); if (blk =3D=3D NULL) { - error_propagate(errp, local_err); ret =3D -EIO; goto out; } @@ -3339,9 +3333,8 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) } blk =3D blk_new_open(NULL, NULL, options, BDRV_O_RDWR | BDRV_O_NO_BACKING | BDRV_O_NO_IO, - &local_err); + errp); if (blk =3D=3D NULL) { - error_propagate(errp, local_err); ret =3D -EIO; goto out; } @@ -3357,12 +3350,12 @@ out: static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpt= s *opts, Error **errp) { + ERRP_AUTO_PROPAGATE(); BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; Visitor *v; BlockDriverState *bs =3D NULL; BlockDriverState *data_bs =3D NULL; - Error *local_err =3D NULL; const char *val; int ret; =20 @@ -3457,11 +3450,10 @@ static int coroutine_fn qcow2_co_create_opts(const = char *filename, QemuOpts *opt goto finish; } =20 - visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); + visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp); visit_free(v); =20 - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { ret =3D -EINVAL; goto finish; } @@ -3740,6 +3732,7 @@ fail: static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t of= fset, PreallocMode prealloc, Error **e= rrp) { + ERRP_AUTO_PROPAGATE(); BDRVQcow2State *s =3D bs->opaque; uint64_t old_length; int64_t new_l1_size; @@ -3824,12 +3817,10 @@ static int coroutine_fn qcow2_co_truncate(BlockDriv= erState *bs, int64_t offset, goto fail; } if ((last_cluster + 1) * s->cluster_size < old_file_size) { - Error *local_err =3D NULL; - bdrv_co_truncate(bs->file, (last_cluster + 1) * s->cluster_siz= e, - PREALLOC_MODE_OFF, &local_err); - if (local_err) { - warn_reportf_err(local_err, + PREALLOC_MODE_OFF, errp); + if (*errp) { + warn_reportf_err(*errp, "Failed to truncate the tail of the image= : "); } } @@ -4405,7 +4396,7 @@ static bool qcow2_measure_luks_headerlen(QemuOpts *op= ts, size_t *len, static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *i= n_bs, Error **errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); BlockMeasureInfo *info; uint64_t required =3D 0; /* bytes that contribute to required size */ uint64_t virtual_size; /* disk size as seen by guest */ @@ -4420,26 +4411,26 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *op= ts, BlockDriverState *in_bs, bool has_luks; =20 /* Parse image creation options */ - cluster_size =3D qcow2_opt_get_cluster_size_del(opts, &local_err); - if (local_err) { + cluster_size =3D qcow2_opt_get_cluster_size_del(opts, errp); + if (*errp) { goto err; } =20 - version =3D qcow2_opt_get_version_del(opts, &local_err); - if (local_err) { + version =3D qcow2_opt_get_version_del(opts, errp); + if (*errp) { goto err; } =20 - refcount_bits =3D qcow2_opt_get_refcount_bits_del(opts, version, &loca= l_err); - if (local_err) { + refcount_bits =3D qcow2_opt_get_refcount_bits_del(opts, version, errp); + if (*errp) { goto err; } =20 optstr =3D qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); prealloc =3D qapi_enum_parse(&PreallocMode_lookup, optstr, - PREALLOC_MODE_OFF, &local_err); + PREALLOC_MODE_OFF, errp); g_free(optstr); - if (local_err) { + if (*errp) { goto err; } =20 @@ -4454,7 +4445,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, if (has_luks) { size_t headerlen; =20 - if (!qcow2_measure_luks_headerlen(opts, &headerlen, &local_err)) { + if (!qcow2_measure_luks_headerlen(opts, &headerlen, errp)) { goto err; } =20 @@ -4468,7 +4459,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, l2_tables =3D DIV_ROUND_UP(virtual_size / cluster_size, cluster_size / sizeof(uint64_t)); if (l2_tables * sizeof(uint64_t) > QCOW_MAX_L1_SIZE) { - error_setg(&local_err, "The image size is too large " + error_setg(errp, "The image size is too large " "(try using a larger cluster size)"); goto err; } @@ -4477,7 +4468,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, if (in_bs) { int64_t ssize =3D bdrv_getlength(in_bs); if (ssize < 0) { - error_setg_errno(&local_err, -ssize, + error_setg_errno(errp, -ssize, "Unable to get image virtual_size"); goto err; } @@ -4502,7 +4493,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, ssize - offset, &pnum, NULL, NULL); if (ret < 0) { - error_setg_errno(&local_err, -ret, + error_setg_errno(errp, -ret, "Unable to get block status"); goto err; } @@ -4541,7 +4532,6 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, return info; =20 err: - error_propagate(errp, local_err); return NULL; } =20 @@ -4557,15 +4547,14 @@ static int qcow2_get_info(BlockDriverState *bs, Blo= ckDriverInfo *bdi) static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs, Error **errp) { + ERRP_AUTO_PROPAGATE(); BDRVQcow2State *s =3D bs->opaque; ImageInfoSpecific *spec_info; QCryptoBlockInfo *encrypt_info =3D NULL; - Error *local_err =3D NULL; =20 if (s->crypto !=3D NULL) { - encrypt_info =3D qcrypto_block_get_info(s->crypto, &local_err); - if (local_err) { - error_propagate(errp, local_err); + encrypt_info =3D qcrypto_block_get_info(s->crypto, errp); + if (*errp) { return NULL; } } @@ -4582,9 +4571,8 @@ static ImageInfoSpecific *qcow2_get_specific_info(Blo= ckDriverState *bs, }; } else if (s->qcow_version =3D=3D 3) { Qcow2BitmapInfoList *bitmaps; - bitmaps =3D qcow2_get_bitmap_info_list(bs, &local_err); - if (local_err) { - error_propagate(errp, local_err); + bitmaps =3D qcow2_get_bitmap_info_list(bs, errp); + if (*errp) { qapi_free_ImageInfoSpecific(spec_info); return NULL; } --=20 2.21.0