From patchwork Fri Apr 20 16:46:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 902050 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 40SMFP0gm4z9s1t for ; Sat, 21 Apr 2018 02:46:33 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id BFDF9D80; Fri, 20 Apr 2018 16:46: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 7A7F8D70 for ; Fri, 20 Apr 2018 16:46:29 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id BA2296D1 for ; Fri, 20 Apr 2018 16:46:28 +0000 (UTC) Received: by mail-wr0-f194.google.com with SMTP id w3-v6so24627597wrg.2 for ; Fri, 20 Apr 2018 09:46: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=z6Ca9qThEzJ5yXRc+fDPjDueBlzBPDOF/Ytv4wGgoHg=; b=Pi9s0wL4hwxJ5WeWohB+GwaSGFM7az5eLmo6unZe9v2FkPk85B3yaZ30gzS5cnguyp HAM7w5AdAN04/Kemy3VXM7DvUjDizW8c7WfzRVQYhH+HGnjrTq1fAhnQvqu9Umc/fKse 9cJIHAgisR+w+2KzviNLZggH/IJVld5frbTGjA4UTadOeu2RyaRZwzEev1CrpQ1ghYUy jwW3mFCE8kV+9Ch5wuWwpBx2CtrQk/E73l/bA8k7czTYpoXE89Xbw1TeGbhWYF3noru9 ECMyxsKm15WTiLLKIm11Cq3YgdyssoCe0j4C6kO5RwW2I5IGTcYpLesfCWnf5UB+Ufjw CxDQ== X-Gm-Message-State: ALQs6tAYUgqhULvSUcJ0fjh35MmuYX1/otZMxTTo+wukQAfpRsQzBAF/ pvKg6ssNpN+MlRuU48liPbuvGQzigqA= X-Google-Smtp-Source: AIpwx4/MCWNDkYdT5nttRBJTfX9/4XPG3D7Vf8lKwsmDSi1rKEUBiUbzR1PQ0PmggdXg0h7Hoo3ZJg== X-Received: by 2002:adf:ea4f:: with SMTP id j15-v6mr5547833wrn.4.1524242787177; Fri, 20 Apr 2018 09:46:27 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id q21-v6sm5847816wra.24.2018.04.20.09.46.26 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Apr 2018 09:46:26 -0700 (PDT) From: Lorenzo Bianconi To: dev@openvswitch.org Date: Fri, 20 Apr 2018 18:46:17 +0200 Message-Id: <612b94ad53014f10951248b91501d2d8e3441e28.1524241944.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: References: 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] OVN: show gw chassis in decreasing prio order 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 Report gateway chassis in decreasing priority order running ovn-nbctl show sub-command. Add get_ordered_gw_chassis_prio_list routine to sort gw chassis according to the configured priority Signed-off-by: Lorenzo Bianconi Acked-by: Mark Michelson --- ovn/utilities/ovn-nbctl.c | 64 +++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 5c18161fe..5d79ecbe3 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -607,6 +607,38 @@ print_alias(const struct smap *external_ids, const char *key, struct ds *s) } } +/* gateway_chassis ordering + * */ +static int +compare_chassis_prio_(const void *gc1_, const void *gc2_) +{ + const struct nbrec_gateway_chassis *const *gc1p = gc1_; + const struct nbrec_gateway_chassis *const *gc2p = gc2_; + const struct nbrec_gateway_chassis *gc1 = *gc1p; + const struct nbrec_gateway_chassis *gc2 = *gc2p; + + int prio_diff = gc2->priority - gc1->priority; + if (!prio_diff) { + return strcmp(gc2->name, gc1->name); + } + return prio_diff; +} + +static const struct nbrec_gateway_chassis ** +get_ordered_gw_chassis_prio_list(const struct nbrec_logical_router_port *lrp) +{ + const struct nbrec_gateway_chassis **gcs; + int i; + + gcs = xmalloc(sizeof *gcs * lrp->n_gateway_chassis); + for (i = 0; i < lrp->n_gateway_chassis; i++) { + gcs[i] = lrp->gateway_chassis[i]; + } + + qsort(gcs, lrp->n_gateway_chassis, sizeof *gcs, compare_chassis_prio_); + return gcs; +} + /* Given pointer to logical router, this routine prints the router * information. */ static void @@ -635,12 +667,17 @@ print_lr(const struct nbrec_logical_router *lr, struct ds *s) } if (lrp->n_gateway_chassis) { + const struct nbrec_gateway_chassis **gcs; + + gcs = get_ordered_gw_chassis_prio_list(lrp); ds_put_cstr(s, " gateway chassis: ["); for (size_t j = 0; j < lrp->n_gateway_chassis; j++) { - ds_put_format(s, "%s ", lrp->gateway_chassis[j]->chassis_name); + const struct nbrec_gateway_chassis *gc = gcs[j]; + ds_put_format(s, "%s ", gc->chassis_name); } ds_chomp(s, ' '); ds_put_cstr(s, "]\n"); + free(gcs); } } @@ -3021,23 +3058,6 @@ nbctl_lrp_del_gateway_chassis(struct ctl_context *ctx) chassis_name, ctx->argv[1]); } -/* gateway_chassis ordering - * */ -static int -compare_chassis_prio_(const void *gc1_, const void *gc2_) -{ - const struct nbrec_gateway_chassis *const *gc1p = gc1_; - const struct nbrec_gateway_chassis *const *gc2p = gc2_; - const struct nbrec_gateway_chassis *gc1 = *gc1p; - const struct nbrec_gateway_chassis *gc2 = *gc2p; - - int prio_diff = gc2->priority - gc1->priority; - if (!prio_diff) { - return strcmp(gc2->name, gc1->name); - } - return prio_diff; -} - /* Print a list of gateway chassis. */ static void nbctl_lrp_get_gateway_chassis(struct ctl_context *ctx) @@ -3048,13 +3068,7 @@ nbctl_lrp_get_gateway_chassis(struct ctl_context *ctx) size_t i; lrp = lrp_by_name_or_uuid(ctx, id, true); - - gcs = xmalloc(sizeof *gcs * lrp->n_gateway_chassis); - for (i = 0; i < lrp->n_gateway_chassis; i++) { - gcs[i] = lrp->gateway_chassis[i]; - } - - qsort(gcs, lrp->n_gateway_chassis, sizeof *gcs, compare_chassis_prio_); + gcs = get_ordered_gw_chassis_prio_list(lrp); for (i = 0; i < lrp->n_gateway_chassis; i++) { const struct nbrec_gateway_chassis *gc = gcs[i];