From patchwork Mon Jul 2 10:49:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 937788 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 41K3vz6NGqz9s29 for ; Mon, 2 Jul 2018 20:51:27 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 3F176CB0; Mon, 2 Jul 2018 10:50:36 +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 43956CAB for ; Mon, 2 Jul 2018 10:50:35 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id CA504691 for ; Mon, 2 Jul 2018 10:50:33 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id i139-v6so8494044wmf.4 for ; Mon, 02 Jul 2018 03:50:33 -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=cGHlppugSqRi//GD9SjU2i0Y/eNVHNmPCvpjFCGYNRU=; b=EljibAz9fxHAs4KgFG3yaaQvx0mB/4ZrwGfU8wBsvvTpn9lIC3DLeMPCAirn8kg08R Zg4eVu5hPlpUqXEYtIIzkp+9r6b3LtwkSIo3x7ScWz8Es4j/3nl34EK4ol7hW1yC2L4B 9p+328Kzaxa4QVQA6QSShGBXpnqcL0kMjTc5WLsRkQ2lMwXhNO+i9gBHe6Y6rKpXFZzD CE0ymdgrwnU3bzpcDOompPmqZoXi/fxIHdo5hhAWWdzUhVfN4ThXgnIlfO+xKNMDJ8bq vBYqRowCM9LgbfDsJYlWtvv71dtYW+Ykr78KeJsx06I5+Mzb48gi7OIWPiHjsuHJlv/A hmKQ== X-Gm-Message-State: APt69E1w7LkAMy80WmJ0kejHlCAvOfIVFGlKgmsZeoGrcc7vOx75C6rs XdacEEqw8B9+u/U0ICTy9CQJxs9HvjU= X-Google-Smtp-Source: AAOMgpcGjQECerNtb+H6Lxuz/Bzd4qPubjcFVv6/8TFpuTrVQYipv6Fe4hfwVsEMEiwnWEHEpVM7yA== X-Received: by 2002:a1c:f46:: with SMTP id 67-v6mr5232679wmp.122.1530528632097; Mon, 02 Jul 2018 03:50:32 -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 a203-v6sm7106512wme.46.2018.07.02.03.50.30 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Jul 2018 03:50:31 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Mon, 2 Jul 2018 12:49:59 +0200 Message-Id: <20180702105019.10345-4-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180702105019.10345-1-jkbs@redhat.com> References: <20180702105019.10345-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 03/23] db-ctl-base: Don't die in is_condition_satisfied() on error. 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 Return the error message to the caller instead of reporting it and dying so that the caller can handle the error without terminating the process if needed. Also, rename the function as it is no longer a typical predicate, so that the users don't assume that the result is passed in return value. Signed-off-by: Jakub Sitnicki --- lib/db-ctl-base.c | 65 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c index 22af30667..a826dfb94 100644 --- a/lib/db-ctl-base.c +++ b/lib/db-ctl-base.c @@ -706,10 +706,14 @@ evaluate_relop(const struct ovsdb_datum *a, const struct ovsdb_datum *b, } } -static bool -is_condition_satisfied(const struct ovsdb_idl_table_class *table, - const struct ovsdb_idl_row *row, const char *arg, - struct ovsdb_symbol_table *symtab) +/* Checks if given row satisfies the specified condition. Returns the result of + * evaluating the condition in 'satisfied' flag and NULL as a return value on + * success. On failure returns a malloc()'ed error message and 'satisfied' + * value is not modified. */ +static char * OVS_WARN_UNUSED_RESULT +check_condition(const struct ovsdb_idl_table_class *table, + const struct ovsdb_idl_row *row, const char *arg, + struct ovsdb_symbol_table *symtab, bool *satisfied) { static const char *operators[] = { #define RELOP(ENUM, STRING) STRING, @@ -719,18 +723,24 @@ is_condition_satisfied(const struct ovsdb_idl_table_class *table, const struct ovsdb_idl_column *column; const struct ovsdb_datum *have_datum; - char *key_string, *value_string; + char *key_string = NULL; + char *value_string = NULL; struct ovsdb_type type; int operator; bool retval; char *error; + ovs_assert(satisfied); + error = parse_column_key_value(arg, table, &column, &key_string, &operator, operators, ARRAY_SIZE(operators), &value_string); - die_if_error(error); + if (error) { + goto out; + } if (!value_string) { - ctl_fatal("%s: missing value", arg); + error = xasprintf("%s: missing value", arg); + goto out; } type = column->type; @@ -743,16 +753,23 @@ is_condition_satisfied(const struct ovsdb_idl_table_class *table, unsigned int idx; if (column->type.value.type == OVSDB_TYPE_VOID) { - ctl_fatal("cannot specify key to check for non-map column %s", - column->name); + error = xasprintf("cannot specify key to check for non-map column " + "%s", column->name); + goto out; } - die_if_error(ovsdb_atom_from_string(&want_key, NULL, &column->type.key, - key_string, symtab)); + error = ovsdb_atom_from_string(&want_key, NULL, &column->type.key, + key_string, symtab); + if (error) { + goto out; + } type.key = type.value; type.value.type = OVSDB_TYPE_VOID; - die_if_error(ovsdb_datum_from_string(&b, &type, value_string, symtab)); + error = ovsdb_datum_from_string(&b, &type, value_string, symtab); + if (error) { + goto out; + } idx = ovsdb_datum_find_key(have_datum, &want_key, column->type.key.type); @@ -779,16 +796,21 @@ is_condition_satisfied(const struct ovsdb_idl_table_class *table, } else { struct ovsdb_datum want_datum; - die_if_error(ovsdb_datum_from_string(&want_datum, &column->type, - value_string, symtab)); + error = ovsdb_datum_from_string(&want_datum, &column->type, + value_string, symtab); + if (error) { + goto out; + } retval = evaluate_relop(have_datum, &want_datum, &type, operator); ovsdb_datum_destroy(&want_datum, &column->type); } + *satisfied = retval; +out: free(key_string); free(value_string); - return retval; + return error; } static void @@ -1157,8 +1179,11 @@ cmd_find(struct ctl_context *ctx) int i; for (i = 2; i < ctx->argc; i++) { - if (!is_condition_satisfied(table, row, ctx->argv[i], - ctx->symtab)) { + bool satisfied; + + die_if_error(check_condition(table, row, ctx->argv[i], ctx->symtab, + &satisfied)); + if (!satisfied) { goto next_row; } } @@ -1599,7 +1624,11 @@ cmd_wait_until(struct ctl_context *ctx) } for (i = 3; i < ctx->argc; i++) { - if (!is_condition_satisfied(table, row, ctx->argv[i], ctx->symtab)) { + bool satisfied; + + die_if_error(check_condition(table, row, ctx->argv[i], ctx->symtab, + &satisfied)); + if (!satisfied) { ctx->try_again = true; return; }