From patchwork Tue Jul 17 13:34:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 945049 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41VLsz3YDYz9rxs for ; Tue, 17 Jul 2018 23:36:55 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 8F6B5CE1; Tue, 17 Jul 2018 13:34:31 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 07E52CCA for ; Tue, 17 Jul 2018 13:34:29 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C8134FC for ; Tue, 17 Jul 2018 13:34:27 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id h10-v6so1293799wre.6 for ; Tue, 17 Jul 2018 06:34:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=2zhjQrFhpotiDq/lpp8cbLkYtSk12URfshOym6+4DUo=; b=nuLgS/zc5vURXiH/VY0ueDfxL+TsJn3GPdkR/HF1L52T7CJ622muc45nubdH7FGifT YsiZDKoKoWqYP8VH3nSeSBJkUbCqDQLeWXt59X1GtFDu2H8lQqBixnbVNl5KBCXBqy4J zKg3Fcd5Q5nl2H8zwpoxHYL8koY/A1I0Srpv/I+ig9TnHZS35BkukcQlPzKS8epBtt2N qRPIaccSckPJ1F8yGf7ahcuInYKLsYUE+nFM1tN10VWmWKcTM0mkHDZejPOujNs9u1Ie gzLc6nrUKIQmxf5YopHnj2I9XJ5SmfJQrKynXw9OwGINkipV7NeLvOdo3CmYtEATVFS6 pOGA== X-Gm-Message-State: AOUpUlHEZkIDqO+ISf8Sl3LR/pw0ABrg6eDewrxDZLaF7r14eAogmfJW epklcYQc/mJyFgmAOI+wCCXFLybAyMQ= X-Google-Smtp-Source: AAOMgpcF0tnw7VAQ8/JyWnLLJHpuvSD9ky/XzMzvWTjepFIzXfB4dxEEOxAawayyw8UwRwg46F6JSQ== X-Received: by 2002:adf:93a3:: with SMTP id 32-v6mr1422701wrp.140.1531834466294; Tue, 17 Jul 2018 06:34:26 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id y11-v6sm2039196wrr.84.2018.07.17.06.34.25 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jul 2018 06:34:25 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Tue, 17 Jul 2018 15:34:10 +0200 Message-Id: <20180717133415.23781-7-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180717133415.23781-1-jkbs@redhat.com> References: <20180717133415.23781-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 06/11] ovn-nbctl: Don't die in parse_direction(). X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Let the caller handle the error. This prepares us for reporting errors in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 1cee059f2..c18fa2825 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -1671,17 +1671,19 @@ qos_cmp(const void *qos1_, const void *qos2_) } } -static const char * -parse_direction(const char *arg) +static char * OVS_WARN_UNUSED_RESULT +parse_direction(const char *arg, const char **direction_p) { /* Validate direction. Only require the first letter. */ if (arg[0] == 't') { - return "to-lport"; + *direction_p = "to-lport"; } else if (arg[0] == 'f') { - return "from-lport"; + *direction_p = "from-lport"; } else { - ctl_fatal("%s: direction must be \"to-lport\" or \"from-lport\"", arg); + return xasprintf("%s: direction must be \"to-lport\" or " + "\"from-lport\"", arg); } + return NULL; } static char * OVS_WARN_UNUSED_RESULT @@ -1710,7 +1712,12 @@ nbctl_acl_add(struct ctl_context *ctx) return; } - const char *direction = parse_direction(ctx->argv[2]); + const char *direction; + error = parse_direction(ctx->argv[2], &direction); + if (error) { + ctx->error = error; + return; + } int64_t priority; error = parse_priority(ctx->argv[3], &priority); if (error) { @@ -1804,7 +1811,11 @@ nbctl_acl_del(struct ctl_context *ctx) return; } - const char *direction = parse_direction(ctx->argv[2]); + const char *direction; + error = parse_direction(ctx->argv[2], &direction); + if (error) { + ctl_fatal("%s", error); + } size_t n_acls = pg ? pg->n_acls : ls->n_acls; struct nbrec_acl **acls = pg ? pg->acls : ls->acls; @@ -1917,13 +1928,18 @@ static void nbctl_qos_add(struct ctl_context *ctx) { const struct nbrec_logical_switch *ls; - const char *direction = parse_direction(ctx->argv[2]); + const char *direction; int64_t priority; int64_t dscp = -1; int64_t rate = 0; int64_t burst = 0; char *error; + error = parse_direction(ctx->argv[2], &direction); + if (error) { + ctx->error = error; + return; + } error = parse_priority(ctx->argv[3], &priority); if (error) { ctx->error = error; @@ -2034,7 +2050,12 @@ nbctl_qos_del(struct ctl_context *ctx) return; } - const char *direction = parse_direction(ctx->argv[2]); + const char *direction; + error = parse_direction(ctx->argv[2], &direction); + if (error) { + ctx->error = error; + return; + } /* If priority and match are not specified, delete all qos_rules with the * specified direction. */