From patchwork Thu Jul 19 12:36:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 946269 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 41WYZf03Tjz9s3x for ; Thu, 19 Jul 2018 22:42:50 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id B7AD2CF9; Thu, 19 Jul 2018 12:36:59 +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 0CD6ACEE for ; Thu, 19 Jul 2018 12:36:58 +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 74A6578A for ; Thu, 19 Jul 2018 12:36:57 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id v14-v6so7919274wro.5 for ; Thu, 19 Jul 2018 05:36:57 -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=yV4exhdnbQDSotuX1+Pyu8IMxXj7NcpOZ+11mgCZawk=; b=PYv+tO0KtLVufIvQjJN+C17/wRI9Ukznjwyj6Y3gGMtkx/G0m4xM/EPOMexb1vQ4g1 eX6GCdCUV2b51N6rlX9gJd00vZQIwXViKlWh9XAku2+IDLIT8fStD3iXf2gu6apDrRGX ZoAxBSniMz6yp95fzzRgfz2M2MoNdf6SfT018u7R8pQMDqECLVDkLCMuvsM2y5Kx3WxL MEQ0vYZX4M9CHPpyXVYmN32ACuAyn3HfurIGiEmkxpP+UQRKPoM3wbI490GA0sKLXUpL K8LcZS0nuyetzfzxNRzG0PBxN94RUcc1FNdrpbQ2oaehoJMd/TQaPQSfgcSWSQZO5YKZ 6SLg== X-Gm-Message-State: AOUpUlGPTywrMO8oh3jYpfz/8rDS0r01aJA3h07q6SiLeags8G329DXk xF4qq47NM0zyFKR5QqauCtWNKHxklPE= X-Google-Smtp-Source: AAOMgpfuVJJ6uJ7DoOPCaENpiGOy7G9VD+di1ubxurzeryBxXwoNwqzkHmydFYFQU5QccxeVSEJGNQ== X-Received: by 2002:adf:e642:: with SMTP id b2-v6mr7881105wrn.254.1532003815894; Thu, 19 Jul 2018 05:36:55 -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 s16-v6sm5806324wrq.20.2018.07.19.05.36.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jul 2018 05:36:55 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Thu, 19 Jul 2018 14:36:24 +0200 Message-Id: <20180719123632.19617-14-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180719123632.19617-1-jkbs@redhat.com> References: <20180719123632.19617-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 v4 13/21] ovn-nbctl: Introduce a poll_timer based wait timeout. 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 Extend the main loop and the command runner so that the caller can specify a timeout for poll_block(). This will allow us to break out of the main loop when waiting on IDL, like in the blocked '--wait=sb/hv sync' case. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index ecb351a80..00b75aa6c 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -37,6 +37,7 @@ #include "svec.h" #include "table.h" #include "timeval.h" +#include "timer.h" #include "util.h" #include "openvswitch/vlog.h" @@ -87,13 +88,16 @@ static char * OVS_WARN_UNUSED_RESULT run_prerequisites(struct ctl_command[], struct ovsdb_idl *); static char * OVS_WARN_UNUSED_RESULT do_nbctl(const char *args, struct ctl_command *, size_t n, - struct ovsdb_idl *, bool *retry); + struct ovsdb_idl *, + const struct timer *, + bool *retry); static const struct nbrec_dhcp_options *dhcp_options_get( struct ctl_context *ctx, const char *id, bool must_exist); static char * OVS_WARN_UNUSED_RESULT main_loop(const char *args, struct ctl_command *commands, size_t n_commands, - struct ovsdb_idl *idl); + struct ovsdb_idl *idl, + const struct timer *); int main(int argc, char *argv[]) @@ -135,7 +139,7 @@ main(int argc, char *argv[]) ctl_fatal("%s", error); } - error = main_loop(args, commands, n_commands, idl); + error = main_loop(args, commands, n_commands, idl, NULL); if (error) { ctl_fatal("%s", error); } @@ -156,7 +160,7 @@ main(int argc, char *argv[]) static char * main_loop(const char *args, struct ctl_command *commands, size_t n_commands, - struct ovsdb_idl *idl) + struct ovsdb_idl *idl, const struct timer *wait_timeout) { unsigned int seqno; @@ -180,7 +184,8 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, seqno = ovsdb_idl_get_seqno(idl); bool retry; - char *error = do_nbctl(args, commands, n_commands, idl, &retry); + char *error = do_nbctl(args, commands, n_commands, idl, + wait_timeout, &retry); if (error) { return error; } @@ -4162,7 +4167,7 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, static char * do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, - struct ovsdb_idl *idl, bool *retry) + struct ovsdb_idl *idl, const struct timer *wait_timeout, bool *retry) { struct ovsdb_idl_txn *txn; enum ovsdb_idl_txn_status status; @@ -4289,8 +4294,6 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, OVS_NOT_REACHED(); } - ovsdb_symbol_table_destroy(symtab); - for (c = commands; c < &commands[n_commands]; c++) { struct ds *ds = &c->output; @@ -4334,11 +4337,19 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, } } ovsdb_idl_wait(idl); + if (wait_timeout) { + timer_wait(wait_timeout); + } poll_block(); + if (wait_timeout && timer_expired(wait_timeout)) { + error = xstrdup("timeout expired"); + goto out_error; + } } done: ; } + ovsdb_symbol_table_destroy(symtab); ovsdb_idl_txn_destroy(txn); the_idl_txn = NULL;