From patchwork Mon Jul 9 18:57:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 941563 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 41PZN33NJzz9s0W for ; Tue, 10 Jul 2018 04:57:55 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A0EC8F43; Mon, 9 Jul 2018 18:57:30 +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 1947AF3F for ; Mon, 9 Jul 2018 18:57:29 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 8C0A46B7 for ; Mon, 9 Jul 2018 18:57:28 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id s13-v6so10742813wmc.1 for ; Mon, 09 Jul 2018 11:57:28 -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=RWU54IpKh+ekoZyH6t+76cCwEnu3uee+eT9FnhLQkCs=; b=rZhhUDZeCXOaLDufsw8sW5LY0EeaG8fwmU4wg0jFuWxwD6nFmZhEJCl/+115IArNAS mdTu+/4MIvnwqpMd/0rfzaIqWXIiJzLuspqQEATaZ/ixTBvQCMFiEsQZ2vdrERARewBc f0rztaU+wYNFRmapatSATkyz+XUee2WhjmBujZENx4SYqM1rAlAl4igaSJrtZFCZKeor 9/KujCjS9fWTwlQ2Q6+Bmt5VpC/QJwTNPXcfjodVRYyBIr1s+uNdGkTZ9xMjyZs2hvsT H+yzzLDMucpI0O+Vm0z9wyiAD49FIX8wG0gYUgYCc/a+t6xNN0Y72QslNuISF99t0mSf Aj0A== X-Gm-Message-State: APt69E17NZVcvWD7F8K5n8/wsgMILJNRZiY5fHCLf2wPhxEOlOUPPs4v 5BYCoqebD5ng8b3yvvZV1UQl/ZIHqHg= X-Google-Smtp-Source: AAOMgpclZ4p73A9rNjas1Josy1ACpigAnAkwYywiCG8qPrk7fNQO6ykq4cvgRJM8jCXE8YFF1I3E/w== X-Received: by 2002:a1c:ce0a:: with SMTP id e10-v6mr11959995wmg.135.1531162647007; Mon, 09 Jul 2018 11:57:27 -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 l10-v6sm23239053wrv.23.2018.07.09.11.57.25 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Jul 2018 11:57:26 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Mon, 9 Jul 2018 20:57:15 +0200 Message-Id: <20180709185723.11349-2-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180709185723.11349-1-jkbs@redhat.com> References: <20180709185723.11349-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] [RFC PATCH 1/9] 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 1181cdfba..66af948de 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; } } From patchwork Mon Jul 9 18:57:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 941564 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 41PZNY4yg3z9s0W for ; Tue, 10 Jul 2018 04:58:21 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 7E3FFF56; Mon, 9 Jul 2018 18:57:32 +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 04B59F4B for ; Mon, 9 Jul 2018 18:57:31 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 7AF83E2 for ; Mon, 9 Jul 2018 18:57:30 +0000 (UTC) Received: by mail-wr1-f51.google.com with SMTP id t6-v6so12055174wrn.7 for ; Mon, 09 Jul 2018 11:57:30 -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=soh5eJuBP0VpRjJNZyrEXer6QFHxlODd2RiAjSDoErA=; b=IS1RejkKrtxOu4hakF77A+/pVlwLR6OeE8JKp5UBj/s5Wy8jrerv6Q0+B81a2F8nfa 9xXXuLO9FuPxWEuUYwDdCMbh49RpHtSGqzdJ6tW4TJDLHfpdwvVocNccSexpie8/vWhN cbVx98DT5ed/z/ob8LwMKUHjk69PPkdsrin1zR4o+022VhsptGZuTjDkv5zwj2bXkV2/ FwtNW74Pim2fRzfhoBIfj93h8P6ciblIimOmPUxhMpwQ/6AjxUciCJssJEJDVA+EKslg MMaK4jkBrAjsxnkvRZyjwaFonvANQUS7/IbsNiidzndODBNNk5th46yj2w5+bBKm+7qU H58g== X-Gm-Message-State: AOUpUlEGO6we0OhEbFDAt7NuDPPHd4ln0W0X6iHx8J175WUwof/ukiv7 iiIykTC3YrBuftgEFYqAoMQIqtUhmoU= X-Google-Smtp-Source: AAOMgpeRYD4CTeX6lfKYH4FVHqGdgwHTOvVOcm3mhy6W2IqWIJP0HHPRSybZj9J5bobexXXrdUZ1ig== X-Received: by 2002:adf:b60a:: with SMTP id f10-v6mr8897645wre.54.1531162648949; Mon, 09 Jul 2018 11:57:28 -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 73-v6sm1084237wmu.37.2018.07.09.11.57.27 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Jul 2018 11:57:28 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Mon, 9 Jul 2018 20:57:16 +0200 Message-Id: <20180709185723.11349-3-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180709185723.11349-1-jkbs@redhat.com> References: <20180709185723.11349-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] [RFC PATCH 2/9] ovn-nbctl: Pull up destroying commands 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 Destroy commands in the same routine where they were allocated. Preparatory work for reusing the main loop in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 66af948de..d7784dff1 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -126,6 +126,13 @@ main(int argc, char *argv[]) main_loop(args, commands, n_commands, idl); + for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { + ds_destroy(&c->output); + table_destroy(c->table); + free(c->table); + shash_destroy_free_data(&c->options); + } + free(commands); free(args); exit(EXIT_SUCCESS); } @@ -4277,13 +4284,7 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, } else { fputs(ds_cstr(ds), stdout); } - ds_destroy(&c->output); - table_destroy(c->table); - free(c->table); - - shash_destroy_free_data(&c->options); } - free(commands); if (wait_type != NBCTL_WAIT_NONE && status != TXN_UNCHANGED) { ovsdb_idl_enable_reconnect(idl); From patchwork Mon Jul 9 18:57:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 941565 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 41PZP6145Mz9s0W for ; Tue, 10 Jul 2018 04:58:50 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 23F35F6C; Mon, 9 Jul 2018 18:57:34 +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 AB834F49 for ; Mon, 9 Jul 2018 18:57:32 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2EBCF6B7 for ; Mon, 9 Jul 2018 18:57:32 +0000 (UTC) Received: by mail-wr1-f44.google.com with SMTP id h10-v6so12039812wre.6 for ; Mon, 09 Jul 2018 11:57:32 -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=OfjZ1MlX38kPpmzB1LDmkP23kq6j+tR0NuHch20f6+8=; b=DpXOyNY5CTiNvuJvtAabfuBzNDEny9yLqernenqUl/z4DJgLZVQfGX68XUS5UBYg5J YPwOOL+YxwZRRyQHnaR3LYbrrREa4wvV+USImjcAjJ6FRaeKPu8CLfsA0t7UhAeZsYz5 Krl7LyENoqgdkrZWT8VpiWhz/ZdCMzXeImY0rf5t/DxXUYM3vJMufdh2C6i20Zsj1GVK rLbo9u4qQjD6wiK0/gbz+cDmE+L9KidbXPAreJRGQJ4ZS9Ofh1SY5bn+EdKZIxUBd+Xv SLRl7ArFOk/KyznRCSIlWZX/U3GV2JN3vMbri0eRP0uaLHKlPOk5JxkdhVmMwCagET1Y JCcw== X-Gm-Message-State: APt69E22po2w/0jP4T53ZLbowbahSl7FrTci1NYiOkJ2E0GSwsxvDAsD BV/KNlevC0Uk0l6GcPHyVZBRmd3PEMM= X-Google-Smtp-Source: AAOMgpd5KFQjdI/7AJVJ6fpqeKGyuxjLuoV9TXu0flaZ/UO9Q2jqegFC9wuBdUyO1wQfPbM+x+qffw== X-Received: by 2002:a5d:67c6:: with SMTP id n6-v6mr14970547wrw.39.1531162650657; Mon, 09 Jul 2018 11:57:30 -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 185-v6sm30210485wmw.23.2018.07.09.11.57.29 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Jul 2018 11:57:30 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Mon, 9 Jul 2018 20:57:17 +0200 Message-Id: <20180709185723.11349-4-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180709185723.11349-1-jkbs@redhat.com> References: <20180709185723.11349-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] [RFC PATCH 3/9] ovn-nbctl: Pull up releasing IDL 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 Destroy IDL resources in the routine where we allocated them. Preparatory work for reusing the main loop in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index d7784dff1..f1fe594ea 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -126,6 +126,9 @@ main(int argc, char *argv[]) main_loop(args, commands, n_commands, idl); + ovsdb_idl_destroy(idl); + idl = the_idl = NULL; + for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { ds_destroy(&c->output); table_destroy(c->table); @@ -4305,7 +4308,6 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, } ovsdb_idl_txn_destroy(txn); - ovsdb_idl_destroy(idl); return true; From patchwork Mon Jul 9 18:57:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 941566 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 41PZPf0Vbzz9s1R for ; Tue, 10 Jul 2018 04:59:18 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id AE44CF6A; Mon, 9 Jul 2018 18:57:34 +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 1BB28F5A for ; Mon, 9 Jul 2018 18:57:34 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 8404D6B7 for ; Mon, 9 Jul 2018 18:57:33 +0000 (UTC) Received: by mail-wr1-f54.google.com with SMTP id t6-v6so12055320wrn.7 for ; Mon, 09 Jul 2018 11:57: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=iuuVeg/XH/M0tai1kyvUFqo0Sj4/1VHBc7Zdz2pR+NQ=; b=MSCAuy10twhPNCqh4MuWzYFhd7DxaWg3DKQb1x+rjPsVXcCh2r1H/Hga12waWcxBdD P/k9oD1rr3OHlzlM3ndr0uUsnA/CBj70L2E8dYfXqDfp8Od2ZK6Xv+k1Q/3pQiIDKrX8 8Qh6gJTQqSpAScu1nM+X3aOtgR0737GOlMLmthdl8YiAEAorVCo6D/Rzu/j1keESmeIw hIgomw1jxbzOv4U+gGJFQXrVnq7Yvaleur4G8cr3pnibX6tv45fpvRasoP+uajTUIGFD 6m2281FmOcIuiPu8P/eShFyfrKjTc6XAEGTwFTE8BNpfe8YohK9BIpDTNjbV7k+ESEfj 3Cbg== X-Gm-Message-State: AOUpUlH7b2HzSqcAWZ0U1klX9j9Ynk0bIF1R8yDvs1hZeiQrnh4+3zMF OYJ9x0RGLZs48wTJZBR2ss6/YwZiSLw= X-Google-Smtp-Source: AAOMgpccR3RZVztSShD046jfli1L9P6xI7ZDmu2c1TlsPTXA9tA4K4pKUYH8ABFNdzKNY2aue1CBEQ== X-Received: by 2002:adf:98d2:: with SMTP id w76-v6mr4456739wrb.124.1531162651975; Mon, 09 Jul 2018 11:57:31 -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 u6-v6sm14286798wmu.5.2018.07.09.11.57.31 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Jul 2018 11:57:31 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Mon, 9 Jul 2018 20:57:18 +0200 Message-Id: <20180709185723.11349-5-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180709185723.11349-1-jkbs@redhat.com> References: <20180709185723.11349-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] [RFC PATCH 4/9] ovn-nbctl: Signal need to try again via an output param. 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 Introduce an output parameter for the flag that signals need to retry running the command. This leaves the return value for error reporting. Preparatory work for reusing the main loop in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index f1fe594ea..b5de2c305 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -84,8 +84,8 @@ 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 bool do_nbctl(const char *args, struct ctl_command *, size_t n, - struct ovsdb_idl *); +static void 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, @@ -164,7 +164,10 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, if (seqno != ovsdb_idl_get_seqno(idl)) { seqno = ovsdb_idl_get_seqno(idl); - if (do_nbctl(args, commands, n_commands, idl)) { + + bool retry; + do_nbctl(args, commands, n_commands, idl, &retry); + if (!retry) { return; } } @@ -4137,9 +4140,9 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, } } -static bool +static void do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, - struct ovsdb_idl *idl) + struct ovsdb_idl *idl, bool *retry) { struct ovsdb_idl_txn *txn; enum ovsdb_idl_txn_status status; @@ -4150,6 +4153,8 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, int64_t next_cfg = 0; char *error = NULL; + ovs_assert(retry); + txn = the_idl_txn = ovsdb_idl_txn_create(idl); if (dry_run) { ovsdb_idl_txn_set_dry_run(txn); @@ -4309,7 +4314,8 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, ovsdb_idl_txn_destroy(txn); - return true; + *retry = false; + return; try_again: /* Our transaction needs to be rerun, or a prerequisite was not met. Free @@ -4325,7 +4331,8 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, free(c->table); } free(error); - return false; + *retry = true; + return; } /* Frees the current transaction and the underlying IDL and then calls From patchwork Mon Jul 9 18:57:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 941570 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 41PZQB6nVCz9s1R for ; Tue, 10 Jul 2018 04:59:46 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 7E9B3F7E; Mon, 9 Jul 2018 18:57:37 +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 14F0DF77 for ; Mon, 9 Jul 2018 18:57:36 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 95B55E2 for ; Mon, 9 Jul 2018 18:57:35 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id z6-v6so11686269wma.0 for ; Mon, 09 Jul 2018 11:57: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:subject:date:message-id:in-reply-to :references; bh=wBI3vrY8k9lCcRI8TnhocUu66Ux2CXsh4EX8Zi0xri4=; b=ihCUsmGKGdR3tqi9DRd4DPLQfzCoUfzC2HMPAxntGeGabh9jqoHwdMn1z4QeIME9Mb otGfSf2SICAQ1tzC7ka5ouLSMkCnJIgXtXYc1NDI6ENtA67o1ZOCr+nkhFqpPqNNRULy wE0Eqebx9nw6JPOhJW/nya8STt42DeZlAYxQxO+PGuA7pdYYvMEOzqDIpT6LBK07HXf4 eu7laH006qnEg0my0UmePbprkUwAQ/DwH3TgJTzjIi1nKJRmgqxUzhMIPOJwrt70BjEa 3ZY8Er0z4N0Wtrb5PIXU14Nyu66mrqsDLokxpx9O1Nv0wPut5L80uXSxKrC8zxyS74AA i5Zg== X-Gm-Message-State: APt69E1ovytkXj30fXDySkRiUZg3vn+JpMzBwOBS3aWscpjQxLqTdI7W 8l8FCEXE7t0qgTW48A2D0Z6y70NtoGw= X-Google-Smtp-Source: AAOMgpcLh2MEHdkwk6l+KLs7IxNk9m9N3MhVrlaqVvYY6kX05h5yWh6f/ob703SgJW4BG0E+Ju/9mA== X-Received: by 2002:a1c:9809:: with SMTP id a9-v6mr8241326wme.15.1531162654051; Mon, 09 Jul 2018 11:57: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 131-v6sm29400059wmm.31.2018.07.09.11.57.32 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Jul 2018 11:57:33 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Mon, 9 Jul 2018 20:57:19 +0200 Message-Id: <20180709185723.11349-6-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180709185723.11349-1-jkbs@redhat.com> References: <20180709185723.11349-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] [RFC PATCH 5/9] ovn-nbctl: Don't dup the error message just to report it. 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 Get rid of a pointless copy operation. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index b5de2c305..511068973 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -4151,7 +4151,6 @@ 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); @@ -4232,7 +4231,6 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, } } } - error = xstrdup(ovsdb_idl_txn_get_error(txn)); switch (status) { case TXN_UNCOMMITTED: @@ -4251,7 +4249,7 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, goto try_again; case TXN_ERROR: - ctl_fatal("transaction error: %s", error); + ctl_fatal("transaction error: %s", ovsdb_idl_txn_get_error(txn)); case TXN_NOT_LOCKED: /* Should not happen--we never call ovsdb_idl_set_lock(). */ @@ -4260,7 +4258,6 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, default: OVS_NOT_REACHED(); } - free(error); ovsdb_symbol_table_destroy(symtab); @@ -4330,7 +4327,6 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, table_destroy(c->table); free(c->table); } - free(error); *retry = true; return; } From patchwork Mon Jul 9 18:57:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 941571 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 41PZQc4gpJz9s0W for ; Tue, 10 Jul 2018 05:00:08 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 41FDCF87; Mon, 9 Jul 2018 18:57:39 +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 59037F87 for ; Mon, 9 Jul 2018 18:57:38 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 83266778 for ; Mon, 9 Jul 2018 18:57:37 +0000 (UTC) Received: by mail-wm0-f42.google.com with SMTP id i139-v6so22058195wmf.4 for ; Mon, 09 Jul 2018 11:57:37 -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=SHBaBdOoV601HgDteXNsrXUcJbXkwTY0AKUsd5GAK+4=; b=i7F7cTzalsPy1abFun4X2JBe6XWKTPjjt5AHlzE8mykXgII13skDj4/rz/0LEMsR/x u55vDaK0/ceIVViomzs713YwnlEZlUDm7Og7PuXcCISCrY1mJeEW5hjUJSEGV9nVfgU0 E+0UB2R8Odysdu9YpRDls3+yloFBHDUlFOuHUcIVo7n0YWGVMcxKfHa8AHUXwMB/33Dh Tl6ETTw9fzQDqmPL/9g44AeUFNWFFfcYgJqa2AOGkDa6oVslujynGWn5b092OjiNX460 VzbsA5Uw60/d7YpngUNZ8L9QtCx15Khy8kA2/OldTcR6T3vQ1Lj6ZRKP8XJYPVCyTaUl glsQ== X-Gm-Message-State: APt69E2MoQuEDkkv7gcn6dJWogAjAD/nw/bAMEl/j3WiKjXATd/aVv1F +ibQFMf/dLaxiTzbTeeuCpV1T5x29Ws= X-Google-Smtp-Source: AAOMgpce5DtJkXmhiM7deldEkws1eWKyphxiMHYbPEt70TgSeRvQZb5p/uvQWtxeyBLRN4pnMxVzsg== X-Received: by 2002:a1c:e409:: with SMTP id b9-v6mr12057920wmh.34.1531162655902; Mon, 09 Jul 2018 11:57:35 -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 m17-v6sm23491226wrg.65.2018.07.09.11.57.34 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Jul 2018 11:57:35 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Mon, 9 Jul 2018 20:57:20 +0200 Message-Id: <20180709185723.11349-7-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180709185723.11349-1-jkbs@redhat.com> References: <20180709185723.11349-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] [RFC PATCH 6/9] 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, 31 insertions(+), 15 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 511068973..2caced626 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; } @@ -4140,7 +4144,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) { @@ -4151,6 +4155,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); @@ -4184,7 +4189,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); @@ -4198,9 +4205,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) { @@ -4225,7 +4233,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); } @@ -4239,7 +4249,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: @@ -4249,11 +4260,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(); @@ -4312,11 +4326,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; @@ -4327,8 +4344,7 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, table_destroy(c->table); free(c->table); } - *retry = true; - return; + return error; } /* Frees the current transaction and the underlying IDL and then calls From patchwork Mon Jul 9 18:57:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 941572 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 41PZR52Vm5z9s0W for ; Tue, 10 Jul 2018 05:00:33 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id CC90FF77; Mon, 9 Jul 2018 18:57:41 +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 26807F85 for ; Mon, 9 Jul 2018 18:57:40 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 9AA476B7 for ; Mon, 9 Jul 2018 18:57:39 +0000 (UTC) Received: by mail-wr1-f47.google.com with SMTP id t6-v6so12055583wrn.7 for ; Mon, 09 Jul 2018 11:57:39 -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=tfZ4HZ2+N772SwRD555zQzGViNRsIAtzR+iEoe9Ccpo=; b=B0jSUNNRS/yMGd2VFx2cJOrawXANgd+Y2ZMRkluWYhA6UnJFNdLyLR/UWHkpflEz6m da1YvRjxp0PcN6/eS17TjKgwYNU8WIZWTdqSCpAVCuxRrBVK2wYMepohKuWN89H6Gqii d84RRDbMpF53tx4yodulb+eRBS6i72XhW1NFyIhFed/93dENkeHy8ffaeWdwVmNX4IuH BXy2FQsYgahEPsd2B7y8K/8E/twrfTF98wUvCurD4bdtG+btPY11lycz00pQzF0W6sQ7 UbIxywib+d5fJaGdE9poJddgifOZtc33QrbzIRuLsLxVDLGdz7jXJXX5xzHzDa4+GFd3 lahw== X-Gm-Message-State: APt69E3R/uResdxeuzc1yJt1RAkBn/9hFET9wYqkgxUnO2QRHN6ECfGV E0N1wIMKg9n+erqlqNVP4H9Zlci3M1o= X-Google-Smtp-Source: AAOMgpdTfZstN2Lnw8yBAKDB58/uyGJq3V5PMJXsNefDDVIxBMtX7pnvx0gbtFFefXPLr4AvNxIfXA== X-Received: by 2002:adf:9582:: with SMTP id p2-v6mr15106636wrp.252.1531162658047; Mon, 09 Jul 2018 11:57:38 -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 m144-v6sm17179063wma.36.2018.07.09.11.57.36 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Jul 2018 11:57:37 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Mon, 9 Jul 2018 20:57:21 +0200 Message-Id: <20180709185723.11349-8-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180709185723.11349-1-jkbs@redhat.com> References: <20180709185723.11349-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] [RFC PATCH 7/9] ovn-nbctl: Propagate errors from 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 Let the caller handle the errors instead of reporting it and terminating. Prepare for reusing the main loop in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 2caced626..b709f0d85 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -89,8 +89,10 @@ static char * OVS_WARN_UNUSED_RESULT do_nbctl(const char *args, 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, - size_t n_commands, struct ovsdb_idl *idl); +static char * OVS_WARN_UNUSED_RESULT main_loop(const char *args, struct + ctl_command *commands, + size_t n_commands, + struct ovsdb_idl *idl); int main(int argc, char *argv[]) @@ -125,7 +127,10 @@ 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); + char *error = main_loop(args, commands, n_commands, idl); + if (error) { + ctl_fatal("%s", error); + } ovsdb_idl_destroy(idl); idl = the_idl = NULL; @@ -141,7 +146,7 @@ main(int argc, char *argv[]) exit(EXIT_SUCCESS); } -static void +static char * main_loop(const char *args, struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl) { @@ -169,10 +174,10 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, bool retry; char *error = do_nbctl(args, commands, n_commands, idl, &retry); if (error) { - ctl_fatal("%s", error); + return error; } if (!retry) { - return; + return NULL; } } @@ -181,6 +186,8 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, poll_block(); } } + + return NULL; } static void From patchwork Mon Jul 9 18:57:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 941573 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 41PZRZ43vYz9s0W for ; Tue, 10 Jul 2018 05:00:58 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 9ACF6F9B; Mon, 9 Jul 2018 18:57:44 +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 02E36F8F for ; Mon, 9 Jul 2018 18:57:43 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C9BFDE2 for ; Mon, 9 Jul 2018 18:57:41 +0000 (UTC) Received: by mail-wr1-f41.google.com with SMTP id p1-v6so12047835wrs.9 for ; Mon, 09 Jul 2018 11:57:41 -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=RTUlFf5aBdpFWmlebbHXVc6u896sgCN+J5zQnL6RLg4=; b=ZgO7I2hR9SMVB35LFPd1R96/ZG3So6CnznvsFJx6VlhLmh6eSLnd8IuP82Kw+UsWgZ 5E+TzdssN9weF24HKHEw1z7HvJx60cp+prKlL/xZIOzWEaEWOqZTmPPgORw/oWa0qmYU Gbo7dMUqpw8mJ0ofmZin3frMQK1haCekT+9VtcOLDlG8nOJ56Oujg448O1x5MvGrUMIx wnOub3mLU4QE01u8zV7upmf9jE+gbvPdjYyuI0Ik8x8Bc5BPlPZQoSvw7VorPFuuilHC +vqc9/Gw87YDaJ1HKkoBqtt7l8hdsLTl8jUcqIEgeETVPGK5eQo4BjXmcg5hIEWqKBhJ zG/A== X-Gm-Message-State: AOUpUlHVGdtT8dcXSQ1jmkkf21vxZ589rfHlUoX/NU1BykYn/bmdQVUC D4YFheZf1IGcOszHViDwzHoSHHmHQ9Q= X-Google-Smtp-Source: AAOMgpfA9trdmCQa7qkWUTi4/qkrP6uu6zqayIXoJdQKv20/L/FXbwp74gTwfcnH4Y0/JxAko5tJ9g== X-Received: by 2002:adf:ee4e:: with SMTP id w14-v6mr2446321wro.63.1531162660068; Mon, 09 Jul 2018 11:57:40 -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 q8-v6sm30668953wmb.3.2018.07.09.11.57.38 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Jul 2018 11:57:39 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Mon, 9 Jul 2018 20:57:22 +0200 Message-Id: <20180709185723.11349-9-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180709185723.11349-1-jkbs@redhat.com> References: <20180709185723.11349-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] [RFC PATCH 8/9] ovn-nbctl: Initial support for daemon mode. 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 Make ovn-nbctl act as a unixctl server if we were asked to detach. This turns ovn-nbctl into a long-lived process that acts a proxy for interacting with NB DB. The main difference to regular mode of ovn-nbctl is that in the daemon mode, a local copy of database contents has to be obtained only once. Just two unixctl commands are supported 'run' and 'exit'. The former can be used to run any ovn-nbctl command or a batch of them as so: ovs-appctl -t ovn-nbctl run [OPTIONS] COMMAND [-- [OPTIONS] COMMAND] ... Commands that use tabular output ('find' and 'list') are not supported. As are --dry-run, --timeout, and --wait ovn-nbctl options. Also, running commands that have not yet been converted to not use ctl_fatal() will result in death of the daemon process. However, --monitor option can be used to keep the daemon running. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 180 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 158 insertions(+), 22 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index b709f0d85..0c0102c49 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -20,6 +20,7 @@ #include #include "command-line.h" +#include "daemon.h" #include "db-ctl-base.h" #include "dirs.h" #include "fatal-signal.h" @@ -37,6 +38,7 @@ #include "svec.h" #include "table.h" #include "timeval.h" +#include "unixctl.h" #include "util.h" #include "openvswitch/vlog.h" @@ -79,6 +81,13 @@ OVS_NO_RETURN static void nbctl_exit(int status); /* --leader-only, --no-leader-only: Only accept the leader in a cluster. */ static int leader_only = true; +/* --unixctl-path: Path to use for unixctl server, for "monitor" and "snoop" + commands. */ +static char *unixctl_path; + +static unixctl_cb_func server_cmd_exit; +static unixctl_cb_func server_cmd_run; + static void nbctl_cmd_init(void); OVS_NO_RETURN static void usage(void); static void parse_options(int argc, char *argv[], struct shash *local_options); @@ -93,14 +102,13 @@ static char * OVS_WARN_UNUSED_RESULT main_loop(const char *args, struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl); +static void server_loop(struct ovsdb_idl *idl); int main(int argc, char *argv[]) { struct ovsdb_idl *idl; - struct ctl_command *commands; struct shash local_options; - size_t n_commands; set_program_name(argv[0]); fatal_ignore_sigpipe(); @@ -113,35 +121,51 @@ main(int argc, char *argv[]) char *args = process_escape_args(argv); shash_init(&local_options); parse_options(argc, argv, &local_options); - commands = ctl_parse_commands(argc - optind, argv + optind, &local_options, - &n_commands); - VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG, - "Called as %s", args); - - if (timeout) { - time_alarm(timeout); - } + argc -= optind; + argv += optind; /* Initialize IDL. */ idl = the_idl = ovsdb_idl_create(db, &nbrec_idl_class, true, false); ovsdb_idl_set_leader_only(idl, leader_only); - run_prerequisites(commands, n_commands, idl); - char *error = main_loop(args, commands, n_commands, idl); - if (error) { - ctl_fatal("%s", error); + if (get_detach()) { + if (argc != 0) { + ctl_fatal("non-option arguments not supported with --detach " + "(use --help for help)"); + } + server_loop(idl); + } else { + struct ctl_command *commands; + size_t n_commands; + + commands = ctl_parse_commands(argc, argv, &local_options, &n_commands); + VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG, + "Called as %s", args); + + if (timeout) { + time_alarm(timeout); + } + + run_prerequisites(commands, n_commands, idl); + + char *error = main_loop(args, commands, n_commands, idl); + if (error) { + ctl_fatal("%s", error); + } + + struct ctl_command *c; + for (c = commands; c < &commands[n_commands]; c++) { + ds_destroy(&c->output); + table_destroy(c->table); + free(c->table); + shash_destroy_free_data(&c->options); + } + free(commands); } ovsdb_idl_destroy(idl); idl = the_idl = NULL; - for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { - ds_destroy(&c->output); - table_destroy(c->table); - free(c->table); - shash_destroy_free_data(&c->options); - } - free(commands); free(args); exit(EXIT_SUCCESS); } @@ -151,6 +175,7 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl) { unsigned int seqno; + bool idl_ready; /* Execute the commands. * @@ -160,6 +185,11 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, * it's because the database changed and we need to obtain an up-to-date * view of the database before we try the transaction again. */ seqno = ovsdb_idl_get_seqno(idl); + + /* IDL might have already obtained the database copy during previous + * invocation. If so, we can't expect the sequence number to change before + * we issue any new requests. */ + idl_ready = ovsdb_idl_has_ever_connected(idl); for (;;) { ovsdb_idl_run(idl); if (!ovsdb_idl_is_alive(idl)) { @@ -168,7 +198,8 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, db, ovs_retval_to_string(retval)); } - if (seqno != ovsdb_idl_get_seqno(idl)) { + if (idl_ready || seqno != ovsdb_idl_get_seqno(idl)) { + idl_ready = false; seqno = ovsdb_idl_get_seqno(idl); bool retry; @@ -204,6 +235,7 @@ parse_options(int argc, char *argv[], struct shash *local_options) OPT_COMMANDS, OPT_OPTIONS, OPT_BOOTSTRAP_CA_CERT, + DAEMON_OPTION_ENUMS, VLOG_OPTION_ENUMS, TABLE_OPTION_ENUMS, SSL_OPTION_ENUMS, @@ -222,6 +254,7 @@ parse_options(int argc, char *argv[], struct shash *local_options) {"leader-only", no_argument, &leader_only, true}, {"no-leader-only", no_argument, &leader_only, false}, {"version", no_argument, NULL, 'V'}, + DAEMON_LONG_OPTIONS, VLOG_LONG_OPTIONS, STREAM_SSL_LONG_OPTIONS, {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT}, @@ -326,6 +359,7 @@ parse_options(int argc, char *argv[], struct shash *local_options) } break; + DAEMON_OPTION_HANDLERS VLOG_OPTION_HANDLERS TABLE_OPTION_HANDLERS(&table_style) STREAM_SSL_OPTION_HANDLERS @@ -519,6 +553,7 @@ Options:\n\ program_name, program_name, ctl_get_db_cmd_usage(), ctl_list_db_tables_usage(), default_nb_db()); table_usage(); + daemon_usage(); vlog_usage(); printf("\ --no-syslog equivalent to --verbose=nbctl:syslog:warn\n"); @@ -4529,3 +4564,104 @@ nbctl_cmd_init(void) ctl_init(&nbrec_idl_class, nbrec_table_classes, tables, NULL, nbctl_exit); ctl_register_commands(nbctl_commands); } + +static void +server_cmd_exit(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[] OVS_UNUSED, void *exiting_) +{ + bool *exiting = exiting_; + *exiting = true; + unixctl_command_reply(conn, NULL); +} + +static void +server_cmd_run(struct unixctl_conn *conn, int argc, const char **argv_, + void *idl_) +{ + struct ovsdb_idl *idl = idl_; + struct ctl_command *commands = NULL; + struct shash local_options; + size_t n_commands = 0; + char *error = NULL; + + /* Copy args so that getopt() can permute them. Leave last entry NULL. */ + char **argv = xcalloc(argc + 1, sizeof *argv); + for (int i = 0; i < argc; i++) { + argv[i] = xstrdup(argv_[i]); + } + + /* Parse commands & options. */ + char *args = process_escape_args(argv); + shash_init(&local_options); + optind = 0; + parse_options(argc, argv, &local_options); + commands = ctl_parse_commands(argc - optind, argv + optind, + &local_options, &n_commands); + VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG, + "Running command %s", args); + + /* TODO: Timeout handling. */ + error = main_loop(args, commands, n_commands, idl); + if (error) { + unixctl_command_reply_error(conn, error); + goto out; + } + + struct ds output = DS_EMPTY_INITIALIZER; + for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { + /* TODO: Support for table output. */ + ds_put_cstr(&output, ds_cstr_ro(&c->output)); + } + unixctl_command_reply(conn, ds_cstr_ro(&output)); + ds_destroy(&output); + +out: + free(error); + for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { + ds_destroy(&c->output); + table_destroy(c->table); + free(c->table); + shash_destroy_free_data(&c->options); + } + free(commands); + shash_destroy_free_data(&local_options); + free(args); + for (int i = 0; i < argc; i++) { + free(argv[i]); + } + free(argv); +} + +static void +server_cmd_init(struct ovsdb_idl *idl, bool *exiting) +{ + unixctl_command_register("exit", "", 0, 0, server_cmd_exit, exiting); + unixctl_command_register("run", "", 1, INT_MAX, server_cmd_run, idl); +} + +static void +server_loop(struct ovsdb_idl *idl) +{ + struct unixctl_server *server = NULL; + bool exiting = false; + + daemonize_start(false); + int error = unixctl_server_create(unixctl_path, &server); + if (error) { + ctl_fatal("failed to create unixctl server (%s)", + ovs_retval_to_string(error)); + } + server_cmd_init(idl, &exiting); + + for (;;) { + unixctl_server_run(server); + daemonize_complete(); + unixctl_server_wait(server); + if (exiting) { + break; + } + poll_block(); + } + + unixctl_server_destroy(server); +} From patchwork Mon Jul 9 18:57:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 941574 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 41PZS30321z9s0W for ; Tue, 10 Jul 2018 05:01:22 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 3CED4F8E; Mon, 9 Jul 2018 18:57:45 +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 A6392F97 for ; Mon, 9 Jul 2018 18:57:43 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 1B367E2 for ; Mon, 9 Jul 2018 18:57:43 +0000 (UTC) Received: by mail-wr1-f44.google.com with SMTP id r16-v6so12057516wrt.11 for ; Mon, 09 Jul 2018 11:57:42 -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=j8ZnLtwSfFVUCjiiGaYlo2VdycU4JgeNvrByVATWynk=; b=VF8/auD2IiEfuYimvOx/CvA4sT6qJe3u8AWg1W889G4ManvmKn3T1g5OLR8mV5xGG6 xpBALpG9I9+1H33qrqgPC3toQQzlglAdiuOC7wJILf9G1BV2AtKbg/hutd1jg7jfYE0i wFTK34jtyjwvszk27sOCiY9Az/mKuV2EuimeltNCrgoH1PsJ0NLK9quv31nTLanCFDnH E7gVLSaRmqwlye4ROa9KVewFOg2KRfwm52EeQRK96+A2x3wTBMgKUHlOK/1B0pqzO2oL bXVYX5/Q9vipUdsEQGllkUitliVIcNCb7g+710lld+MciX2/KIvcj+MtD/fAsy7Y8CY9 hG5g== X-Gm-Message-State: APt69E3aCdrDCqu4viILp6J+PXM7j66qh5Pl+pZYHKryW7MQHWbJw5Q4 /lRVAITvaY6f/QBYrVmJ5O5wOuCotRI= X-Google-Smtp-Source: AAOMgpcoGKvGGKiNYhQpA9Te8aOPsyximt3pS+PV2Lgh/FBpIx/t6aSlYJjsgkvWno5/RnGvjPp/0g== X-Received: by 2002:adf:b8ce:: with SMTP id c14-v6mr16350124wrg.65.1531162661563; Mon, 09 Jul 2018 11:57:41 -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 z5-v6sm9620878wrv.2.2018.07.09.11.57.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Jul 2018 11:57:40 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Mon, 9 Jul 2018 20:57:23 +0200 Message-Id: <20180709185723.11349-10-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180709185723.11349-1-jkbs@redhat.com> References: <20180709185723.11349-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] [RFC PATCH 9/9] WIP: tests: Integrate with ovn-nctl daemon mode. 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 NOTE: This patch should not be applied. It is for testing only. Switch ovn-nbctl test suite to use the ovn-nbctl daemon. Signed-off-by: Jakub Sitnicki --- tests/ovn-nbctl.at | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index 62d82287a..ee76ce0f7 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -9,6 +9,10 @@ m4_define([OVN_NBCTL_TEST_START], dnl Start ovsdb-server. AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:$OVS_RUNDIR/ovnnb_db.sock ovn-nb.db], [0], [], [stderr]) on_exit "kill `cat ovsdb-server.pid`" + + dnl Start ovn-nbctl server + start_daemon ovn-nbctl + AT_CHECK([ovn-nbctl init]) AT_CHECK([[sed < stderr ' /vlog|INFO|opened log file/d @@ -19,7 +23,32 @@ m4_define([OVN_NBCTL_TEST_START], # OVN_NBCTL_TEST_STOP m4_define([OVN_NBCTL_TEST_STOP], [AT_CHECK([check_logs "$1"]) - OVS_APP_EXIT_AND_WAIT([ovsdb-server])]) + OVS_APP_EXIT_AND_WAIT([ovsdb-server]) + OVS_APP_EXIT_AND_WAIT([ovn-nbctl]) +]) + +m4_divert_push([PREPARE_TESTS]) +[ +OVN_NBCTL_CLIENT () { + local rc=0 + + # Run ovs-appctl filtering just its stderr. + exec 3>&1 + ovs-appctl -t ovn-nbctl run "$@" 2>&1 >&3 3>&- | sed '/^ovs-appctl:/d;s/^/ovn-nbctl: /' 1>&2 3>&- + rc=$PIPESTATUS + exec 3>&- + + # Map ovs-appctl exit status to ones from ovn-nbctl + if [ $rc -eq 0 ]; then + rc=0 + else + rc=1 + fi + return $rc +} +alias ovn-nbctl='OVN_NBCTL_CLIENT' +] +m4_divert_pop([PREPARE_TESTS]) AT_SETUP([ovn-nbctl - basic switch commands])