- if (memcmp(expected_sha1, actual_sha1, SHA1_DIGEST_SIZE)) {
- error = ovsdb_syntax_error(NULL, NULL, "%s: %lu bytes starting at "
- "offset %lld have SHA-1 hash "SHA1_FMT" "
- "but should have hash "SHA1_FMT,
- file->name, data_length,
- (long long int) data_offset,
- SHA1_ARGS(actual_sha1),
- SHA1_ARGS(expected_sha1));
- goto error;
+/* Saves a snapshot of 'db''s current contents as 'file_name'. If 'comment' is
+ * nonnull, then it is added along with the data contents and can be viewed
+ * with "ovsdb-tool show-log".
+ *
+ * 'locking' is passed along to ovsdb_log_open() untouched. */
+struct ovsdb_error *
+ovsdb_file_save_copy(const char *file_name, int locking,
+ const char *comment, const struct ovsdb *db)
+{
+ return ovsdb_file_save_copy__(file_name, locking, comment, db, NULL);
+}
+
+/* Opens database 'file_name', reads its schema, and closes it. On success,
+ * stores the schema into '*schemap' and returns NULL; the caller then owns the
+ * schema. On failure, returns an ovsdb_error (which the caller must destroy)
+ * and sets '*dbp' to NULL. */
+struct ovsdb_error *
+ovsdb_file_read_schema(const char *file_name, struct ovsdb_schema **schemap)
+{
+ assert(schemap != NULL);
+ return ovsdb_file_open_log(file_name, OVSDB_LOG_READ_ONLY, NULL, schemap);
+}
+\f
+/* Replica implementation. */
+
+struct ovsdb_file {
+ struct ovsdb_replica replica;
+ struct ovsdb *db;
+ struct ovsdb_log *log;
+ char *file_name;
+ long long int oldest_commit;
+ long long int next_compact;
+ unsigned int n_transactions;
+};
+
+static const struct ovsdb_replica_class ovsdb_file_class;
+
+static struct ovsdb_error *
+ovsdb_file_create(struct ovsdb *db, struct ovsdb_log *log,
+ const char *file_name,
+ long long int oldest_commit,
+ unsigned int n_transactions,
+ struct ovsdb_file **filep)
+{
+ long long int now = time_msec();
+ struct ovsdb_file *file;
+ char *abs_name;
+
+ /* Use the absolute name of the file because ovsdb-server opens its
+ * database before daemonize() chdirs to "/". */
+ abs_name = abs_file_name(NULL, file_name);
+ if (!abs_name) {
+ *filep = NULL;
+ return ovsdb_io_error(0, "could not determine current "
+ "working directory");