From patchwork Tue Jan 9 22:49:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1884680 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T8mRq26zfz1yPh for ; Wed, 10 Jan 2024 09:53:11 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 7909C488B0; Tue, 9 Jan 2024 22:53:09 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 7909C488B0 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xJRB8rDqdeH5; Tue, 9 Jan 2024 22:53:08 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 406354873D; Tue, 9 Jan 2024 22:53:07 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 406354873D Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1064DC0DD2; Tue, 9 Jan 2024 22:53:07 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1A524C007C for ; Tue, 9 Jan 2024 22:53:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id ADEF5439C5 for ; Tue, 9 Jan 2024 22:52:21 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org ADEF5439C5 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id h9OzbojNlLEF for ; Tue, 9 Jan 2024 22:52:20 +0000 (UTC) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by smtp2.osuosl.org (Postfix) with ESMTPS id 6D4A943B2E for ; Tue, 9 Jan 2024 22:52:20 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 6D4A943B2E Received: by mail.gandi.net (Postfix) with ESMTPSA id 3499E60003; Tue, 9 Jan 2024 22:52:18 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Tue, 9 Jan 2024 23:49:11 +0100 Message-ID: <20240109225142.1987981-12-i.maximets@ovn.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240109225142.1987981-1-i.maximets@ovn.org> References: <20240109225142.1987981-1-i.maximets@ovn.org> MIME-Version: 1.0 X-GND-Sasl: i.maximets@ovn.org Cc: Dumitru Ceara , Ilya Maximets , Vladislav Odintsov Subject: [ovs-dev] [PATCH v2 11/17] ovsdb: Embed jsonrpc session options into ovsdb jsonrpc options. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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. Signed-off-by: Ilya Maximets Acked-by: Dumitru Ceara --- ovsdb/jsonrpc-server.c | 40 ++++++++++++++++------------------------ ovsdb/jsonrpc-server.h | 5 ++--- ovsdb/ovsdb-server.c | 31 +++++++++++++++++-------------- 3 files changed, 35 insertions(+), 41 deletions(-) diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index f3b4961f3..5b3b5f451 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -211,11 +211,12 @@ 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); - options->dscp = DSCP_DEFAULT; + 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); + rpc_opt->dscp = DSCP_DEFAULT; return options; } @@ -237,10 +238,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 interested in OVSDB-specific options. */ @@ -270,18 +271,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) { @@ -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); } @@ -360,7 +361,7 @@ 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: @@ -368,7 +369,7 @@ ovsdb_jsonrpc_server_add_remote(struct ovsdb_jsonrpc_server *svr, 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); @@ -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) { @@ -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); } } diff --git a/ovsdb/jsonrpc-server.h b/ovsdb/jsonrpc-server.h index 0d8f87da7..2fe381010 100644 --- a/ovsdb/jsonrpc-server.h +++ b/ovsdb/jsonrpc-server.h @@ -18,6 +18,7 @@ #include #include "openvswitch/types.h" +#include "jsonrpc.h" struct ovsdb; struct shash; @@ -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( diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index 3765cf066..eceed7b54 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -464,9 +464,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; @@ -1017,14 +1017,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; } @@ -1241,11 +1241,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; @@ -1257,13 +1257,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; } } } @@ -1722,7 +1722,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); @@ -1731,7 +1731,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; } } @@ -1797,10 +1798,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); } } } @@ -1836,7 +1838,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; } } @@ -1879,7 +1881,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); } } }