From patchwork Fri Oct 14 15:28:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 9376967 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 3BAC26022E for ; Fri, 14 Oct 2016 15:33:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C9EE29F6F for ; Fri, 14 Oct 2016 15:33:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2135129FAD; Fri, 14 Oct 2016 15:33:52 +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 70C1B2A774 for ; Fri, 14 Oct 2016 15:33:51 +0000 (UTC) Received: from localhost ([::1]:47933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv4UY-0002YH-GL for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Oct 2016 11:33:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv4Pg-0007Kl-OI for qemu-devel@nongnu.org; Fri, 14 Oct 2016 11:28:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bv4Pf-0008IO-1L for qemu-devel@nongnu.org; Fri, 14 Oct 2016 11:28:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57244) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv4Pe-0008IC-O8 for qemu-devel@nongnu.org; Fri, 14 Oct 2016 11:28:46 -0400 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 4C8AE1CCA8A for ; Fri, 14 Oct 2016 15:28:46 +0000 (UTC) Received: from emacs.mitica (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9EFSV1B025555; Fri, 14 Oct 2016 11:28:44 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 14 Oct 2016 17:28:16 +0200 Message-Id: <1476458903-7888-9-git-send-email-quintela@redhat.com> In-Reply-To: <1476458903-7888-1-git-send-email-quintela@redhat.com> References: <1476458903-7888-1-git-send-email-quintela@redhat.com> MIME-Version: 1.0 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.26]); Fri, 14 Oct 2016 15:28:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/15] migrate: Use boxed qapi for migrate-set-parameters 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: amit.shah@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Blake Now that QAPI makes it easy to pass a struct around, we don't have to declare as many parameters or local variables. Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- hmp.c | 40 ++++++++++++++----------------- migration/migration.c | 65 +++++++++++++++++++++------------------------------ qapi-schema.json | 2 +- 3 files changed, 46 insertions(+), 61 deletions(-) diff --git a/hmp.c b/hmp.c index c405d3e..4c0f600 100644 --- a/hmp.c +++ b/hmp.c @@ -1325,44 +1325,40 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) const char *valuestr = qdict_get_str(qdict, "value"); long valueint = 0; Error *err = NULL; - bool has_compress_level = false; - bool has_compress_threads = false; - bool has_decompress_threads = false; - bool has_cpu_throttle_initial = false; - bool has_cpu_throttle_increment = false; - bool has_tls_creds = false; - bool has_tls_hostname = false; bool use_int_value = false; int i; for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) { if (strcmp(param, MigrationParameter_lookup[i]) == 0) { + MigrationParameters p = { 0 }; switch (i) { case MIGRATION_PARAMETER_COMPRESS_LEVEL: - has_compress_level = true; + p.has_compress_level = true; use_int_value = true; break; case MIGRATION_PARAMETER_COMPRESS_THREADS: - has_compress_threads = true; + p.has_compress_threads = true; use_int_value = true; break; case MIGRATION_PARAMETER_DECOMPRESS_THREADS: - has_decompress_threads = true; + p.has_decompress_threads = true; use_int_value = true; break; case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: - has_cpu_throttle_initial = true; + p.has_cpu_throttle_initial = true; use_int_value = true; break; case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: - has_cpu_throttle_increment = true; + p.has_cpu_throttle_increment = true; use_int_value = true; break; case MIGRATION_PARAMETER_TLS_CREDS: - has_tls_creds = true; + p.has_tls_creds = true; + p.tls_creds = (char *) valuestr; break; case MIGRATION_PARAMETER_TLS_HOSTNAME: - has_tls_hostname = true; + p.has_tls_hostname = true; + p.tls_hostname = (char *) valuestr; break; } @@ -1372,16 +1368,16 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) valuestr); goto cleanup; } + /* Set all integers; only one has_FOO will be set, and + * the code ignores the remaining values */ + p.compress_level = valueint; + p.compress_threads = valueint; + p.decompress_threads = valueint; + p.cpu_throttle_initial = valueint; + p.cpu_throttle_increment = valueint; } - qmp_migrate_set_parameters(has_compress_level, valueint, - has_compress_threads, valueint, - has_decompress_threads, valueint, - has_cpu_throttle_initial, valueint, - has_cpu_throttle_increment, valueint, - has_tls_creds, valuestr, - has_tls_hostname, valuestr, - &err); + qmp_migrate_set_parameters(&p, &err); break; } } diff --git a/migration/migration.c b/migration/migration.c index 1a8f26b..42336e3 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -766,78 +766,67 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params, } } -void qmp_migrate_set_parameters(bool has_compress_level, - int64_t compress_level, - bool has_compress_threads, - int64_t compress_threads, - bool has_decompress_threads, - int64_t decompress_threads, - bool has_cpu_throttle_initial, - int64_t cpu_throttle_initial, - bool has_cpu_throttle_increment, - int64_t cpu_throttle_increment, - bool has_tls_creds, - const char *tls_creds, - bool has_tls_hostname, - const char *tls_hostname, - Error **errp) +void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp) { MigrationState *s = migrate_get_current(); - if (has_compress_level && (compress_level < 0 || compress_level > 9)) { + if (params->has_compress_level && + (params->compress_level < 0 || params->compress_level > 9)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level", "is invalid, it should be in the range of 0 to 9"); return; } - if (has_compress_threads && - (compress_threads < 1 || compress_threads > 255)) { + if (params->has_compress_threads && + (params->compress_threads < 1 || params->compress_threads > 255)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_threads", "is invalid, it should be in the range of 1 to 255"); return; } - if (has_decompress_threads && - (decompress_threads < 1 || decompress_threads > 255)) { + if (params->has_decompress_threads && + (params->decompress_threads < 1 || params->decompress_threads > 255)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "decompress_threads", "is invalid, it should be in the range of 1 to 255"); return; } - if (has_cpu_throttle_initial && - (cpu_throttle_initial < 1 || cpu_throttle_initial > 99)) { + if (params->has_cpu_throttle_initial && + (params->cpu_throttle_initial < 1 || + params->cpu_throttle_initial > 99)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu_throttle_initial", "an integer in the range of 1 to 99"); } - if (has_cpu_throttle_increment && - (cpu_throttle_increment < 1 || cpu_throttle_increment > 99)) { + if (params->has_cpu_throttle_increment && + (params->cpu_throttle_increment < 1 || + params->cpu_throttle_increment > 99)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu_throttle_increment", "an integer in the range of 1 to 99"); } - if (has_compress_level) { - s->parameters.compress_level = compress_level; + if (params->has_compress_level) { + s->parameters.compress_level = params->compress_level; } - if (has_compress_threads) { - s->parameters.compress_threads = compress_threads; + if (params->has_compress_threads) { + s->parameters.compress_threads = params->compress_threads; } - if (has_decompress_threads) { - s->parameters.decompress_threads = decompress_threads; + if (params->has_decompress_threads) { + s->parameters.decompress_threads = params->decompress_threads; } - if (has_cpu_throttle_initial) { - s->parameters.cpu_throttle_initial = cpu_throttle_initial; + if (params->has_cpu_throttle_initial) { + s->parameters.cpu_throttle_initial = params->cpu_throttle_initial; } - if (has_cpu_throttle_increment) { - s->parameters.cpu_throttle_increment = cpu_throttle_increment; + if (params->has_cpu_throttle_increment) { + s->parameters.cpu_throttle_increment = params->cpu_throttle_increment; } - if (has_tls_creds) { + if (params->has_tls_creds) { g_free(s->parameters.tls_creds); - s->parameters.tls_creds = g_strdup(tls_creds); + s->parameters.tls_creds = g_strdup(params->tls_creds); } - if (has_tls_hostname) { + if (params->has_tls_hostname) { g_free(s->parameters.tls_hostname); - s->parameters.tls_hostname = g_strdup(tls_hostname); + s->parameters.tls_hostname = g_strdup(params->tls_hostname); } } diff --git a/qapi-schema.json b/qapi-schema.json index e16e889..58bed71 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -672,7 +672,7 @@ # # Since: 2.4 ## -{ 'command': 'migrate-set-parameters', +{ 'command': 'migrate-set-parameters', 'boxed': true, 'data': 'MigrationParameters' } #