Use Open vSwitch IDL pattern to read OVS configuration on dpctl start, needed as some functionality is dependent on that configuration.
Signed-off-by: Paul Blakey <[email protected]> Reviewed-by: Roi Dayan <[email protected]> --- lib/dpctl.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/dpctl.h | 2 ++ utilities/ovs-dpctl.c | 2 ++ 3 files changed, 48 insertions(+) diff --git a/lib/dpctl.c b/lib/dpctl.c index edccb7f..a892632 100644 --- a/lib/dpctl.c +++ b/lib/dpctl.c @@ -50,6 +50,10 @@ #include "unixctl.h" #include "util.h" #include "openvswitch/ofp-parse.h" +#include "ovsdb-idl.h" +#include "vswitch-idl.h" +#include "db-ctl-base.h" +#include "tc.h" typedef int dpctl_command_handler(int argc, const char *argv[], struct dpctl_params *); @@ -1645,6 +1649,46 @@ static const struct dpctl_command *get_all_dpctl_commands(void) return all_commands; } +int +dpctl_read_db() +{ + char *db = ctl_default_db(); + struct ovsdb_idl *idl = ovsdb_idl_create(db, &ovsrec_idl_class, true, + true); + ovsdb_idl_track_add_all(idl); + unsigned int seqno = ovsdb_idl_get_seqno(idl); + const struct ovsrec_open_vswitch *cfg; + + for (;;) { + /* synchronize OVSDB */ + ovsdb_idl_run(idl); + + if (!ovsdb_idl_is_alive(idl)) { + int retval = ovsdb_idl_get_last_error(idl); + + ctl_fatal("%s: database connection failed (%s)", + db, ovs_retval_to_string(retval)); + } + + if (seqno != ovsdb_idl_get_seqno(idl)) { + cfg = ovsrec_open_vswitch_first(idl); + if (cfg) { + netdev_set_flow_api_enabled(smap_get_bool(&cfg->other_config, + "hw-offload", + false)); + tc_set_skip_hw(smap_get_bool(&cfg->other_config, "skip_hw", + false)); + break; + } + } else { + ovsdb_idl_wait(idl); + } + } + + ovsdb_idl_destroy(idl); + return 0; +} + /* Runs the command designated by argv[0] within the command table specified by * 'commands', which must be terminated by a command whose 'name' member is a * null pointer. */ diff --git a/lib/dpctl.h b/lib/dpctl.h index 4ee083f..4828f3d 100644 --- a/lib/dpctl.h +++ b/lib/dpctl.h @@ -50,6 +50,8 @@ struct dpctl_params { void (*usage)(void *aux); }; +int dpctl_read_db(void); + int dpctl_run_command(int argc, const char *argv[], struct dpctl_params *dpctl_p); diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index 843d305..135035d 100644 --- a/utilities/ovs-dpctl.c +++ b/utilities/ovs-dpctl.c @@ -66,6 +66,8 @@ main(int argc, char *argv[]) dpctl_p.output = dpctl_print; dpctl_p.usage = usage; + dpctl_read_db(); + error = dpctl_run_command(argc - optind, (const char **) argv + optind, &dpctl_p); return error ? EXIT_FAILURE : EXIT_SUCCESS; -- 1.8.3.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
