From patchwork Mon Apr 20 14:57:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pier Luigi Ventre X-Patchwork-Id: 1273476 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.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=P4G81+O8; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 495VDc5ZL5z9s71 for ; Tue, 21 Apr 2020 00:57:52 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 8D87486E42; Mon, 20 Apr 2020 14:57:49 +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 yfq1rgswtRmR; Mon, 20 Apr 2020 14:57:46 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 0852686D9A; Mon, 20 Apr 2020 14:57:46 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DEBF6C1D74; Mon, 20 Apr 2020 14:57:45 +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 EF385C0177 for ; Mon, 20 Apr 2020 14:57:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id DDB2220766 for ; Mon, 20 Apr 2020 14:57:44 +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 VyO0Lr9mE4DK for ; Mon, 20 Apr 2020 14:57:41 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by silver.osuosl.org (Postfix) with ESMTPS id 25F2120373 for ; Mon, 20 Apr 2020 14:57:41 +0000 (UTC) Received: by mail-wm1-f44.google.com with SMTP id v8so224719wma.0 for ; Mon, 20 Apr 2020 07:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:message-id:date:to; bh=KfmuXAHfcbNADuxgXg/0oD86Z80KyWrgKumcJtONOGY=; b=P4G81+O88qVcKE9UYa10LgAGgX95pEa00oHk0tIBrjCgHHzEf+2cNHIpaukba37KHD M7tL4a+Vldo0bZAK5qTlTr8vTEJcnG2MRra/U0ReSuEwQUh9JxUf4ZBt/KRjyE0Xe71j M7AXsID5MIWEBvs+MoRNYVgtYmjuAF9enyKTCJTNi5K76q8hIP9NGYNrANL6BE5Nip9+ mgJ/aRPMS6cS2laY/SmF78dGiXpT+/wEj3SYg3CtW9hH6SNlFrInys5ZBlgtY++rTwdK n+u2gys9TMktLypdEOUvBgZVDwwNmQgXP6I7qibGgwHyxnup/a56Tc85ISGN1MhQOXi2 wEZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=KfmuXAHfcbNADuxgXg/0oD86Z80KyWrgKumcJtONOGY=; b=pYG2dc/KTbItOucCx+UI6a93t8yZ7pOJ8BEl6nGcNa/Py0iYkZNKo4KjUotQKmxKsP uWN4saQW5l62c+ldkzRR+UBe3ubAubMFTrx5iLSdioC0h6h57VRpy8e/jHVpfpweE5hM Oaj/GTHVvAczzBWCRgFboKRCEqFzhwQEcbhatqztONEBqLPofpz5xzteVVPErHp6aRcd Ax/ee5rpQdSWf75G/cUbJI211HtXLkHpc1Jva7DuBVFvjxS/84Z+SWxb6m9graL9unMp UqkaG913K5ZIKy0LYNfcpBjidW3TYTPKk3qhmdyFspgoPFWGBHLSWh59+2+mADoGyIyi +C5w== X-Gm-Message-State: AGi0PuaEeNlp4VdKML3QxPxnrzeHQuXHJo0bspK6052stFM+c0EyapXL +nDbCc/gU81f1YlrygKzAYP6rDpajME= X-Google-Smtp-Source: APiQypJA7JbC+kjbKShMqv5LOSY2VWM8QJYL62ecto6rGFNqHRS0tPlDcnlf3TrgyGVEYNnyEREwUA== X-Received: by 2002:a1c:7d4b:: with SMTP id y72mr18560241wmc.11.1587394658745; Mon, 20 Apr 2020 07:57:38 -0700 (PDT) Received: from [192.168.1.114] (host98-3-dynamic.17-79-r.retail.telecomitalia.it. [79.17.3.98]) by smtp.gmail.com with ESMTPSA id t8sm1542638wrq.88.2020.04.20.07.57.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Apr 2020 07:57:37 -0700 (PDT) From: Pier Luigi Ventre Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Message-Id: <05D5A265-76C3-45B7-97A1-0F332767C457@gmail.com> Date: Mon, 20 Apr 2020 16:57:36 +0200 To: ovs-dev@openvswitch.org X-Mailer: Apple Mail (2.3445.104.11) X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [ovs-dev] [PATCH 1/1] ofproto: Fix ofgroup ref_count in the group stats. 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" Hi everyone. This patch is a followup to this message sent in ovs-discuss: https://mail.openvswitch.org/pipermail/ovs-discuss/2020-April/049897.html This is the brief description of the change: The patch fixes ofgroup ref_count in the group stats. Previously, only the rules were counted. However, ofgroups can reference other ofgroups. Updates tests that were failing: groups were not created in order. Adds new unit tests for reference count Signed-off-by: Pier Luigi Ventre — — Thanks Pier diff --git a/include/openvswitch/ofp-group.h b/include/openvswitch/ofp-group.h index cd7af0ebf..e5dd3a9ec 100644 --- a/include/openvswitch/ofp-group.h +++ b/include/openvswitch/ofp-group.h @@ -58,6 +58,9 @@ struct ofputil_bucket { struct ofpact *ofpacts; /* Series of "struct ofpact"s. */ size_t ofpacts_len; /* Length of ofpacts, in bytes. */ + bool has_groups; /* 'has_groups' is true if 'ofpacts' contains + * an OFPACT_GROUP action .*/ + struct bucket_counter stats; }; diff --git a/lib/ofp-group.c b/lib/ofp-group.c index bf0f8af54..6cb904f79 100644 --- a/lib/ofp-group.c +++ b/lib/ofp-group.c @@ -1375,6 +1375,10 @@ ofputil_pull_ofp11_buckets(struct ofpbuf *msg, size_t buckets_length, bucket->ofpacts = ofpbuf_steal_data(&ofpacts); bucket->ofpacts_len = ofpacts.size; + bucket->has_groups = + (ofpact_find_type_flattened(bucket->ofpacts, OFPACT_GROUP, + ofpact_end(bucket->ofpacts, bucket->ofpacts_len)) + != NULL); ovs_list_push_back(buckets, &bucket->list_node); } diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h index afecb24cb..b0779996e 100644 --- a/ofproto/ofproto-provider.h +++ b/ofproto/ofproto-provider.h @@ -586,6 +586,7 @@ struct ofgroup { struct ofputil_group_props props; struct rule_collection rules OVS_GUARDED; /* Referring rules. */ + uint32_t rgroups OVS_GUARDED; /* Referring groups. */ }; struct pkt_stats { diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 0fbd6c380..f31d4160e 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -3075,7 +3075,9 @@ ofproto_group_unref(struct ofgroup *group) OVS_NO_THREAD_SAFETY_ANALYSIS { if (group && ovs_refcount_unref_relaxed(&group->ref_count) == 1) { + /* There are no rules nor groups still referencing it. */ ovs_assert(rule_collection_n(&group->rules) == 0); + ovs_assert(group->rgroups == 0); ovsrcu_postpone(group_destroy_cb, group); } } @@ -7100,6 +7102,45 @@ group_remove_rule(struct ofgroup *group, struct rule *rule) rule_collection_remove(&group->rules, rule); } +static void +group_add_rgroup(struct ofgroup *group) +{ + group->rgroups++; +} + +static void +group_remove_rgroup(struct ofgroup *group) +{ + group->rgroups--; +} + +/* Iterates over the buckets and updates the rgroups count + * in the referenced groups. */ +static void +update_group_references(struct ofproto *ofproto, struct ofgroup *ogroup, + bool add) +{ + struct ofputil_bucket *bucket; + LIST_FOR_EACH (bucket, list_node, &ogroup->buckets) { + if (bucket->has_groups) { + /* Iterate over the group actions and update the references */ + const struct ofpact_group *a; + OFPACT_FOR_EACH_TYPE_FLATTENED (a, GROUP, bucket->ofpacts, + bucket->ofpacts_len) { + struct ofgroup *group; + group = ofproto_group_lookup(ofproto, a->group_id, + OVS_VERSION_MAX, false); + ovs_assert(group != NULL); + if (add) { + group_add_rgroup(group); + } else { + group_remove_rgroup(group); + } + } + } + } +} + static void append_group_stats(struct ofgroup *group, struct ovs_list *replies) OVS_REQUIRES(ofproto_mutex) @@ -7112,7 +7153,7 @@ append_group_stats(struct ofgroup *group, struct ovs_list *replies) ogs.bucket_stats = xmalloc(group->n_buckets * sizeof *ogs.bucket_stats); /* Provider sets the packet and byte counts, we do the rest. */ - ogs.ref_count = rule_collection_n(&group->rules); + ogs.ref_count = rule_collection_n(&group->rules) + group->rgroups; ogs.n_buckets = group->n_buckets; error = (ofproto->ofproto_class->group_get_stats @@ -7349,6 +7390,7 @@ init_group(struct ofproto *ofproto, const struct ofputil_group_mod *gm, &(*ofgroup)->props), &gm->props); rule_collection_init(&(*ofgroup)->rules); + *CONST_CAST(uint32_t *, &((*ofgroup)->rgroups)) = 0; /* Make group visible from 'version'. */ (*ofgroup)->versions = VERSIONS_INITIALIZER(version, @@ -7391,6 +7433,8 @@ add_group_start(struct ofproto *ofproto, struct ofproto_group_mod *ogm) cmap_insert(&ofproto->groups, &ogm->new_group->cmap_node, hash_int(ogm->new_group->group_id, 0)); ofproto->n_groups[ogm->new_group->type]++; + /* Update group references. */ + update_group_references(ofproto, ogm->new_group, true); } return error; } @@ -7551,6 +7595,11 @@ modify_group_start(struct ofproto *ofproto, struct ofproto_group_mod *ogm) goto out; } + /* Remove all the references from the groups. */ + update_group_references(ofproto, old_group, false); + /* Add back all the references without making the diff. */ + update_group_references(ofproto, new_group, true); + /* The group creation time does not change during modification. */ *CONST_CAST(long long int *, &(new_group->created)) = old_group->created; *CONST_CAST(long long int *, &(new_group->modified)) = time_msec(); @@ -7608,6 +7657,7 @@ delete_group_start(struct ofproto *ofproto, ovs_version_t version, group->being_deleted = true; /* Mark all the referring groups for deletion. */ + /* Why is needed ? */ delete_flows_start__(ofproto, version, &group->rules); group_collection_add(groups, group); versions_set_remove_version(&group->versions, version); @@ -7633,6 +7683,14 @@ delete_groups_start(struct ofproto *ofproto, struct ofproto_group_mod *ogm) struct ofgroup *group; if (ogm->gm.group_id == OFPG_ALL) { + /* Unless there is a way to do things in order. + * To make sure there are no pending references. */ + CMAP_FOR_EACH (group, cmap_node, &ofproto->groups) { + if (versions_visible_in_version(&group->versions, ogm->version)) { + /* Remove all the references for the other groups.*/ + update_group_references(ofproto, group, false); + } + } CMAP_FOR_EACH (group, cmap_node, &ofproto->groups) { if (versions_visible_in_version(&group->versions, ogm->version)) { delete_group_start(ofproto, ogm->version, &ogm->old_groups, @@ -7640,8 +7698,11 @@ delete_groups_start(struct ofproto *ofproto, struct ofproto_group_mod *ogm) } } } else { - group = ofproto_group_lookup__(ofproto, ogm->gm.group_id, ogm->version); + group = ofproto_group_lookup__(ofproto, ogm->gm.group_id, + ogm->version); if (group) { + /* Remove all the references for the other groups.*/ + update_group_references(ofproto, group, false); delete_group_start(ofproto, ogm->version, &ogm->old_groups, group); } } @@ -7708,16 +7769,24 @@ ofproto_group_mod_revert(struct ofproto *ofproto, ovs_assert(group_collection_n(&ogm->old_groups) == 1); /* Transfer rules back. */ rule_collection_move(&old_group->rules, &new_group->rules); + /* Remove the new references and restore the old ones. */ + update_group_references(ofproto, new_group, false); + update_group_references(ofproto, old_group, true); } else { old_group->being_deleted = false; /* Revert rule deletion. */ delete_flows_revert__(ofproto, &old_group->rules); + /* Restore the old references. */ + update_group_references(ofproto, old_group, true); } /* Restore visibility. */ versions_set_remove_version(&old_group->versions, OVS_VERSION_NOT_REMOVED); } + /* Revert new added groups. */ if (new_group) { + /* Remove the new references. */ + update_group_references(ofproto, new_group, false); /* Remove the new group immediately. It was never visible to * lookups. */ cmap_remove(&ofproto->groups, &new_group->cmap_node, diff --git a/tests/nsh.at b/tests/nsh.at index d5c772ff0..99d0a391c 100644 --- a/tests/nsh.at +++ b/tests/nsh.at @@ -299,9 +299,9 @@ AT_DATA([flows.txt], [dnl ]) AT_DATA([groups.txt], [dnl - add group_id=100,type=indirect,bucket=actions=encap(nsh(md_type=1)),set_field:0x1234->nsh_spi,set_field:0x11223344->nsh_c1,group:200 - add group_id=200,type=indirect,bucket=actions=encap(nsh(md_type=1)),set_field:0x5678->nsh_spi,set_field:0x55667788->nsh_c1,group:300 add group_id=300,type=indirect,bucket=actions=encap(ethernet),set_field:11:22:33:44:55:66->dl_dst,3 + add group_id=200,type=indirect,bucket=actions=encap(nsh(md_type=1)),set_field:0x5678->nsh_spi,set_field:0x55667788->nsh_c1,group:300 + add group_id=100,type=indirect,bucket=actions=encap(nsh(md_type=1)),set_field:0x1234->nsh_spi,set_field:0x11223344->nsh_c1,group:200 ]) AT_CHECK([ diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index d444cf084..335abf4b6 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -318,8 +318,8 @@ AT_CLEANUP AT_SETUP([ofproto-dpif - group chaining]) OVS_VSWITCHD_START add_of_ports br0 1 10 11 -AT_CHECK([ovs-ofctl -O OpenFlow12 add-group br0 'group_id=1234,type=all,bucket=set_field:192.168.3.90->ip_src,group:123,bucket=output:11']) AT_CHECK([ovs-ofctl -O OpenFlow12 add-group br0 'group_id=123,type=all,bucket=output:10']) +AT_CHECK([ovs-ofctl -O OpenFlow12 add-group br0 'group_id=1234,type=all,bucket=set_field:192.168.3.90->ip_src,group:123,bucket=output:11']) AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 'ip actions=group:1234']) AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=1,dl_src=50:54:00:00:00:05,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=192.168.0.2,nw_proto=1,nw_tos=0,nw_ttl=128,icmp_type=8,icmp_code=0'], [0], [stdout]) AT_CHECK([tail -1 stdout], [0], diff --git a/tests/ofproto.at b/tests/ofproto.at index 76a3be44d..8dbef9559 100644 --- a/tests/ofproto.at +++ b/tests/ofproto.at @@ -6447,3 +6447,71 @@ verify_deleted OVS_VSWITCHD_STOP(["/