From patchwork Fri Mar 20 09:34:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: taoyunxiang X-Patchwork-Id: 1258751 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cmss.chinamobile.com Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48kJY10hgMz9sRf for ; Fri, 20 Mar 2020 20:35:31 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 85290889FE; Fri, 20 Mar 2020 09:35:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id n2Ec-fls+yn8; Fri, 20 Mar 2020 09:35:26 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id A1546886F5; Fri, 20 Mar 2020 09:35:26 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 795E2C089E; Fri, 20 Mar 2020 09:35:26 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9A4B7C07FF for ; Fri, 20 Mar 2020 09:35:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 873B987740 for ; Fri, 20 Mar 2020 09:35:24 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id L3EPJGi2w8Ve for ; Fri, 20 Mar 2020 09:35:21 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from cmccmta1.chinamobile.com (cmccmta1.chinamobile.com [221.176.66.79]) by whitealder.osuosl.org (Postfix) with ESMTP id 156E48811A for ; Fri, 20 Mar 2020 09:35:20 +0000 (UTC) Received: from spf.mail.chinamobile.com (unknown[172.16.121.5]) by rmmx-syy-dmz-app04-12004 (RichMail) with SMTP id 2ee45e748e38cfb-41b8a; Fri, 20 Mar 2020 17:34:48 +0800 (CST) X-RM-TRANSID: 2ee45e748e38cfb-41b8a X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from yun.localdomain (unknown[112.25.154.146]) by rmsmtp-syy-appsvr03-12003 (RichMail) with SMTP id 2ee35e748e37a06-73e5c; Fri, 20 Mar 2020 17:34:47 +0800 (CST) X-RM-TRANSID: 2ee35e748e37a06-73e5c From: Tao YunXiang To: ovs-dev@openvswitch.org Date: Fri, 20 Mar 2020 17:34:33 +0800 Message-Id: <20200320093433.30928-1-taoyunxiang@cmss.chinamobile.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <7> References: <7> Cc: Liu Chang , Rong Yin , Tao YunXiang Subject: [ovs-dev] [PATCH OVN] ovn-nbctl.c: Add an optional way to delete router policy by uuid X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" We can delete router policy by specify lr and more parameters. If CMS want to delete it exactly, it must specify detailed "match" field. It's not an easy way, also maybe deleted by mistake. This change adds a way to specify lr and uuid, which is optional. You can still use the previous method to delete. usage: ovn-nbctl lr-policy-del lr0 [UUID0] Author: Tao YunXiang Co-authored-by: Liu Chang Co-authored-by: Rong Yin Signed-off-by: Tao YunXiang Signed-off-by: Liu Chang Signed-off-by: Rong Yin --- utilities/ovn-nbctl.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index e80058e61..c05d79661 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -696,7 +696,7 @@ Route commands:\n\ Policy commands:\n\ lr-policy-add ROUTER PRIORITY MATCH ACTION [NEXTHOP]\n\ add a policy to router\n\ - lr-policy-del ROUTER [PRIORITY [MATCH]]\n\ + lr-policy-del ROUTER [{PRIORITY | UUID} [MATCH]]\n\ remove policies from ROUTER\n\ lr-policy-list ROUTER print policies for ROUTER\n\ \n\ @@ -3587,21 +3587,40 @@ nbctl_lr_policy_del(struct ctl_context *ctx) return; } - error = parse_priority(ctx->argv[2], &priority); - if (error) { - ctx->error = error; - return; + const struct uuid *lr_policy_uuid = NULL; + struct uuid uuid_from_cmd; + if (uuid_from_string(&uuid_from_cmd, ctx->argv[2])) { + lr_policy_uuid = &uuid_from_cmd; + } else { + error = parse_priority(ctx->argv[2], &priority); + if (error) { + ctx->error = error; + return; + } + } - /* If match is not specified, delete all routing policies with the - * specified priority. */ + /* If uuid was specified, delete routing policy with the + * specified uuid. */ if (ctx->argc == 3) { struct nbrec_logical_router_policy **new_policies = xmemdup(lr->policies, sizeof *new_policies * lr->n_policies); int n_policies = 0; - for (int i = 0; i < lr->n_policies; i++) { - if (priority != lr->policies[i]->priority) { - new_policies[n_policies++] = lr->policies[i]; + + if (lr_policy_uuid) { + for (size_t i = 0; i < lr->n_policies; i++) { + if (!uuid_equals(lr_policy_uuid, + &(lr->policies[i]->header_.uuid))) { + new_policies[n_policies++] = lr->policies[i]; + } + } + /* If match is not specified, delete all routing policies with the + * specified priority. */ + } else { + for (int i = 0; i < lr->n_policies; i++) { + if (priority != lr->policies[i]->priority) { + new_policies[n_policies++] = lr->policies[i]; + } } } nbrec_logical_router_verify_policies(lr); @@ -6125,7 +6144,7 @@ static const struct ctl_command_syntax nbctl_commands[] = { /* Policy commands */ { "lr-policy-add", 4, 5, "ROUTER PRIORITY MATCH ACTION [NEXTHOP]", NULL, nbctl_lr_policy_add, NULL, "", RW }, - { "lr-policy-del", 1, 3, "ROUTER [PRIORITY [MATCH]]", NULL, + { "lr-policy-del", 1, 3, "ROUTER [{PRIORITY | UUID} [MATCH]]", NULL, nbctl_lr_policy_del, NULL, "", RW }, { "lr-policy-list", 1, 1, "ROUTER", NULL, nbctl_lr_policy_list, NULL, "", RO },