Skip to content

Commit 43b084f

Browse files
committed
ovn-trace: need to read latest data when using daemon mode
When logical flow changed in SB, the result that ovn-trace evaluate using daemon mode is previous. Because the data from db just is read once when ovn-trace startup. This situation is not adapted for daemon mode. So we need to keep latest data from SB when ovn-trace use daemon mode. In addition, print the unixctl server path used to be recorded refer from ovn-nbctl and ovn-sbctl. Signed-off-by: Jun Gu <[email protected]>
1 parent bae861d commit 43b084f

File tree

1 file changed

+121
-7
lines changed

1 file changed

+121
-7
lines changed

Diff for: utilities/ovn-trace.c

+121-7
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static bool use_friendly_names = true;
9595
OVS_NO_RETURN static void usage(void);
9696
static void parse_options(int argc, char *argv[]);
9797
static char *trace(const char *datapath, const char *flow);
98+
static void clear_data(void);
9899
static void read_db(void);
99100
static unixctl_cb_func ovntrace_exit;
100101
static unixctl_cb_func ovntrace_trace;
@@ -136,14 +137,16 @@ main(int argc, char *argv[])
136137
if (error) {
137138
ovs_fatal(error, "failed to create unixctl server");
138139
}
140+
puts(unixctl_server_get_path(server));
141+
fflush(stdout);
142+
139143
unixctl_command_register("exit", "", 0, 0, ovntrace_exit, &exiting);
140144
unixctl_command_register("trace", "[OPTIONS] [DATAPATH] MICROFLOW",
141145
1, INT_MAX, ovntrace_trace, NULL);
142146
}
143147
ovnsb_idl = ovsdb_idl_create(db, &sbrec_idl_class, true, false);
144148
ovsdb_idl_set_leader_only(ovnsb_idl, leader_only);
145149

146-
bool already_read = false;
147150
for (;;) {
148151
ovsdb_idl_run(ovnsb_idl);
149152
unixctl_server_run(server);
@@ -154,11 +157,8 @@ main(int argc, char *argv[])
154157
}
155158

156159
if (ovsdb_idl_has_ever_connected(ovnsb_idl)) {
157-
if (!already_read) {
158-
already_read = true;
159-
read_db();
160-
}
161-
160+
clear_data();
161+
read_db();
162162
daemonize_complete();
163163
if (!get_detach()) {
164164
const char *dp_s = argc > 1 ? argv[0] : NULL;
@@ -443,7 +443,7 @@ struct ovntrace_port {
443443
struct uuid uuid;
444444
char *name;
445445
char *name2;
446-
const char *friendly_name;
446+
char *friendly_name;
447447
char *type;
448448
uint16_t tunnel_key;
449449
struct ovntrace_port *peer; /* Patch ports only. */
@@ -679,6 +679,120 @@ shorten_uuid(const char *s)
679679
: xstrdup(s));
680680
}
681681

682+
static void
683+
ovntrace_fdbs_destroy(struct hmap *fdbs)
684+
{
685+
struct ovntrace_fdb *fdb;
686+
HMAP_FOR_EACH_POP (fdb, node, fdbs) {
687+
free(fdb);
688+
}
689+
hmap_destroy(fdbs);
690+
}
691+
692+
static void
693+
ovntrace_mac_bindings_destroy(struct hmap *bindings)
694+
{
695+
struct ovntrace_mac_binding *binding;
696+
HMAP_FOR_EACH_POP (binding, node, bindings) {
697+
free(binding);
698+
}
699+
hmap_destroy(bindings);
700+
}
701+
702+
static void
703+
ovntrace_flows_destroy(struct ovntrace_flow **flows, size_t n_flows)
704+
{
705+
for (size_t i = 0; i < n_flows; i++) {
706+
struct ovntrace_flow *flow = flows[i];
707+
free(flow->stage_name);
708+
free(flow->source);
709+
expr_destroy(flow->match);
710+
free(flow->match_s);
711+
ovnacts_free(flow->ovnacts, flow->ovnacts_len);
712+
free(flow->ovnacts);
713+
free(flow);
714+
}
715+
free(flows);
716+
}
717+
718+
static void
719+
ovntrace_mcgroups_destroy(struct ovs_list *mcgroups)
720+
{
721+
struct ovntrace_mcgroup *mcgroup;
722+
LIST_FOR_EACH_POP (mcgroup, list_node, mcgroups) {
723+
free(mcgroup->name);
724+
free(mcgroup->ports);
725+
free(mcgroup);
726+
}
727+
}
728+
729+
static void
730+
ovntrace_datapaths_destroy(void)
731+
{
732+
struct ovntrace_datapath *dp;
733+
HMAP_FOR_EACH_POP (dp, sb_uuid_node, &datapaths) {
734+
ovntrace_mcgroups_destroy(&dp->mcgroups);
735+
ovntrace_mac_bindings_destroy(&dp->mac_bindings);
736+
ovntrace_fdbs_destroy(&dp->fdbs);
737+
ovntrace_flows_destroy(dp->flows, dp->n_flows);
738+
free(dp->name);
739+
free(dp->name2);
740+
free(dp->friendly_name);
741+
free(dp);
742+
}
743+
hmap_destroy(&datapaths);
744+
}
745+
746+
static void
747+
ovntrace_ports_destroy(void)
748+
{
749+
struct shash_node *node, *node_next;
750+
SHASH_FOR_EACH_SAFE (node, node_next, &ports) {
751+
struct ovntrace_port *port = node->data;
752+
free(port->name);
753+
free(port->type);
754+
free(port->name2);
755+
free(port->friendly_name);
756+
free(port);
757+
shash_delete(&ports, node);
758+
}
759+
shash_destroy(&ports);
760+
}
761+
762+
static void
763+
address_sets_destroy(void)
764+
{
765+
expr_const_sets_destroy(&address_sets);
766+
shash_destroy(&address_sets);
767+
}
768+
769+
static void
770+
port_groups_destroy(void)
771+
{
772+
expr_const_sets_destroy(&port_groups);
773+
shash_destroy(&port_groups);
774+
}
775+
776+
static void
777+
clear_data(void)
778+
{
779+
static bool first_clear = true;
780+
if (first_clear) {
781+
first_clear = false;
782+
} else {
783+
ovntrace_datapaths_destroy();
784+
ovntrace_ports_destroy();
785+
address_sets_destroy();
786+
port_groups_destroy();
787+
dhcp_opts_destroy(&dhcp_opts);
788+
dhcp_opts_destroy(&dhcpv6_opts);
789+
nd_ra_opts_destroy(&nd_ra_opts);
790+
controller_event_opts_destroy(&event_opts);
791+
expr_symtab_destroy(&symtab);
792+
shash_destroy(&symtab);
793+
}
794+
}
795+
682796
static void
683797
read_datapaths(void)
684798
{

0 commit comments

Comments
 (0)