mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 14:25:26 +00:00
ovsdb: Embed jsonrpc session options into ovsdb jsonrpc options.
Just introduced structure 'jsonrpc_session_options' is the same as part of the 'ovsdb_jsonrpc_options'. In fact, these options do really belong to a lower layer. So, replace a copy of these fields with a structure, so it can be easily passed to jsonrpc's 'jsonrpc_session_set_options()'. Not creating separate JSON parsing/formatting functions to avoid creating an extra nesting level for the users who will write the JSON definition in a configuration file. I.e. keeping the JSON object flat. Also, not changing the 'db_config->options' to be 'jsonrpc_session_options', even though we don't need the 'role' or 'read-only' fields. This allows us to use the same JSON parsing function for both the remotes ans database sources. Can be changed in the future, but for now keeping as is to avoid extra code complication. Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
@@ -211,11 +211,12 @@ struct ovsdb_jsonrpc_options *
|
|||||||
ovsdb_jsonrpc_default_options(const char *target)
|
ovsdb_jsonrpc_default_options(const char *target)
|
||||||
{
|
{
|
||||||
struct ovsdb_jsonrpc_options *options = xzalloc(sizeof *options);
|
struct ovsdb_jsonrpc_options *options = xzalloc(sizeof *options);
|
||||||
options->max_backoff = RECONNECT_DEFAULT_MAX_BACKOFF;
|
struct jsonrpc_session_options *rpc_opt = &options->rpc;
|
||||||
options->probe_interval = (stream_or_pstream_needs_probes(target)
|
|
||||||
? RECONNECT_DEFAULT_PROBE_INTERVAL
|
rpc_opt->max_backoff = RECONNECT_DEFAULT_MAX_BACKOFF;
|
||||||
: 0);
|
rpc_opt->probe_interval = (stream_or_pstream_needs_probes(target)
|
||||||
options->dscp = DSCP_DEFAULT;
|
? RECONNECT_DEFAULT_PROBE_INTERVAL : 0);
|
||||||
|
rpc_opt->dscp = DSCP_DEFAULT;
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,10 +247,10 @@ ovsdb_jsonrpc_options_to_json(const struct ovsdb_jsonrpc_options *options,
|
|||||||
struct json *json = json_object_create();
|
struct json *json = json_object_create();
|
||||||
|
|
||||||
json_object_put(json, "max-backoff",
|
json_object_put(json, "max-backoff",
|
||||||
json_integer_create(options->max_backoff));
|
json_integer_create(options->rpc.max_backoff));
|
||||||
json_object_put(json, "inactivity-probe",
|
json_object_put(json, "inactivity-probe",
|
||||||
json_integer_create(options->probe_interval));
|
json_integer_create(options->rpc.probe_interval));
|
||||||
json_object_put(json, "dscp", json_integer_create(options->dscp));
|
json_object_put(json, "dscp", json_integer_create(options->rpc.dscp));
|
||||||
|
|
||||||
if (jsonrpc_session_only) {
|
if (jsonrpc_session_only) {
|
||||||
/* Caller is not interested in OVSDB-specific options. */
|
/* Caller is not interested in OVSDB-specific options. */
|
||||||
@@ -279,18 +280,18 @@ ovsdb_jsonrpc_options_update_from_json(struct ovsdb_jsonrpc_options *options,
|
|||||||
max_backoff = ovsdb_parser_member(&parser, "max-backoff",
|
max_backoff = ovsdb_parser_member(&parser, "max-backoff",
|
||||||
OP_INTEGER | OP_OPTIONAL);
|
OP_INTEGER | OP_OPTIONAL);
|
||||||
if (max_backoff) {
|
if (max_backoff) {
|
||||||
options->max_backoff = json_integer(max_backoff);
|
options->rpc.max_backoff = json_integer(max_backoff);
|
||||||
}
|
}
|
||||||
|
|
||||||
probe_interval = ovsdb_parser_member(&parser, "inactivity-probe",
|
probe_interval = ovsdb_parser_member(&parser, "inactivity-probe",
|
||||||
OP_INTEGER | OP_OPTIONAL);
|
OP_INTEGER | OP_OPTIONAL);
|
||||||
if (probe_interval) {
|
if (probe_interval) {
|
||||||
options->probe_interval = json_integer(probe_interval);
|
options->rpc.probe_interval = json_integer(probe_interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
dscp = ovsdb_parser_member(&parser, "dscp", OP_INTEGER | OP_OPTIONAL);
|
dscp = ovsdb_parser_member(&parser, "dscp", OP_INTEGER | OP_OPTIONAL);
|
||||||
if (dscp) {
|
if (dscp) {
|
||||||
options->dscp = json_integer(dscp);
|
options->rpc.dscp = json_integer(dscp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jsonrpc_session_only) {
|
if (jsonrpc_session_only) {
|
||||||
@@ -339,7 +340,7 @@ ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *svr,
|
|||||||
if (!options) {
|
if (!options) {
|
||||||
VLOG_INFO("%s: remote deconfigured", node->name);
|
VLOG_INFO("%s: remote deconfigured", node->name);
|
||||||
ovsdb_jsonrpc_server_del_remote(node);
|
ovsdb_jsonrpc_server_del_remote(node);
|
||||||
} else if (options->dscp != remote->dscp
|
} else if (options->rpc.dscp != remote->dscp
|
||||||
|| !nullable_string_is_equal(options->role, remote->role)) {
|
|| !nullable_string_is_equal(options->role, remote->role)) {
|
||||||
ovsdb_jsonrpc_server_del_remote(node);
|
ovsdb_jsonrpc_server_del_remote(node);
|
||||||
}
|
}
|
||||||
@@ -369,7 +370,7 @@ ovsdb_jsonrpc_server_add_remote(struct ovsdb_jsonrpc_server *svr,
|
|||||||
struct pstream *listener;
|
struct pstream *listener;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
error = jsonrpc_pstream_open(name, &listener, options->dscp);
|
error = jsonrpc_pstream_open(name, &listener, options->rpc.dscp);
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case 0:
|
case 0:
|
||||||
case EAFNOSUPPORT:
|
case EAFNOSUPPORT:
|
||||||
@@ -377,7 +378,7 @@ ovsdb_jsonrpc_server_add_remote(struct ovsdb_jsonrpc_server *svr,
|
|||||||
remote->server = svr;
|
remote->server = svr;
|
||||||
remote->listener = listener;
|
remote->listener = listener;
|
||||||
ovs_list_init(&remote->sessions);
|
ovs_list_init(&remote->sessions);
|
||||||
remote->dscp = options->dscp;
|
remote->dscp = options->rpc.dscp;
|
||||||
remote->read_only = options->read_only;
|
remote->read_only = options->read_only;
|
||||||
remote->role = nullable_xstrdup(options->role);
|
remote->role = nullable_xstrdup(options->role);
|
||||||
shash_add(&svr->remotes, name, remote);
|
shash_add(&svr->remotes, name, remote);
|
||||||
@@ -687,15 +688,6 @@ ovsdb_jsonrpc_session_run(struct ovsdb_jsonrpc_session *s)
|
|||||||
return jsonrpc_session_is_alive(s->js) ? 0 : ETIMEDOUT;
|
return jsonrpc_session_is_alive(s->js) ? 0 : ETIMEDOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
ovsdb_jsonrpc_session_set_options(struct ovsdb_jsonrpc_session *session,
|
|
||||||
const struct ovsdb_jsonrpc_options *options)
|
|
||||||
{
|
|
||||||
jsonrpc_session_set_max_backoff(session->js, options->max_backoff);
|
|
||||||
jsonrpc_session_set_probe_interval(session->js, options->probe_interval);
|
|
||||||
jsonrpc_session_set_dscp(session->js, options->dscp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ovsdb_jsonrpc_session_run_all(struct ovsdb_jsonrpc_remote *remote)
|
ovsdb_jsonrpc_session_run_all(struct ovsdb_jsonrpc_remote *remote)
|
||||||
{
|
{
|
||||||
@@ -814,7 +806,7 @@ ovsdb_jsonrpc_session_set_all_options(
|
|||||||
struct ovsdb_jsonrpc_session *s;
|
struct ovsdb_jsonrpc_session *s;
|
||||||
|
|
||||||
LIST_FOR_EACH (s, node, &remote->sessions) {
|
LIST_FOR_EACH (s, node, &remote->sessions) {
|
||||||
ovsdb_jsonrpc_session_set_options(s, options);
|
jsonrpc_session_set_options(s->js, &options->rpc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "openvswitch/types.h"
|
#include "openvswitch/types.h"
|
||||||
|
#include "jsonrpc.h"
|
||||||
|
|
||||||
struct ovsdb;
|
struct ovsdb;
|
||||||
struct shash;
|
struct shash;
|
||||||
@@ -33,10 +34,8 @@ void ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *);
|
|||||||
|
|
||||||
/* Options for a remote. */
|
/* Options for a remote. */
|
||||||
struct ovsdb_jsonrpc_options {
|
struct ovsdb_jsonrpc_options {
|
||||||
int max_backoff; /* Maximum reconnection backoff, in msec. */
|
struct jsonrpc_session_options rpc; /* JSON-RPC options. */
|
||||||
int probe_interval; /* Max idle time before probing, in msec. */
|
|
||||||
bool read_only; /* Only read-only transactions are allowed. */
|
bool read_only; /* Only read-only transactions are allowed. */
|
||||||
int dscp; /* Dscp value for manager connections */
|
|
||||||
char *role; /* Role, for role-based access controls */
|
char *role; /* Role, for role-based access controls */
|
||||||
};
|
};
|
||||||
struct ovsdb_jsonrpc_options *ovsdb_jsonrpc_default_options(
|
struct ovsdb_jsonrpc_options *ovsdb_jsonrpc_default_options(
|
||||||
|
@@ -461,9 +461,9 @@ get_jsonrpc_options(const char *target, enum service_model model)
|
|||||||
|
|
||||||
options = ovsdb_jsonrpc_default_options(target);
|
options = ovsdb_jsonrpc_default_options(target);
|
||||||
if (model == SM_ACTIVE_BACKUP) {
|
if (model == SM_ACTIVE_BACKUP) {
|
||||||
options->probe_interval = REPLICATION_DEFAULT_PROBE_INTERVAL;
|
options->rpc.probe_interval = REPLICATION_DEFAULT_PROBE_INTERVAL;
|
||||||
} else if (model == SM_RELAY) {
|
} else if (model == SM_RELAY) {
|
||||||
options->probe_interval = RELAY_SOURCE_DEFAULT_PROBE_INTERVAL;
|
options->rpc.probe_interval = RELAY_SOURCE_DEFAULT_PROBE_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
@@ -1016,14 +1016,14 @@ open_db(struct server_config *server_config,
|
|||||||
|
|
||||||
if (model == SM_RELAY) {
|
if (model == SM_RELAY) {
|
||||||
ovsdb_relay_add_db(db->db, conf->source, update_schema, server_config,
|
ovsdb_relay_add_db(db->db, conf->source, update_schema, server_config,
|
||||||
conf->options->probe_interval);
|
conf->options->rpc.probe_interval);
|
||||||
}
|
}
|
||||||
if (model == SM_ACTIVE_BACKUP && conf->ab.backup) {
|
if (model == SM_ACTIVE_BACKUP && conf->ab.backup) {
|
||||||
const struct uuid *server_uuid;
|
const struct uuid *server_uuid;
|
||||||
|
|
||||||
server_uuid = ovsdb_jsonrpc_server_get_uuid(server_config->jsonrpc);
|
server_uuid = ovsdb_jsonrpc_server_get_uuid(server_config->jsonrpc);
|
||||||
replication_set_db(db->db, conf->source, conf->ab.sync_exclude,
|
replication_set_db(db->db, conf->source, conf->ab.sync_exclude,
|
||||||
server_uuid, conf->options->probe_interval);
|
server_uuid, conf->options->rpc.probe_interval);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1240,11 +1240,11 @@ add_manager_options(struct shash *remotes, const struct ovsdb_row *row)
|
|||||||
|
|
||||||
options = add_remote(remotes, target, NULL);
|
options = add_remote(remotes, target, NULL);
|
||||||
if (ovsdb_util_read_integer_column(row, "max_backoff", &max_backoff)) {
|
if (ovsdb_util_read_integer_column(row, "max_backoff", &max_backoff)) {
|
||||||
options->max_backoff = max_backoff;
|
options->rpc.max_backoff = max_backoff;
|
||||||
}
|
}
|
||||||
if (ovsdb_util_read_integer_column(row, "inactivity_probe",
|
if (ovsdb_util_read_integer_column(row, "inactivity_probe",
|
||||||
&probe_interval)) {
|
&probe_interval)) {
|
||||||
options->probe_interval = probe_interval;
|
options->rpc.probe_interval = probe_interval;
|
||||||
}
|
}
|
||||||
if (ovsdb_util_read_bool_column(row, "read_only", &read_only)) {
|
if (ovsdb_util_read_bool_column(row, "read_only", &read_only)) {
|
||||||
options->read_only = read_only;
|
options->read_only = read_only;
|
||||||
@@ -1256,13 +1256,13 @@ add_manager_options(struct shash *remotes, const struct ovsdb_row *row)
|
|||||||
options->role = xstrdup(role);
|
options->role = xstrdup(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
options->dscp = DSCP_DEFAULT;
|
options->rpc.dscp = DSCP_DEFAULT;
|
||||||
dscp_string = ovsdb_util_read_map_string_column(row, "other_config",
|
dscp_string = ovsdb_util_read_map_string_column(row, "other_config",
|
||||||
"dscp");
|
"dscp");
|
||||||
if (dscp_string) {
|
if (dscp_string) {
|
||||||
int dscp = atoi(dscp_string);
|
int dscp = atoi(dscp_string);
|
||||||
if (dscp >= 0 && dscp <= 63) {
|
if (dscp >= 0 && dscp <= 63) {
|
||||||
options->dscp = dscp;
|
options->rpc.dscp = dscp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1725,7 +1725,7 @@ ovsdb_server_connect_active_ovsdb_server(struct unixctl_conn *conn,
|
|||||||
conf->model = SM_ACTIVE_BACKUP;
|
conf->model = SM_ACTIVE_BACKUP;
|
||||||
conf->source = xstrdup(*config->sync_from);
|
conf->source = xstrdup(*config->sync_from);
|
||||||
conf->options = ovsdb_jsonrpc_default_options(conf->source);
|
conf->options = ovsdb_jsonrpc_default_options(conf->source);
|
||||||
conf->options->probe_interval =
|
conf->options->rpc.probe_interval =
|
||||||
*config->replication_probe_interval;
|
*config->replication_probe_interval;
|
||||||
conf->ab.sync_exclude =
|
conf->ab.sync_exclude =
|
||||||
nullable_xstrdup(*config->sync_exclude);
|
nullable_xstrdup(*config->sync_exclude);
|
||||||
@@ -1734,7 +1734,8 @@ ovsdb_server_connect_active_ovsdb_server(struct unixctl_conn *conn,
|
|||||||
|
|
||||||
if (conf->model == SM_ACTIVE_BACKUP && !conf->ab.backup) {
|
if (conf->model == SM_ACTIVE_BACKUP && !conf->ab.backup) {
|
||||||
replication_set_db(db->db, conf->source, conf->ab.sync_exclude,
|
replication_set_db(db->db, conf->source, conf->ab.sync_exclude,
|
||||||
server_uuid, conf->options->probe_interval);
|
server_uuid,
|
||||||
|
conf->options->rpc.probe_interval);
|
||||||
conf->ab.backup = true;
|
conf->ab.backup = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1800,10 +1801,11 @@ ovsdb_server_set_active_ovsdb_server_probe_interval(struct unixctl_conn *conn,
|
|||||||
struct db_config *conf = db->config;
|
struct db_config *conf = db->config;
|
||||||
|
|
||||||
if (conf->model == SM_ACTIVE_BACKUP) {
|
if (conf->model == SM_ACTIVE_BACKUP) {
|
||||||
conf->options->probe_interval = probe_interval;
|
conf->options->rpc.probe_interval = probe_interval;
|
||||||
if (conf->ab.backup) {
|
if (conf->ab.backup) {
|
||||||
replication_set_db(db->db, conf->source, conf->ab.sync_exclude,
|
replication_set_db(db->db, conf->source, conf->ab.sync_exclude,
|
||||||
server_uuid, conf->options->probe_interval);
|
server_uuid,
|
||||||
|
conf->options->rpc.probe_interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1839,7 +1841,7 @@ ovsdb_server_set_relay_source_interval(struct unixctl_conn *conn,
|
|||||||
struct db_config *conf = db->config;
|
struct db_config *conf = db->config;
|
||||||
|
|
||||||
if (conf->model == SM_RELAY) {
|
if (conf->model == SM_RELAY) {
|
||||||
conf->options->probe_interval = probe_interval;
|
conf->options->rpc.probe_interval = probe_interval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1882,7 +1884,8 @@ ovsdb_server_set_sync_exclude_tables(struct unixctl_conn *conn,
|
|||||||
conf->ab.sync_exclude = xstrdup(argv[1]);
|
conf->ab.sync_exclude = xstrdup(argv[1]);
|
||||||
if (conf->ab.backup) {
|
if (conf->ab.backup) {
|
||||||
replication_set_db(db->db, conf->source, conf->ab.sync_exclude,
|
replication_set_db(db->db, conf->source, conf->ab.sync_exclude,
|
||||||
server_uuid, conf->options->probe_interval);
|
server_uuid,
|
||||||
|
conf->options->rpc.probe_interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user