2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 09:58:01 +00:00

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>
This commit is contained in:
Ilya Maximets 2021-06-01 21:52:08 +02:00
parent 4d9605379d
commit e93fc5db9b
5 changed files with 16 additions and 9 deletions

View File

@ -318,7 +318,7 @@ ovsdb_convert(const struct ovsdb *src, const struct ovsdb_schema *new_schema,
struct ovsdb **dstp)
{
struct ovsdb *dst = ovsdb_create(ovsdb_schema_clone(new_schema),
ovsdb_storage_create_unbacked());
ovsdb_storage_create_unbacked(NULL));
struct ovsdb_txn *txn = ovsdb_txn_create(dst);
struct ovsdb_error *error = NULL;

View File

@ -736,7 +736,7 @@ add_server_db(struct server_config *config)
/* We don't need txn_history for server_db. */
db->filename = xstrdup("<internal>");
db->db = ovsdb_create(schema, ovsdb_storage_create_unbacked());
db->db = ovsdb_create(schema, ovsdb_storage_create_unbacked(NULL));
bool ok OVS_UNUSED = ovsdb_jsonrpc_server_add_db(config->jsonrpc, db->db);
ovs_assert(ok);
add_db(config, db);

View File

@ -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'.

View File

@ -29,7 +29,7 @@ struct uuid;
struct ovsdb_error *ovsdb_storage_open(const char *filename, bool rw,
struct ovsdb_storage **)
OVS_WARN_UNUSED_RESULT;
struct ovsdb_storage *ovsdb_storage_create_unbacked(void);
struct ovsdb_storage *ovsdb_storage_create_unbacked(const char *name);
void ovsdb_storage_close(struct ovsdb_storage *);
const char *ovsdb_storage_get_model(const struct ovsdb_storage *);

View File

@ -1485,7 +1485,7 @@ do_execute__(struct ovs_cmdl_context *ctx, bool ro)
json = parse_json(ctx->argv[1]);
check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
json_destroy(json);
db = ovsdb_create(schema, ovsdb_storage_create_unbacked());
db = ovsdb_create(schema, ovsdb_storage_create_unbacked(NULL));
for (i = 2; i < ctx->argc; i++) {
struct json *params, *result;
@ -1551,7 +1551,7 @@ do_trigger(struct ovs_cmdl_context *ctx)
json = parse_json(ctx->argv[1]);
check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
json_destroy(json);
db = ovsdb_create(schema, ovsdb_storage_create_unbacked());
db = ovsdb_create(schema, ovsdb_storage_create_unbacked(NULL));
ovsdb_server_init(&server);
ovsdb_server_add_db(&server, db);
@ -1781,7 +1781,7 @@ do_transact(struct ovs_cmdl_context *ctx)
" \"j\": {\"type\": \"integer\"}}}}}");
check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
json_destroy(json);
do_transact_db = ovsdb_create(schema, ovsdb_storage_create_unbacked());
do_transact_db = ovsdb_create(schema, ovsdb_storage_create_unbacked(NULL));
do_transact_table = ovsdb_get_table(do_transact_db, "mytable");
ovs_assert(do_transact_table != NULL);