From patchwork Tue Nov 26 07:57:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: taoyunxiang X-Patchwork-Id: 1200792 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.136; helo=silver.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 silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Mc2C4pznz9sP3 for ; Tue, 26 Nov 2019 19:07:15 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 668EF2156C; Tue, 26 Nov 2019 08:07:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6xOuZ9uMWWJF; Tue, 26 Nov 2019 08:07:11 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 714432001C; Tue, 26 Nov 2019 08:07:11 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5E591C0878; Tue, 26 Nov 2019 08:07:11 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 78871C0880 for ; Tue, 26 Nov 2019 08:07:09 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 646A0204D2 for ; Tue, 26 Nov 2019 08:07:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TAF2jnppJHXt for ; Tue, 26 Nov 2019 08:07:07 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from cmccmta2.chinamobile.com (cmccmta2.chinamobile.com [221.176.66.80]) by silver.osuosl.org (Postfix) with ESMTP id 39C8E20110 for ; Tue, 26 Nov 2019 08:07:06 +0000 (UTC) Received: from spf.mail.chinamobile.com (unknown[172.16.121.3]) by rmmx-syy-dmz-app06-12006 (RichMail) with SMTP id 2ee65ddcdaea669-ebd92; Tue, 26 Nov 2019 15:57:30 +0800 (CST) X-RM-TRANSID: 2ee65ddcdaea669-ebd92 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from Yun (unknown[112.25.154.148]) by rmsmtp-syy-appsvr02-12002 (RichMail) with SMTP id 2ee25ddcdae808b-87f95; Tue, 26 Nov 2019 15:57:30 +0800 (CST) X-RM-TRANSID: 2ee25ddcdae808b-87f95 Date: Tue, 26 Nov 2019 15:57:29 +0800 From: "taoyunxiang@cmss.chinamobile.com" To: ovs-dev X-Priority: 3 X-GUID: 7E2A2FF9-BDEF-4586-A544-AF28B30EC223 X-Has-Attach: no X-Mailer: Foxmail 7.2.13.365[cn] Mime-Version: 1.0 Message-ID: <2019112615572930099726@cmss.chinamobile.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [ovs-dev] [ovs-dev, ovn, 1/2] ovn-nbctl.c: Add "name" column of QoS table. 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: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add "name" column of QoS table Add "name" column of QoS table and make qos could be list by command "ovn-nbctl list qos "name"". Signed-off-by: Yunxiang Tao taoyunxiang@cmss.chinamobile.com Signed-off-by: Yunxiang Tao diff --git a/ovn-nb.ovsschema b/ovn-nb.ovsschema index 12999a466..02ae48e73 100644 --- a/ovn-nb.ovsschema +++ b/ovn-nb.ovsschema @@ -1,7 +1,7 @@ { "name": "OVN_Northbound", "version": "5.18.0", - "cksum": "2806349485 24196", + "cksum": "80177565 24240", "tables": { "NB_Global": { "columns": { @@ -204,6 +204,7 @@ "isRoot": false}, "QoS": { "columns": { + "name": {"type": "string"}, "priority": {"type": {"key": {"type": "integer", "minInteger": 0, "maxInteger": 32767}}}, diff --git a/ovn-nb.xml b/ovn-nb.xml index 4a93d2f4a..61e77397e 100644 --- a/ovn-nb.xml +++ b/ovn-nb.xml @@ -1662,6 +1662,12 @@

+ +

+ A name for the logical router. +

+
+

The value of this field is similar to X-Patchwork-Id: 1200791 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.137; helo=fraxinus.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 fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Mc2C0vbQz9s3Z for ; Tue, 26 Nov 2019 19:07:15 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 6B7B985D37; Tue, 26 Nov 2019 08:07:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l6ZI1xvcILR8; Tue, 26 Nov 2019 08:07:12 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2852785C67; Tue, 26 Nov 2019 08:07:12 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 08102C1DDB; Tue, 26 Nov 2019 08:07:12 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1061BC0880 for ; Tue, 26 Nov 2019 08:07:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id EFB1920110 for ; Tue, 26 Nov 2019 08:07:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Y7SkyrEazJTd for ; Tue, 26 Nov 2019 08:07:07 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from cmccmta2.chinamobile.com (cmccmta2.chinamobile.com [221.176.66.80]) by silver.osuosl.org (Postfix) with ESMTP id BC7532001C for ; Tue, 26 Nov 2019 08:07:06 +0000 (UTC) Received: from spf.mail.chinamobile.com (unknown[172.16.121.19]) by rmmx-syy-dmz-app08-12008 (RichMail) with SMTP id 2ee85ddcdaf06f4-ebea5; Tue, 26 Nov 2019 15:57:36 +0800 (CST) X-RM-TRANSID: 2ee85ddcdaf06f4-ebea5 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from Yun (unknown[112.25.154.148]) by rmsmtp-syy-appsvr10-12010 (RichMail) with SMTP id 2eea5ddcdaefca1-86588; Tue, 26 Nov 2019 15:57:36 +0800 (CST) X-RM-TRANSID: 2eea5ddcdaefca1-86588 Date: Tue, 26 Nov 2019 15:57:36 +0800 From: "taoyunxiang@cmss.chinamobile.com" To: ovs-dev X-Priority: 3 X-GUID: F05295CC-6BDA-4DD9-93AB-035CA806D100 X-Has-Attach: no X-Mailer: Foxmail 7.2.13.365[cn] Mime-Version: 1.0 Message-ID: <2019112615573569275427@cmss.chinamobile.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [ovs-dev] [ovs-dev, ovn, 2/2] ovn-nbctl.c: Add a way to delete QoS by its name or 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: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add a way to delete QoS by its name or uuid Currently, qos can only be deleted by indirect way which must designate switch or more parameters. This patch change the original "qos-del" to "ls-qos-del", and add a new "qos-del" command. By the new command, you can delete qos by uuid or name of the qos. It is very import to support a way to delete a table by direct way. For example, we can associate the qos table in neutron and OVN by "name" of qos in OVN, so neutron could find and easily delete the corresponding qos in OVN. Signed-off-by: Yunxiang Tao taoyunxiang@cmss.chinamobile.com Signed-off-by: Yunxiang Tao diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index 93e37d169..f1d64208d 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -604,8 +604,9 @@ ACL commands:\n\ QoS commands:\n\ qos-add SWITCH DIRECTION PRIORITY MATCH [rate=RATE [burst=BURST]] [dscp=DSCP]\n\ add an QoS rule to SWITCH\n\ - qos-del SWITCH [DIRECTION [PRIORITY MATCH]]\n\ + ls-qos-del SWITCH [DIRECTION [PRIORITY MATCH]]\n\ remove QoS rules from SWITCH\n\ + qos-del QOS remove QoS rules by name or UUID\n\ qos-list SWITCH print QoS rules for SWITCH\n\ \n\ Meter commands:\n\ @@ -2490,7 +2491,7 @@ nbctl_qos_add(struct ctl_context *ctx) } static void -nbctl_qos_del(struct ctl_context *ctx) +nbctl_ls_qos_del(struct ctl_context *ctx) { const struct nbrec_logical_switch *ls; char *error = ls_by_name_or_uuid(ctx, ctx->argv[1], true, &ls); @@ -2564,6 +2565,96 @@ nbctl_qos_del(struct ctl_context *ctx) } } +/* Remove qos*/ +static void +remove_qos(const struct nbrec_logical_switch *ls, size_t idx) +{ + + /* First remove 'qos' from the array of qos_rules. This is what will + * actually cause the qos to be deleted when the transaction is + * sent to the database server (due to garbage collection). */ + struct nbrec_qos **new_qos_rules + = xmemdup(ls->qos_rules, sizeof *new_qos_rules * ls->n_qos_rules); + new_qos_rules[idx] = new_qos_rules[ls->n_qos_rules - 1]; + nbrec_logical_switch_verify_qos_rules(ls); + nbrec_logical_switch_set_qos_rules(ls, new_qos_rules, \ + ls->n_qos_rules - 1); + free(new_qos_rules); + + /* Delete 'qos' from the IDL.This won't have a real effect on the + * database server (the IDL will suppress it in fact) but it means that it + * won't show up when we iterate with NBREC_LOGICAL_QOS_FOR_EACH later. */ +} + +static char * OVS_WARN_UNUSED_RESULT +qos_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist, + const struct nbrec_qos **qos_p) +{ + const struct nbrec_qos *qos = NULL; + *qos_p = NULL; + + struct uuid qos_uuid; + bool is_uuid = uuid_from_string(&qos_uuid, id); + if (is_uuid) { + qos = nbrec_qos_get_for_uuid(ctx->idl, &qos_uuid); + } + + if (!qos) { + const struct nbrec_qos *iter; + + NBREC_QOS_FOR_EACH(iter, ctx->idl) { + if (strcmp(iter->name, id)) { + continue; + } + if (qos) { + return xasprintf("Multiple qos named '%s'. " + "Use a UUID.", id); + } + qos = iter; + } + } + + if (!qos && must_exist) { + return xasprintf("%s: qos %s not found", + id, is_uuid ? "UUID" : "name"); + } + + *qos_p = qos; + return NULL; +} + +static void +nbctl_qos_del(struct ctl_context *ctx) +{ + bool must_exist = !shash_find(&ctx->options, "--if-exists"); + const char *id = ctx->argv[1]; + const struct nbrec_qos *qos = NULL; + + char *error = qos_by_name_or_uuid(ctx, id, must_exist, &qos); + if (error) { + ctx->error = error; + return; + } + if (!qos) { + return; + } + + /* Find the switch that contains 'qos_rules', then delete it. */ + const struct nbrec_logical_switch *ls; + NBREC_LOGICAL_SWITCH_FOR_EACH (ls, ctx->idl) { + for (size_t i = 0; i < ls->n_qos_rules; i++) { + if (ls->qos_rules[i] == qos) { + remove_qos(ls, i); + return; + } + } + } + + /* Can't happen because of the database schema. */ + ctl_error(ctx, "qos %s is not part of any logical switch", + ctx->argv[1]); +} + static int meter_cmp(const void *meter1_, const void *meter2_) { @@ -5652,8 +5743,9 @@ static const struct ctl_command_syntax nbctl_commands[] = { { "qos-add", 5, 7, "SWITCH DIRECTION PRIORITY MATCH [rate=RATE [burst=BURST]] [dscp=DSCP]", NULL, nbctl_qos_add, NULL, "--may-exist", RW }, - { "qos-del", 1, 4, "SWITCH [DIRECTION [PRIORITY MATCH]]", NULL, - nbctl_qos_del, NULL, "", RW }, + { "qos-del", 1, 1, "QOS", NULL, nbctl_qos_del, NULL, "--if-exists", RW }, + { "ls-qos-del", 1, 4, "SWITCH [DIRECTION [PRIORITY MATCH]]", NULL, + nbctl_ls_qos_del, NULL, "", RW }, { "qos-list", 1, 1, "SWITCH", NULL, nbctl_qos_list, NULL, "", RO }, /* meter commands. */