-struct ovsdb_error *
-ovsdb_open(const char *file_name, bool read_only, struct ovsdb **dbp)
-{
- struct ovsdb_schema *schema;
- struct ovsdb_error *error;
- struct ovsdb_file *file;
- struct json *json;
- struct ovsdb *db;
-
- error = ovsdb_file_open(file_name, read_only ? O_RDONLY : O_RDWR, &file);
- if (error) {
- return error;
- }
-
- error = ovsdb_file_read(file, &json);
- if (error) {
- return error;
- } else if (!json) {
- return ovsdb_io_error(EOF, "%s: database file contains no schema",
- file_name);
- }
-
- error = ovsdb_schema_from_json(json, &schema);
- if (error) {
- json_destroy(json);
- return ovsdb_wrap_error(error,
- "failed to parse \"%s\" as ovsdb schema",
- file_name);
- }
- json_destroy(json);
-
- db = ovsdb_create(read_only ? file : NULL, schema);
- while ((error = ovsdb_file_read(file, &json)) == NULL && json) {
- struct ovsdb_txn *txn;
-
- error = ovsdb_txn_from_json(db, json, &txn);
- json_destroy(json);
- if (error) {
- break;
- }
-
- ovsdb_txn_commit(txn);
- }
- if (error) {
- char *msg = ovsdb_error_to_string(error);
- VLOG_WARN("%s", msg);
- free(msg);
-
- ovsdb_error_destroy(error);
- }
-
- if (read_only) {
- ovsdb_file_close(file);
- }
-
- *dbp = db;
- return NULL;
-}
-