From patchwork Fri Oct 11 16:05:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 11185983 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 898D7912 for ; Fri, 11 Oct 2019 17:01:37 +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 5982E206A1 for ; Fri, 11 Oct 2019 17:01:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5982E206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIyIJ-0004lq-Ih for patchwork-qemu-devel@patchwork.kernel.org; Fri, 11 Oct 2019 13:01:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37027) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIxRD-0006k5-CG for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:06:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIxR8-0004oN-JC for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:06:43 -0400 Received: from relay.sw.ru ([185.231.240.75]:48470) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iIxR8-0004WM-8x for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:06:38 -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 1iIxQv-0003XG-KW; Fri, 11 Oct 2019 19:06:25 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [RFC v5 087/126] Migration: introduce ERRP_AUTO_PROPAGATE Date: Fri, 11 Oct 2019 19:05:13 +0300 Message-Id: <20191011160552.22907-88-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 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, Juan Quintela , armbru@redhat.com, "Dr. David Alan Gilbert" , Greg Kurz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 == &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 --- migration/migration.c | 39 ++++++++++++++++++--------------------- migration/ram.c | 13 ++++++------- migration/rdma.c | 13 ++++++------- migration/savevm.c | 2 ++ migration/socket.c | 18 ++++++++---------- 5 files changed, 40 insertions(+), 45 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 5f7e4d15e9..36a0b9e783 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -583,6 +583,7 @@ void migration_fd_process_incoming(QEMUFile *f) void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) { + ERRP_AUTO_PROPAGATE(); MigrationIncomingState *mis = migration_incoming_get_current(); bool start_migration; @@ -603,12 +604,10 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) */ start_migration = !migrate_use_multifd(); } else { - Error *local_err = NULL; /* Multiple connections */ assert(migrate_use_multifd()); - start_migration = multifd_recv_new_channel(ioc, &local_err); - if (local_err) { - error_propagate(errp, local_err); + start_migration = multifd_recv_new_channel(ioc, errp); + if (*errp) { return; } } @@ -971,6 +970,7 @@ static bool migrate_caps_check(bool *cap_list, MigrationCapabilityStatusList *params, Error **errp) { + ERRP_AUTO_PROPAGATE(); MigrationCapabilityStatusList *cap; bool old_postcopy_cap; MigrationIncomingState *mis = migration_incoming_get_current(); @@ -1764,7 +1764,7 @@ void migrate_del_blocker(Error *reason) void qmp_migrate_incoming(const char *uri, Error **errp) { - Error *local_err = NULL; + ERRP_AUTO_PROPAGATE(); static bool once = true; if (!deferred_incoming) { @@ -1775,10 +1775,9 @@ void qmp_migrate_incoming(const char *uri, Error **errp) error_setg(errp, "The incoming migration has already been started"); } - qemu_start_incoming_migration(uri, &local_err); + qemu_start_incoming_migration(uri, errp); - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { return; } @@ -1856,7 +1855,7 @@ bool migration_is_blocked(Error **errp) static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc, bool resume, Error **errp) { - Error *local_err = NULL; + ERRP_AUTO_PROPAGATE(); if (resume) { if (s->state != MIGRATION_STATUS_POSTCOPY_PAUSED) { @@ -1909,9 +1908,8 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc, "current migration capabilities"); return false; } - migrate_set_block_enabled(true, &local_err); - if (local_err) { - error_propagate(errp, local_err); + migrate_set_block_enabled(true, errp); + if (*errp) { return false; } s->must_remove_block_options = true; @@ -1935,7 +1933,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, bool has_inc, bool inc, bool has_detach, bool detach, bool has_resume, bool resume, Error **errp) { - Error *local_err = NULL; + ERRP_AUTO_PROPAGATE(); MigrationState *s = migrate_get_current(); const char *p; @@ -1946,17 +1944,17 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, } if (strstart(uri, "tcp:", &p)) { - tcp_start_outgoing_migration(s, p, &local_err); + tcp_start_outgoing_migration(s, p, errp); #ifdef CONFIG_RDMA } else if (strstart(uri, "rdma:", &p)) { - rdma_start_outgoing_migration(s, p, &local_err); + rdma_start_outgoing_migration(s, p, errp); #endif } else if (strstart(uri, "exec:", &p)) { - exec_start_outgoing_migration(s, p, &local_err); + exec_start_outgoing_migration(s, p, errp); } else if (strstart(uri, "unix:", &p)) { - unix_start_outgoing_migration(s, p, &local_err); + unix_start_outgoing_migration(s, p, errp); } else if (strstart(uri, "fd:", &p)) { - fd_start_outgoing_migration(s, p, &local_err); + fd_start_outgoing_migration(s, p, errp); } else { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); @@ -1966,9 +1964,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, return; } - if (local_err) { - migrate_fd_error(s, local_err); - error_propagate(errp, local_err); + if (*errp) { + migrate_fd_error(s, *errp); return; } } diff --git a/migration/ram.c b/migration/ram.c index 22423f08cd..0100c11dd7 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1474,14 +1474,14 @@ bool multifd_recv_all_channels_created(void) */ bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp) { + ERRP_AUTO_PROPAGATE(); MultiFDRecvParams *p; - Error *local_err = NULL; int id; - id = multifd_recv_initial_packet(ioc, &local_err); + id = multifd_recv_initial_packet(ioc, errp); if (id < 0) { - multifd_recv_terminate_threads(local_err); - error_propagate_prepend(errp, local_err, + multifd_recv_terminate_threads(*errp); + error_prepend(errp, "failed to receive packet" " via multifd channel %d: ", atomic_read(&multifd_recv_state->count)); @@ -1491,10 +1491,9 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp) p = &multifd_recv_state->params[id]; if (p->c != NULL) { - error_setg(&local_err, "multifd: received id '%d' already setup'", + error_setg(errp, "multifd: received id '%d' already setup'", id); - multifd_recv_terminate_threads(local_err); - error_propagate(errp, local_err); + multifd_recv_terminate_threads(*errp); return false; } p->c = ioc; diff --git a/migration/rdma.c b/migration/rdma.c index 4c74e88a37..db985fee73 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -2396,8 +2396,9 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) static int qemu_rdma_source_init(RDMAContext *rdma, bool pin_all, Error **errp) { + ERRP_AUTO_PROPAGATE(); int ret, idx; - Error *local_err = NULL, **temp = &local_err; + Error **temp = errp; /* * Will be validated against destination's actual capabilities @@ -2450,7 +2451,6 @@ static int qemu_rdma_source_init(RDMAContext *rdma, bool pin_all, Error **errp) return 0; err_rdma_source_init: - error_propagate(errp, local_err); qemu_rdma_cleanup(rdma); return -1; } @@ -4044,18 +4044,18 @@ static void rdma_accept_incoming_migration(void *opaque) void rdma_start_incoming_migration(const char *host_port, Error **errp) { + ERRP_AUTO_PROPAGATE(); int ret; RDMAContext *rdma, *rdma_return_path = NULL; - Error *local_err = NULL; trace_rdma_start_incoming_migration(); - rdma = qemu_rdma_data_init(host_port, &local_err); + rdma = qemu_rdma_data_init(host_port, errp); if (rdma == NULL) { goto err; } - ret = qemu_rdma_dest_init(rdma, &local_err); + ret = qemu_rdma_dest_init(rdma, errp); if (ret) { goto err; @@ -4074,7 +4074,7 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp) /* initialize the RDMAContext for return path */ if (migrate_postcopy()) { - rdma_return_path = qemu_rdma_data_init(host_port, &local_err); + rdma_return_path = qemu_rdma_data_init(host_port, errp); if (rdma_return_path == NULL) { goto err; @@ -4087,7 +4087,6 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp) NULL, (void *)(intptr_t)rdma); return; err: - error_propagate(errp, local_err); g_free(rdma); g_free(rdma_return_path); } diff --git a/migration/savevm.c b/migration/savevm.c index bb9462a54d..f9293fe192 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2586,6 +2586,7 @@ int qemu_load_device_state(QEMUFile *f) int save_snapshot(const char *name, Error **errp) { + ERRP_AUTO_PROPAGATE(); BlockDriverState *bs, *bs1; QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1; int ret = -1; @@ -2790,6 +2791,7 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp) int load_snapshot(const char *name, Error **errp) { + ERRP_AUTO_PROPAGATE(); BlockDriverState *bs, *bs_vm_state; QEMUSnapshotInfo sn; QEMUFile *f; diff --git a/migration/socket.c b/migration/socket.c index 97c9efde59..bc07ef92a1 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -139,12 +139,11 @@ void tcp_start_outgoing_migration(MigrationState *s, const char *host_port, Error **errp) { - Error *err = NULL; - SocketAddress *saddr = tcp_build_address(host_port, &err); - if (!err) { - socket_start_outgoing_migration(s, saddr, &err); + ERRP_AUTO_PROPAGATE(); + SocketAddress *saddr = tcp_build_address(host_port, errp); + if (!*errp) { + socket_start_outgoing_migration(s, saddr, errp); } - error_propagate(errp, err); } void unix_start_outgoing_migration(MigrationState *s, @@ -209,13 +208,12 @@ static void socket_start_incoming_migration(SocketAddress *saddr, void tcp_start_incoming_migration(const char *host_port, Error **errp) { - Error *err = NULL; - SocketAddress *saddr = tcp_build_address(host_port, &err); - if (!err) { - socket_start_incoming_migration(saddr, &err); + ERRP_AUTO_PROPAGATE(); + SocketAddress *saddr = tcp_build_address(host_port, errp); + if (!*errp) { + socket_start_incoming_migration(saddr, errp); } qapi_free_SocketAddress(saddr); - error_propagate(errp, err); } void unix_start_incoming_migration(const char *path, Error **errp)