locking was never used in a way that forced locking. We can therefor make the signature simpler, by switching form a special int to a bool.
Signed-off-by: Felix Huettner <felix.huettner@stackit.cloud> --- ovsdb/log.c | 13 ++++--------- ovsdb/log.h | 2 +- ovsdb/ovsdb-tool.c | 17 +++++++++-------- ovsdb/raft.c | 4 ++-- ovsdb/storage.c | 2 +- tests/test-ovsdb.c | 2 +- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/ovsdb/log.c b/ovsdb/log.c index 754aa7892..11d52f950 100644 --- a/ovsdb/log.c +++ b/ovsdb/log.c @@ -116,9 +116,8 @@ static uint64_t afsync_destroy(struct afsync *); * log file, use the OVSDB_MAGIC macro. To accept more than one magic string, * separate them with "|", e.g. "MAGIC 1|MAGIC 2". * - * Whether the file will be locked using lockfile_lock() depends on 'locking': - * use true to lock it, false not to lock it, or -1 to lock it only if - * 'open_mode' is a mode that allows writing. + * Whether the file will be locked using lockfile_lock() depends on 'may_lock': + * use true to lock if 'open_mode' allows writing, false not to never lock it. * * A log consists of a series of records. After opening or creating a log with * this function, the client may use ovsdb_log_read() to read any existing @@ -129,7 +128,7 @@ static uint64_t afsync_destroy(struct afsync *); struct ovsdb_error * ovsdb_log_open(const char *name, const char *magic, enum ovsdb_log_open_mode open_mode, - int locking, struct ovsdb_log **filep) + bool may_lock, struct ovsdb_log **filep) { struct lockfile *lockfile; struct ovsdb_error *error; @@ -159,11 +158,7 @@ ovsdb_log_open(const char *name, const char *magic, goto error; } - ovs_assert(locking == -1 || locking == false || locking == true); - if (locking < 0) { - locking = open_mode != OVSDB_LOG_READ_ONLY; - } - if (locking) { + if (may_lock && open_mode != OVSDB_LOG_READ_ONLY) { int retval = lockfile_lock(name, &lockfile); if (retval) { error = ovsdb_io_error(retval, "%s: failed to lock lockfile", diff --git a/ovsdb/log.h b/ovsdb/log.h index 63e5681a0..b1db234b0 100644 --- a/ovsdb/log.h +++ b/ovsdb/log.h @@ -56,7 +56,7 @@ enum ovsdb_log_open_mode { struct ovsdb_error *ovsdb_log_open(const char *name, const char *magic, enum ovsdb_log_open_mode, - int locking, struct ovsdb_log **) + bool may_lock, struct ovsdb_log **) OVS_WARN_UNUSED_RESULT; void ovsdb_log_close(struct ovsdb_log *); diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c index ed35cf6e6..5ab7988e9 100644 --- a/ovsdb/ovsdb-tool.c +++ b/ovsdb/ovsdb-tool.c @@ -278,7 +278,7 @@ do_create(struct ovs_cmdl_context *ctx) /* Create database file. */ check_ovsdb_error(ovsdb_log_open(db_file_name, OVSDB_MAGIC, - OVSDB_LOG_CREATE_EXCL, -1, &log)); + OVSDB_LOG_CREATE_EXCL, true, &log)); check_ovsdb_error(ovsdb_log_write_and_free(log, json)); check_ovsdb_error(ovsdb_log_commit_block(log)); ovsdb_log_close(log); @@ -480,7 +480,7 @@ do_db_name(struct ovs_cmdl_context *ctx) struct ovsdb_log *log; check_ovsdb_error(ovsdb_log_open(db_file_name, OVSDB_MAGIC"|"RAFT_MAGIC, - OVSDB_LOG_READ_ONLY, -1, &log)); + OVSDB_LOG_READ_ONLY, true, &log)); if (!strcmp(ovsdb_log_get_magic(log), OVSDB_MAGIC)) { struct json *schema_json; check_ovsdb_error(ovsdb_log_read(log, &schema_json)); @@ -528,7 +528,7 @@ read_cluster_metadata(const char *filename) { struct ovsdb_log *log; check_ovsdb_error(ovsdb_log_open(filename, OVSDB_MAGIC"|"RAFT_MAGIC, - OVSDB_LOG_READ_ONLY, -1, &log)); + OVSDB_LOG_READ_ONLY, true, &log)); if (strcmp(ovsdb_log_get_magic(log), RAFT_MAGIC)) { ovs_fatal(0, "%s: not a clustered database", filename); } @@ -579,7 +579,7 @@ do_db_has_magic(struct ovs_cmdl_context *ctx, const char *magic) struct ovsdb_log *log; check_ovsdb_error(ovsdb_log_open(filename, OVSDB_MAGIC"|"RAFT_MAGIC, - OVSDB_LOG_READ_ONLY, -1, &log)); + OVSDB_LOG_READ_ONLY, true, &log)); int cmp = strcmp(ovsdb_log_get_magic(log), magic); ovsdb_log_close(log); if (cmp) { @@ -1109,7 +1109,7 @@ do_show_log(struct ovs_cmdl_context *ctx) struct ovsdb_log *log; check_ovsdb_error(ovsdb_log_open(db_file_name, OVSDB_MAGIC"|"RAFT_MAGIC, - OVSDB_LOG_READ_ONLY, -1, &log)); + OVSDB_LOG_READ_ONLY, true, &log)); if (!strcmp(ovsdb_log_get_magic(log), OVSDB_MAGIC)) { do_show_log_standalone(log); } else { @@ -1284,7 +1284,7 @@ do_check_cluster(struct ovs_cmdl_context *ctx) s->filename = ctx->argv[i]; check_ovsdb_error(ovsdb_log_open(s->filename, RAFT_MAGIC, - OVSDB_LOG_READ_ONLY, -1, &s->log)); + OVSDB_LOG_READ_ONLY, true, &s->log)); struct json *json; check_ovsdb_error(ovsdb_log_read(s->log, &json)); @@ -1706,9 +1706,10 @@ do_cluster_standalone(struct ovs_cmdl_context *ctx) check_ovsdb_error(ovsdb_log_open(cluster_db_file_name, OVSDB_MAGIC"|"RAFT_MAGIC, - OVSDB_LOG_READ_ONLY, -1, &log)); + OVSDB_LOG_READ_ONLY, true, &log)); check_ovsdb_error(ovsdb_log_open(db_file_name, OVSDB_MAGIC, - OVSDB_LOG_CREATE_EXCL, -1, &db_log_data)); + OVSDB_LOG_CREATE_EXCL, true, + &db_log_data)); if (strcmp(ovsdb_log_get_magic(log), RAFT_MAGIC) != 0) { ovs_fatal(0, "Database is not clustered db.\n"); } diff --git a/ovsdb/raft.c b/ovsdb/raft.c index 9f09b0ede..e2b3eb60e 100644 --- a/ovsdb/raft.c +++ b/ovsdb/raft.c @@ -503,7 +503,7 @@ raft_create_cluster(const char *file_name, const char *name, /* Create log file. */ struct ovsdb_log *log; error = ovsdb_log_open(file_name, RAFT_MAGIC, OVSDB_LOG_CREATE_EXCL, - -1, &log); + true, &log); if (error) { return error; } @@ -621,7 +621,7 @@ raft_join_cluster(const char *file_name, /* Create log file. */ struct ovsdb_log *log; error = ovsdb_log_open(file_name, RAFT_MAGIC, OVSDB_LOG_CREATE_EXCL, - -1, &log); + true, &log); if (error) { return error; } diff --git a/ovsdb/storage.c b/ovsdb/storage.c index a736bffb6..a1fb86df9 100644 --- a/ovsdb/storage.c +++ b/ovsdb/storage.c @@ -69,7 +69,7 @@ ovsdb_storage_open__(const char *filename, bool rw, bool allow_clustered, struct ovsdb_error *error; error = ovsdb_log_open(filename, OVSDB_MAGIC"|"RAFT_MAGIC, rw ? OVSDB_LOG_READ_WRITE : OVSDB_LOG_READ_ONLY, - -1, &log); + true, &log); if (error) { return error; } diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index d3bb199ef..a2b037063 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -354,7 +354,7 @@ do_log_io(struct ovs_cmdl_context *ctx) } struct ovsdb_log *log; - check_ovsdb_error(ovsdb_log_open(name, magic, mode, -1, &log)); + check_ovsdb_error(ovsdb_log_open(name, magic, mode, true, &log)); printf("%s: open successful\n", name); struct ovsdb_log *replacement = NULL; -- 2.43.0 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev