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 <[email protected]>
---
 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(-)

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. */
-- 
2.43.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to