From patchwork Fri Jul 13 18:36:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943770 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 41S1nN25CVz9s0n for ; Sat, 14 Jul 2018 04:39:52 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 2A5BDE48; Fri, 13 Jul 2018 18:36:42 +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 CB5F6E43 for ; Fri, 13 Jul 2018 18:36:39 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 963957B2 for ; Fri, 13 Jul 2018 18:36:38 +0000 (UTC) Received: by mail-wr1-f52.google.com with SMTP id m1-v6so13283512wrg.5 for ; Fri, 13 Jul 2018 11:36:38 -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:cc:subject:date:message-id:in-reply-to :references; bh=PVOT2BukTxFiIYIY9Bhpb+5zfNgWlYFWC44rgCeOj6c=; b=M/qyAzyr/Ba6H0QOjaYhSY3FhizfxWBJRf+qUchCMg4J0YhbWGDxT3i5BDFtRq+JIJ 4pA+Xcr0vP5pvFMRs94yRz/14wdAvPo5dcc6Ytj3NxGWeBFvcbD1VL3EYgy/CkjPKdLA 5VcA2ESDbThxFy5Fp8VttNbbIzBD8x23oO9JmGMUu9V1Ohf+tt3v5fFbCHx/o/j/zfdc 51p4gsqVBPKI5ECmdp2yeVbpP768THat9hYdEd6BENB3pemZ+BHcryh05J97rz7Lffxs CHouoMHSl69tVxQMn+YaInxMYXWoLjRGG8+xysgOttwyTDTok2psBWLQ7RttvZvw5bDW 6u3Q== X-Gm-Message-State: AOUpUlEHIh4+fLALsWDwq71/AjWaB8pi7q1ItdNEEwq75QVMSITixrNv 6PRWB2uasG3BinW7X82tn9lV7f7h+lc= X-Google-Smtp-Source: AAOMgpcxKOYGIasGnejNGafjN7jETB5nbcc+BekXOfyXp1H5pVvdxzm38mouLazHPKeS2RFJb6eCSQ== X-Received: by 2002:adf:9142:: with SMTP id j60-v6mr5495836wrj.180.1531506996948; Fri, 13 Jul 2018 11:36:36 -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 s10-v6sm11532670wmb.12.2018.07.13.11.36.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:36 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:14 +0200 Message-Id: <20180713183624.16937-8-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-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 v3 07/17] ovn-nbctl: Propagate the error from do_nbctl(). 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 Instead of terminating the process, return the error to the caller. This will allow us to reuse the main loop in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 360b25a89..6e136e1d0 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -84,8 +84,9 @@ OVS_NO_RETURN static void usage(void); static void parse_options(int argc, char *argv[], struct shash *local_options); static void run_prerequisites(struct ctl_command[], size_t n_commands, struct ovsdb_idl *); -static void do_nbctl(const char *args, struct ctl_command *, size_t n, - struct ovsdb_idl *, bool *retry); +static char * OVS_WARN_UNUSED_RESULT do_nbctl(const char *args, + struct ctl_command *, size_t n, + struct ovsdb_idl *, bool *retry); static const struct nbrec_dhcp_options *dhcp_options_get( struct ctl_context *ctx, const char *id, bool must_exist); static void main_loop(const char *args, struct ctl_command *commands, @@ -166,7 +167,10 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, seqno = ovsdb_idl_get_seqno(idl); bool retry; - do_nbctl(args, commands, n_commands, idl, &retry); + char *error = do_nbctl(args, commands, n_commands, idl, &retry); + if (error) { + ctl_fatal("%s", error); + } if (!retry) { return; } @@ -4137,7 +4141,7 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, } } -static void +static char * do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl, bool *retry) { @@ -4148,6 +4152,7 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, struct ctl_command *c; struct shash_node *node; int64_t next_cfg = 0; + char *error = NULL; ovs_assert(retry); @@ -4181,7 +4186,9 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, (c->syntax->run)(&ctx); } if (ctx.error) { - ctl_fatal("%s", ctx.error); + error = xstrdup(ctx.error); + ctl_context_done(&ctx, c); + goto out_error; } ctl_context_done_command(&ctx, c); @@ -4195,9 +4202,10 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, SHASH_FOR_EACH (node, &symtab->sh) { struct ovsdb_symbol *symbol = node->data; if (!symbol->created) { - ctl_fatal("row id \"%s\" is referenced but never created (e.g. " - "with \"-- --id=%s create ...\")", - node->name, node->name); + error = xasprintf("row id \"%s\" is referenced but never created " + "(e.g. with \"-- --id=%s create ...\")", + node->name, node->name); + goto out_error; } if (!symbol->strong_ref) { if (!symbol->weak_ref) { @@ -4222,7 +4230,9 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, ctl_context_init(&ctx, c, idl, txn, symtab, NULL); (c->syntax->postprocess)(&ctx); if (ctx.error) { - ctl_fatal("%s", ctx.error); + error = xstrdup(ctx.error); + ctl_context_done(&ctx, c); + goto out_error; } ctl_context_done(&ctx, c); } @@ -4236,7 +4246,8 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, case TXN_ABORTED: /* Should not happen--we never call ovsdb_idl_txn_abort(). */ - ctl_fatal("transaction aborted"); + error = xstrdup("transaction aborted"); + goto out_error; case TXN_UNCHANGED: case TXN_SUCCESS: @@ -4246,11 +4257,14 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, goto try_again; case TXN_ERROR: - ctl_fatal("transaction error: %s", ovsdb_idl_txn_get_error(txn)); + error = xasprintf("transaction error: %s", + ovsdb_idl_txn_get_error(txn)); + goto out_error; case TXN_NOT_LOCKED: /* Should not happen--we never call ovsdb_idl_set_lock(). */ - ctl_fatal("database not locked"); + error = xstrdup("database not locked"); + goto out_error; default: OVS_NOT_REACHED(); @@ -4309,11 +4323,14 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, ovsdb_idl_txn_destroy(txn); *retry = false; - return; + return NULL; try_again: /* Our transaction needs to be rerun, or a prerequisite was not met. Free * resources and return so that the caller can try again. */ + *retry = true; + +out_error: ovsdb_idl_txn_abort(txn); ovsdb_idl_txn_destroy(txn); the_idl_txn = NULL; @@ -4324,7 +4341,8 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, table_destroy(c->table); free(c->table); } - *retry = true; + + return error; } /* Frees the current transaction and the underlying IDL and then calls