diff mbox series

[ovs-dev,06/22] ovsdb: Allow database itself to be read-only.

Message ID 20231214010431.1664005-7-i.maximets@ovn.org
State Superseded
Delegated to: Ilya Maximets
Headers show
Series [ovs-dev,01/22] ovsdb-server.at: Enbale debug logs in active-backup tests. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Ilya Maximets Dec. 14, 2023, 1:04 a.m. UTC
Currently, the read-only option can be set on connections or JSON-RPC
server as a whole.  However, there is no way to allow modifications in
one database, but not in the other.

Adding an internal read-only flag for a database itself.  Will be used
later for running active and backup databases in a single process.

Marking the _Server database as read only is not necessary, because
modifications of internal databases are not allowed anyway, but it
doesn't hurt.

Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---
 ovsdb/jsonrpc-server.c | 3 ++-
 ovsdb/ovsdb-server.c   | 3 +++
 ovsdb/ovsdb.c          | 2 ++
 ovsdb/ovsdb.h          | 3 +++
 4 files changed, 10 insertions(+), 1 deletion(-)

Comments

Mike Pattrick Jan. 2, 2024, 3:57 p.m. UTC | #1
On Wed, Dec 13, 2023 at 8:05 PM Ilya Maximets <i.maximets@ovn.org> wrote:
>
> Currently, the read-only option can be set on connections or JSON-RPC
> server as a whole.  However, there is no way to allow modifications in
> one database, but not in the other.
>
> Adding an internal read-only flag for a database itself.  Will be used
> later for running active and backup databases in a single process.
>
> Marking the _Server database as read only is not necessary, because
> modifications of internal databases are not allowed anyway, but it
> doesn't hurt.
>
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>

Acked-by: Mike Pattrick <mkp@redhat.com>
diff mbox series

Patch

diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c
index 45f7c8038..4ea4c7a4b 100644
--- a/ovsdb/jsonrpc-server.c
+++ b/ovsdb/jsonrpc-server.c
@@ -1148,7 +1148,8 @@  ovsdb_jsonrpc_trigger_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
     /* Insert into trigger table. */
     t = xmalloc(sizeof *t);
     bool disconnect_all = ovsdb_trigger_init(
-        &s->up, db, &t->trigger, request, time_msec(), s->read_only,
+        &s->up, db, &t->trigger, request, time_msec(),
+        s->read_only || db->read_only,
         s->remote->role, jsonrpc_session_get_id(s->js));
     t->id = json_clone(request->id);
     hmap_insert(&s->triggers, &t->hmap_node, hash);
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index 4d29043f4..c294ebe67 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -831,8 +831,11 @@  add_server_db(struct server_config *config)
 
     db->filename = xstrdup("<internal>");
     db->db = ovsdb_create(schema, ovsdb_storage_create_unbacked(NULL));
+    db->db->read_only = true;
+
     bool ok OVS_UNUSED = ovsdb_jsonrpc_server_add_db(config->jsonrpc, db->db);
     ovs_assert(ok);
+
     add_db(config, db);
 }
 
diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c
index f67b836d7..298616a64 100644
--- a/ovsdb/ovsdb.c
+++ b/ovsdb/ovsdb.c
@@ -464,6 +464,8 @@  ovsdb_create(struct ovsdb_schema *schema, struct ovsdb_storage *storage)
 
     db->n_atoms = 0;
 
+    db->read_only = false;
+
     db->is_relay = false;
     ovs_list_init(&db->txn_forward_new);
     hmap_init(&db->txn_forward_sent);
diff --git a/ovsdb/ovsdb.h b/ovsdb/ovsdb.h
index d45630e8f..325900bc6 100644
--- a/ovsdb/ovsdb.h
+++ b/ovsdb/ovsdb.h
@@ -114,6 +114,9 @@  struct ovsdb {
 
     size_t n_atoms;  /* Total number of ovsdb atoms in the database. */
 
+    bool read_only;  /* If 'true', JSON-RPC clients are not allowed to change
+                      * the data. */
+
     /* Relay mode. */
     bool is_relay;  /* True, if database is in relay mode. */
     /* List that holds transactions waiting to be forwarded to the server. */