From patchwork Mon Dec 23 02:47:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: taoyunxiang X-Patchwork-Id: 1214816 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 47h3g35VQFz9sPV for ; Mon, 23 Dec 2019 13:47:43 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 3F26887994; Mon, 23 Dec 2019 02:47:40 +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 kKg+acQ3J5NX; Mon, 23 Dec 2019 02:47:36 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id A00C7874BA; Mon, 23 Dec 2019 02:47:35 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 87A26C1D81; Mon, 23 Dec 2019 02:47:35 +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 12067C0881 for ; Mon, 23 Dec 2019 02:47:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 0F0682043B for ; Mon, 23 Dec 2019 02:47:32 +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 pVhSRgQU0+Rt for ; Mon, 23 Dec 2019 02:47:29 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from cmccmta3.chinamobile.com (cmccmta3.chinamobile.com [221.176.66.81]) by silver.osuosl.org (Postfix) with ESMTP id 45EF420028 for ; Mon, 23 Dec 2019 02:47:28 +0000 (UTC) Received: from spf.mail.chinamobile.com (unknown[172.16.121.11]) by rmmx-syy-dmz-app11-12011 (RichMail) with SMTP id 2eeb5e002aa9d8e-2aba6; Mon, 23 Dec 2019 10:47:06 +0800 (CST) X-RM-TRANSID: 2eeb5e002aa9d8e-2aba6 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from Yun (unknown[112.25.154.148]) by rmsmtp-syy-appsvr06-12006 (RichMail) with SMTP id 2ee65e002aa9755-02e86; Mon, 23 Dec 2019 10:47:06 +0800 (CST) X-RM-TRANSID: 2ee65e002aa9755-02e86 Date: Mon, 23 Dec 2019 10:47:05 +0800 From: "taoyunxiang@cmss.chinamobile.com" To: ovs-dev X-Priority: 3 X-GUID: 35C1ADB7-B8D7-4991-811E-F54E78E56231 X-Has-Attach: no X-Mailer: Foxmail 7.2.13.365[cn] Mime-Version: 1.0 Message-ID: <2019122310470507155426@cmss.chinamobile.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [ovs-dev] [PATCH v3 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 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. */