From patchwork Thu Jul 19 13:51:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 946340 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 41Wb7x3Jz4z9s55 for ; Thu, 19 Jul 2018 23:53:17 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1B32AF25; Thu, 19 Jul 2018 13:51:38 +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 1EF65F1C for ; Thu, 19 Jul 2018 13:51:36 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 91CCE5D4 for ; Thu, 19 Jul 2018 13:51:35 +0000 (UTC) Received: by mail-wm0-f45.google.com with SMTP id h3-v6so5873205wmb.1 for ; Thu, 19 Jul 2018 06:51:35 -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=eW8QL+SA2oAIAVJJouqT1NLBQS16FoZ7pTl+jdQBoDM=; b=kVj7r9YjdoCjxArpt+w4II3hiuhkNG5WYjvwrGu8GnDTKOz2MEgmCxJDcSuzZAFoES SEakNYMbCCyfpnLCWcvSCed7x0E9nWUE/drR7SpPMHGPg2mNDQdWmBkkfsheW+8aSg3u UBDf4vzF5Q6FrHcQ2f88WcSnoBzLahhObJ4U6RCPzzmdF8289aLKzVUvNd3n9CufL++y NkFXp4tRgnIOjJcblvkCDTKX96WcDWa8bI6QRHd3EBoUhrY5NjYrXpQkUnLmg0AfKSKp vYAXii7X/F4JS4KCSYpqPn8/EASpuGidx+BHydkYnFGOyYyHjA6AxBG/GGeztAhszt/j sgVQ== X-Gm-Message-State: AOUpUlHV0MIO5/Fh+Wf9sJ7KWdGwQ0ufPbc49nJ+2rWdarh1RP5Qcp7w W+nsyin5vgY/bIZjpfJZx4B6jqhbxRo= X-Google-Smtp-Source: AAOMgpebDnkjmtnEYpWTt5BXimcjuafkp/HNcyawsIGr13pwLUT3py9OjQKfJXGsrDIO5SyVeYsC7A== X-Received: by 2002:a1c:815:: with SMTP id 21-v6mr4274532wmi.151.1532008294049; Thu, 19 Jul 2018 06:51:34 -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 z1-v6sm3502274wmf.5.2018.07.19.06.51.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jul 2018 06:51:33 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Thu, 19 Jul 2018 15:51:08 +0200 Message-Id: <20180719135126.19636-4-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180719135126.19636-1-jkbs@redhat.com> References: <20180719135126.19636-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 v5 03/21] ovn-nbctl: Extract the main loop. 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 Split out a routine for the main ovn-nbctl loop. Preparatory work for introducing daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 47df19b23..a027553b7 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -88,6 +88,8 @@ static bool do_nbctl(const char *args, struct ctl_command *, size_t n, struct ovsdb_idl *); 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, + size_t n_commands, struct ovsdb_idl *idl); int main(int argc, char *argv[]) @@ -95,7 +97,6 @@ main(int argc, char *argv[]) struct ovsdb_idl *idl; struct ctl_command *commands; struct shash local_options; - unsigned int seqno; size_t n_commands; set_program_name(argv[0]); @@ -123,6 +124,18 @@ main(int argc, char *argv[]) ovsdb_idl_set_leader_only(idl, leader_only); run_prerequisites(commands, n_commands, idl); + main_loop(args, commands, n_commands, idl); + + free(args); + exit(EXIT_SUCCESS); +} + +static void +main_loop(const char *args, struct ctl_command *commands, size_t n_commands, + struct ovsdb_idl *idl) +{ + unsigned int seqno; + /* Execute the commands. * * 'seqno' is the database sequence number for which we last tried to @@ -136,14 +149,13 @@ main(int argc, char *argv[]) if (!ovsdb_idl_is_alive(idl)) { int retval = ovsdb_idl_get_last_error(idl); ctl_fatal("%s: database connection failed (%s)", - db, ovs_retval_to_string(retval)); + db, ovs_retval_to_string(retval)); } if (seqno != ovsdb_idl_get_seqno(idl)) { seqno = ovsdb_idl_get_seqno(idl); if (do_nbctl(args, commands, n_commands, idl)) { - free(args); - exit(EXIT_SUCCESS); + return; } }