summaryrefslogtreecommitdiff
path: root/ovsdb/storage.c
diff options
context:
space:
mode:
authorIlya Maximets <i.maximets@ovn.org>2021-06-01 21:52:08 +0200
committerIlya Maximets <i.maximets@ovn.org>2021-07-15 22:37:32 +0200
commite93fc5db9b6fd9f9e562b928d4c5ef701ebeef70 (patch)
treed1c71911867a797b1c8b4683dd0d9b13a1bfa03c /ovsdb/storage.c
parent4d9605379d827bebbc6bf52632f0b5963d982874 (diff)
downloadopenvswitch-e93fc5db9b6fd9f9e562b928d4c5ef701ebeef70.tar.gz
ovsdb: storage: Allow setting the name for the unbacked storage.
ovsdb_create() requires schema or storage to be nonnull, but in practice it requires to have schema name or a storage name to use it as a database name. Only clustered storage has a name. This means that only clustered database can be created without schema, Changing that by allowing unbacked storage to have a name. This way we can create database with unbacked storage without schema. Will be used in next commits to create database for ovsdb 'relay' service model. Acked-by: Mark D. Gray <mark.d.gray@redhat.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'ovsdb/storage.c')
-rw-r--r--ovsdb/storage.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/ovsdb/storage.c b/ovsdb/storage.c
index 40415fcf6..d727b1eac 100644
--- a/ovsdb/storage.c
+++ b/ovsdb/storage.c
@@ -45,6 +45,8 @@ struct ovsdb_storage {
struct ovsdb_log *log;
struct raft *raft;
+ char *unbacked_name; /* Name of the unbacked storage. */
+
/* All kinds of storage. */
struct ovsdb_error *error; /* If nonnull, a permanent error. */
long long next_snapshot_min; /* Earliest time to take next snapshot. */
@@ -121,12 +123,14 @@ ovsdb_storage_open_standalone(const char *filename, bool rw)
}
/* Creates and returns new storage without any backing. Nothing will be read
- * from the storage, and writes are discarded. */
+ * from the storage, and writes are discarded. If 'name' is nonnull, it will
+ * be used as a storage name. */
struct ovsdb_storage *
-ovsdb_storage_create_unbacked(void)
+ovsdb_storage_create_unbacked(const char *name)
{
struct ovsdb_storage *storage = xzalloc(sizeof *storage);
schedule_next_snapshot(storage, false);
+ storage->unbacked_name = nullable_xstrdup(name);
return storage;
}
@@ -137,6 +141,7 @@ ovsdb_storage_close(struct ovsdb_storage *storage)
ovsdb_log_close(storage->log);
raft_close(storage->raft);
ovsdb_error_destroy(storage->error);
+ free(storage->unbacked_name);
free(storage);
}
}
@@ -230,7 +235,9 @@ ovsdb_storage_wait(struct ovsdb_storage *storage)
const char *
ovsdb_storage_get_name(const struct ovsdb_storage *storage)
{
- return storage->raft ? raft_get_name(storage->raft) : NULL;
+ return storage->unbacked_name ? storage->unbacked_name
+ : storage->raft ? raft_get_name(storage->raft)
+ : NULL;
}
/* Attempts to read a log record from 'storage'.