Skip to content

Commit

Permalink
ovsdb: Embed jsonrpc session options into ovsdb jsonrpc options.
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Maximets <[email protected]>
  • Loading branch information
igsilya committed Dec 13, 2023
1 parent 312e774 commit 7239485
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 40 deletions.
38 changes: 15 additions & 23 deletions ovsdb/jsonrpc-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ struct ovsdb_jsonrpc_options *
ovsdb_jsonrpc_default_options(const char *target)
{
struct ovsdb_jsonrpc_options *options = xzalloc(sizeof *options);
options->max_backoff = RECONNECT_DEFAULT_MAX_BACKOFF;
options->probe_interval = (stream_or_pstream_needs_probes(target)
? RECONNECT_DEFAULT_PROBE_INTERVAL
: 0);
struct jsonrpc_session_options *rpc_opt = &options->rpc;

rpc_opt->max_backoff = RECONNECT_DEFAULT_MAX_BACKOFF;
rpc_opt->probe_interval = (stream_or_pstream_needs_probes(target)
? RECONNECT_DEFAULT_PROBE_INTERVAL : 0);
return options;
}

Expand All @@ -236,10 +237,10 @@ ovsdb_jsonrpc_options_to_json(const struct ovsdb_jsonrpc_options *options,
struct json *json = json_object_create();

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_integer_create(options->probe_interval));
json_object_put(json, "dscp", json_integer_create(options->dscp));
json_integer_create(options->rpc.probe_interval));
json_object_put(json, "dscp", json_integer_create(options->rpc.dscp));

if (jsonrpc_session_only) {
/* Caller is not inrerested in OVSDB-specific options. */
Expand Down Expand Up @@ -269,18 +270,18 @@ ovsdb_jsonrpc_options_update_from_json(struct ovsdb_jsonrpc_options *options,
max_backoff = ovsdb_parser_member(&parser, "max-backoff",
OP_INTEGER | OP_OPTIONAL);
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",
OP_INTEGER | OP_OPTIONAL);
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);
if (dscp) {
options->dscp = json_integer(dscp);
options->rpc.dscp = json_integer(dscp);
}

