Message ID | 1482665989-791-20-git-send-email-paulb@mellanox.com |
---|---|
State | Changes Requested |
Headers | show |
On 25 December 2016 at 03:39, Paul Blakey <paulb@mellanox.com> wrote: > 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 <paulb@mellanox.com> > Reviewed-by: Roi Dayan <roid@mellanox.com> Why? What functionality? What if OVSDB isn't running, does ovs-dpctl block?
On 05/01/2017 23:46, Joe Stringer wrote: > On 25 December 2016 at 03:39, Paul Blakey <paulb@mellanox.com> wrote: >> 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 <paulb@mellanox.com> >> Reviewed-by: Roi Dayan <roid@mellanox.com> > Why? What functionality? Since the hw-offload/skip-hw configurations aren't saved with kernel dpif and dumped back on open, we needed "hw-offload" configuration to know if to try offloading for add-flow dpctl command, and then which flag to pass on to TC (skip_hw/skip_sw) if offloading is enabled. Also for dpctl dump-flows, if hw offload is enabled dump offloaded flows from netdevs. > > What if OVSDB isn't running, does ovs-dpctl block? Yes.
On 10 January 2017 at 08:38, Paul Blakey <paulb@mellanox.com> wrote: > > > On 05/01/2017 23:46, Joe Stringer wrote: >> >> On 25 December 2016 at 03:39, Paul Blakey <paulb@mellanox.com> wrote: >>> >>> 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 <paulb@mellanox.com> >>> Reviewed-by: Roi Dayan <roid@mellanox.com> >> >> Why? What functionality? > > Since the hw-offload/skip-hw configurations aren't saved with kernel dpif > and dumped back on open, > we needed "hw-offload" configuration to know if to try offloading for > add-flow dpctl command, and then > which flag to pass on to TC (skip_hw/skip_sw) if offloading is enabled. > Also for dpctl dump-flows, if hw offload is enabled dump offloaded flows > from netdevs. I think we can come up with reasonable defaults that don't require the database, and commandline flags for anything else. ovs-dpctl is intended as a standalone debug tool, not a regular configuration interface.
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;