if (jsonrpc_session_only) {
Expand Down Expand Up @@ -330,7 +331,7 @@ ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *svr,
if (!options) {
VLOG_INFO("%s: remote deconfigured", node->name);
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)) {
ovsdb_jsonrpc_server_del_remote(node);
}
Expand Down Expand Up @@ -360,15 +361,15 @@ ovsdb_jsonrpc_server_add_remote(struct ovsdb_jsonrpc_server *svr,
struct pstream *listener;
int error;

error = jsonrpc_pstream_open(name, &listener, options->dscp);
error = jsonrpc_pstream_open(name, &listener, options->rpc.dscp);
switch (error) {
case 0:
case EAFNOSUPPORT:
remote = xmalloc(sizeof *remote);
remote->server = svr;
remote->listener = listener;
ovs_list_init(&remote->sessions);
remote->dscp = options->dscp;
remote->dscp = options->rpc.dscp;
remote->read_only = options->read_only;
remote->role = nullable_xstrdup(options->role);
shash_add(&svr->remotes, name, remote);
Expand Down Expand Up @@ -678,15 +679,6 @@ ovsdb_jsonrpc_session_run(struct ovsdb_jsonrpc_session *s)
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
ovsdb_jsonrpc_session_run_all(struct ovsdb_jsonrpc_remote *remote)
{
Expand Down Expand Up @@ -805,7 +797,7 @@ ovsdb_jsonrpc_session_set_all_options(
struct ovsdb_jsonrpc_session *s;

LIST_FOR_EACH (s, node, &remote->sessions) {
ovsdb_jsonrpc_session_set_options(s, options);
jsonrpc_session_set_options(s->js, &options->rpc);
}
}

Expand Down
5 changes: 2 additions & 3 deletions ovsdb/jsonrpc-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <stdbool.h>
#include "openvswitch/types.h"
#include "jsonrpc.h"

struct ovsdb;
struct shash;
Expand All @@ -33,10 +34,8 @@ void ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *);

/* Options for a remote. */
struct ovsdb_jsonrpc_options {
int max_backoff; /* Maximum reconnection backoff, in msec. */
int probe_interval; /* Max idle time before probing, in msec. */
struct jsonrpc_session_options rpc; /* JSON-RPC options. */
bool read_only; /* Only read-only transactions are allowed. */
int dscp; /* Dscp value for manager connections */
char *role; /* Role, for role-based access controls */
};
struct ovsdb_jsonrpc_options *ovsdb_jsonrpc_default_options(
Expand Down
31 changes: 17 additions & 14 deletions ovsdb/ovsdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ get_jsonrpc_options(const char *target, enum service_model model)

options = ovsdb_jsonrpc_default_options(target);
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) {
options->probe_interval = RELAY_SOURCE_DEFAULT_PROBE_INTERVAL;
options->rpc.probe_interval = RELAY_SOURCE_DEFAULT_PROBE_INTERVAL;
}

return options;
Expand Down Expand Up @@ -1013,14 +1013,14 @@ open_db(struct server_config *server_config,

if (model == SM_RELAY) {
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) {
const struct uuid *server_uuid;

server_uuid = ovsdb_jsonrpc_server_get_uuid(server_config->jsonrpc);
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;
}
Expand Down Expand Up @@ -1237,11 +1237,11 @@ add_manager_options(struct shash *remotes, const struct ovsdb_row *row)

options = add_remote(remotes, target, NULL);
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",
&probe_interval)) {
options->probe_interval = probe_interval;
options->rpc.probe_interval = probe_interval;
}
if (ovsdb_util_read_bool_column(row, "read_only", &read_only)) {
options->read_only = read_only;
Expand All @@ -1253,13 +1253,13 @@ add_manager_options(struct shash *remotes, const struct ovsdb_row *row)
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");
if (dscp_string) {
int dscp = atoi(dscp_string);
if (dscp >= 0 && dscp <= 63) {
options->dscp = dscp;
options->rpc.dscp = dscp;
}
}
}
Expand Down Expand Up @@ -1718,7 +1718,7 @@ ovsdb_server_connect_active_ovsdb_server(struct unixctl_conn *conn,
conf->model = SM_ACTIVE_BACKUP;
conf->source = xstrdup(*config->sync_from);
conf->options = ovsdb_jsonrpc_default_options(conf->source);
conf->options->probe_interval =
conf->options->rpc.probe_interval =
*config->replication_probe_interval;
conf->ab.sync_exclude =
nullable_xstrdup(*config->sync_exclude);
Expand All @@ -1727,7 +1727,8 @@ ovsdb_server_connect_active_ovsdb_server(struct unixctl_conn *conn,

if (conf->model == SM_ACTIVE_BACKUP && !conf->ab.backup) {
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;
}
}
Expand Down Expand Up @@ -1793,10 +1794,11 @@ ovsdb_server_set_active_ovsdb_server_probe_interval(struct unixctl_conn *conn,
struct db_config *conf = db->config;

if (conf->model == SM_ACTIVE_BACKUP) {
conf->options->probe_interval = probe_interval;
conf->options->rpc.probe_interval = probe_interval;
if (conf->ab.backup) {
replication_set_db(db->db, conf->source, conf->ab.sync_exclude,
server_uuid, conf->options->probe_interval);
server_uuid,
conf->options->rpc.probe_interval);
}
}
}
Expand Down Expand Up @@ -1832,7 +1834,7 @@ ovsdb_server_set_relay_source_interval(struct unixctl_conn *conn,
struct db_config *conf = db->config;

if (conf->model == SM_RELAY) {
conf->options->probe_interval = probe_interval;
conf->options->rpc.probe_interval = probe_interval;
}
}

Expand Down Expand Up @@ -1875,7 +1877,8 @@ ovsdb_server_set_sync_exclude_tables(struct unixctl_conn *conn,
conf->ab.sync_exclude = xstrdup(argv[1]);
if (conf->ab.backup) {
replication_set_db(db->db, conf->source, conf->ab.sync_exclude,
server_uuid, conf->options->probe_interval);
server_uuid,
conf->options->rpc.probe_interval);
}
}
}
Expand Down

0 comments on commit 7239485

Please sign in to comment.