summaryrefslogtreecommitdiff
path: root/ovsdb
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2009-11-13 13:23:35 -0800
committerBen Pfaff <blp@nicira.com>2009-11-16 10:55:27 -0800
commit41709cccb8099972f9c6c3faf583b1286cb92e8a (patch)
tree87e13ec8a4dcd307f047eef0b38a6eebb05ff683 /ovsdb
parent6e79e2104c95e005e81a070053a3dc99a2bfde09 (diff)
downloadopenvswitch-41709cccb8099972f9c6c3faf583b1286cb92e8a.tar.gz
ovsdb: Rename ovsdb_file to ovsdb_log.
This prepares for introducing a new, higher-level ovsdb_file that encapsulates ovsdb storage in a file.
Diffstat (limited to 'ovsdb')
-rw-r--r--ovsdb/automake.mk4
-rw-r--r--ovsdb/execution.c8
-rw-r--r--ovsdb/log.c (renamed from ovsdb/file.c)43
-rw-r--r--ovsdb/log.h (renamed from ovsdb/file.h)20
-rw-r--r--ovsdb/ovsdb-tool.c14
-rw-r--r--ovsdb/ovsdb.c20
-rw-r--r--ovsdb/ovsdb.h4
7 files changed, 58 insertions, 55 deletions
diff --git a/ovsdb/automake.mk b/ovsdb/automake.mk
index 04fa52da1..b996a306f 100644
--- a/ovsdb/automake.mk
+++ b/ovsdb/automake.mk
@@ -6,10 +6,10 @@ ovsdb_libovsdb_a_SOURCES = \
ovsdb/condition.c \
ovsdb/condition.h \
ovsdb/execution.c \
- ovsdb/file.c \
- ovsdb/file.h \
ovsdb/jsonrpc-server.c \
ovsdb/jsonrpc-server.h \
+ ovsdb/log.c \
+ ovsdb/log.h \
ovsdb/ovsdb-server.c \
ovsdb/ovsdb.c \
ovsdb/ovsdb.h \
diff --git a/ovsdb/execution.c b/ovsdb/execution.c
index f3e917260..6bad67c2b 100644
--- a/ovsdb/execution.c
+++ b/ovsdb/execution.c
@@ -20,8 +20,8 @@
#include "column.h"
#include "condition.h"
-#include "file.h"
#include "json.h"
+#include "log.h"
#include "ovsdb-data.h"
#include "ovsdb-error.h"
#include "ovsdb-parser.h"
@@ -211,7 +211,7 @@ ovsdb_execute_abort(struct ovsdb_execution *x UNUSED,
static struct ovsdb_error *
do_commit(struct ovsdb_execution *x)
{
- if (x->db->file) {
+ if (x->db->log) {
struct ovsdb_error *error;
struct json *json;
@@ -221,14 +221,14 @@ do_commit(struct ovsdb_execution *x)
return NULL;
}
- error = ovsdb_file_write(x->db->file, json);
+ error = ovsdb_log_write(x->db->log, json);
json_destroy(json);
if (error) {
return ovsdb_wrap_error(error, "writing transaction failed");
}
if (x->durable) {
- error = ovsdb_file_commit(x->db->file);
+ error = ovsdb_log_commit(x->db->log);
if (error) {
return ovsdb_wrap_error(error,
"committing transaction failed");
diff --git a/ovsdb/file.c b/ovsdb/log.c
index 4883d76f1..9c2e277ce 100644
--- a/ovsdb/file.c
+++ b/ovsdb/log.c
@@ -15,7 +15,7 @@
#include <config.h>
-#include "file.h"
+#include "log.h"
#include <assert.h>
#include <errno.h>
@@ -26,34 +26,36 @@
#include "json.h"
#include "lockfile.h"
+#include "ovsdb.h"
#include "ovsdb-error.h"
#include "sha1.h"
+#include "transaction.h"
#include "util.h"
-#define THIS_MODULE VLM_ovsdb_file
+#define THIS_MODULE VLM_ovsdb_log
#include "vlog.h"
-enum ovsdb_file_mode {
- OVSDB_FILE_READ,
- OVSDB_FILE_WRITE
+enum ovsdb_log_mode {
+ OVSDB_LOG_READ,
+ OVSDB_LOG_WRITE
};
-struct ovsdb_file {
+struct ovsdb_log {
off_t offset;
char *name;
struct lockfile *lockfile;
FILE *stream;
struct ovsdb_error *read_error;
struct ovsdb_error *write_error;
- enum ovsdb_file_mode mode;
+ enum ovsdb_log_mode mode;
};
struct ovsdb_error *
-ovsdb_file_open(const char *name, int flags, struct ovsdb_file **filep)
+ovsdb_log_open(const char *name, int flags, struct ovsdb_log **filep)
{
struct lockfile *lockfile;
struct ovsdb_error *error;
- struct ovsdb_file *file;
+ struct ovsdb_log *file;
struct stat s;
FILE *stream;
int accmode;
@@ -111,7 +113,7 @@ ovsdb_file_open(const char *name, int flags, struct ovsdb_file **filep)
file->offset = 0;
file->read_error = NULL;
file->write_error = NULL;
- file->mode = OVSDB_FILE_READ;
+ file->mode = OVSDB_LOG_READ;
*filep = file;
return NULL;
@@ -124,7 +126,7 @@ error:
}
void
-ovsdb_file_close(struct ovsdb_file *file)
+ovsdb_log_close(struct ovsdb_log *file)
{
if (file) {
free(file->name);
@@ -170,15 +172,15 @@ parse_header(char *header, unsigned long int *length,
return true;
}
-struct ovsdb_file_read_cbdata {
+struct ovsdb_log_read_cbdata {
char input[4096];
- struct ovsdb_file *file;
+ struct ovsdb_log *file;
int error;
unsigned long length;
};
static struct ovsdb_error *
-parse_body(struct ovsdb_file *file, off_t offset, unsigned long int length,
+parse_body(struct ovsdb_log *file, off_t offset, unsigned long int length,
uint8_t sha1[SHA1_DIGEST_SIZE], struct json **jsonp)
{
unsigned long int bytes_left;
@@ -212,7 +214,7 @@ parse_body(struct ovsdb_file *file, off_t offset, unsigned long int length,
}
struct ovsdb_error *
-ovsdb_file_read(struct ovsdb_file *file, struct json **jsonp)
+ovsdb_log_read(struct ovsdb_log *file, struct json **jsonp)
{
uint8_t expected_sha1[SHA1_DIGEST_SIZE];
uint8_t actual_sha1[SHA1_DIGEST_SIZE];
@@ -226,7 +228,7 @@ ovsdb_file_read(struct ovsdb_file *file, struct json **jsonp)
if (file->read_error) {
return ovsdb_error_clone(file->read_error);
- } else if (file->mode == OVSDB_FILE_WRITE) {
+ } else if (file->mode == OVSDB_LOG_WRITE) {
return OVSDB_BUG("reading file in write mode");
}
@@ -284,7 +286,7 @@ error:
}
struct ovsdb_error *
-ovsdb_file_write(struct ovsdb_file *file, struct json *json)
+ovsdb_log_write(struct ovsdb_log *file, struct json *json)
{
uint8_t sha1[SHA1_DIGEST_SIZE];
struct ovsdb_error *error;
@@ -296,8 +298,8 @@ ovsdb_file_write(struct ovsdb_file *file, struct json *json)
if (file->write_error) {
return ovsdb_error_clone(file->write_error);
- } else if (file->mode == OVSDB_FILE_READ) {
- file->mode = OVSDB_FILE_WRITE;
+ } else if (file->mode == OVSDB_LOG_READ) {
+ file->mode = OVSDB_LOG_WRITE;
if (fseeko(file->stream, file->offset, SEEK_SET)) {
error = ovsdb_io_error(errno, "%s: cannot seek to offset %lld",
file->name, (long long int) file->offset);
@@ -351,10 +353,11 @@ error:
}
struct ovsdb_error *
-ovsdb_file_commit(struct ovsdb_file *file)
+ovsdb_log_commit(struct ovsdb_log *file)
{
if (fsync(fileno(file->stream))) {
return ovsdb_io_error(errno, "%s: fsync failed", file->name);
}
return 0;
}
+
diff --git a/ovsdb/file.h b/ovsdb/log.h
index 5178140a1..2daa635ba 100644
--- a/ovsdb/file.h
+++ b/ovsdb/log.h
@@ -13,24 +13,24 @@
* limitations under the License.
*/
-#ifndef OVSDB_FILE_H
-#define OVSDB_FILE_H 1
+#ifndef OVSDB_LOG_H
+#define OVSDB_LOG_H 1
#include <sys/types.h>
#include "compiler.h"
struct json;
-struct ovsdb_file;
+struct ovsdb_log;
-struct ovsdb_error *ovsdb_file_open(const char *name, int flags,
- struct ovsdb_file **) WARN_UNUSED_RESULT;
-void ovsdb_file_close(struct ovsdb_file *);
+struct ovsdb_error *ovsdb_log_open(const char *name, int flags,
+ struct ovsdb_log **) WARN_UNUSED_RESULT;
+void ovsdb_log_close(struct ovsdb_log *);
-struct ovsdb_error *ovsdb_file_read(struct ovsdb_file *, struct json **)
+struct ovsdb_error *ovsdb_log_read(struct ovsdb_log *, struct json **)
WARN_UNUSED_RESULT;
-struct ovsdb_error *ovsdb_file_write(struct ovsdb_file *, struct json *)
+struct ovsdb_error *ovsdb_log_write(struct ovsdb_log *, struct json *)
WARN_UNUSED_RESULT;
-struct ovsdb_error *ovsdb_file_commit(struct ovsdb_file *)
+struct ovsdb_error *ovsdb_log_commit(struct ovsdb_log *)
WARN_UNUSED_RESULT;
-#endif /* ovsdb/file.h */
+#endif /* ovsdb/log.h */
diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
index d6e0ff941..8b81ef615 100644
--- a/ovsdb/ovsdb-tool.c
+++ b/ovsdb/ovsdb-tool.c
@@ -24,7 +24,7 @@
#include "command-line.h"
#include "compiler.h"
-#include "file.h"
+#include "log.h"
#include "json.h"
#include "ovsdb.h"
#include "ovsdb-error.h"
@@ -144,7 +144,7 @@ do_create(int argc UNUSED, char *argv[])
const char *db_file_name = argv[1];
const char *schema_file_name = argv[2];
struct ovsdb_schema *schema;
- struct ovsdb_file *db_file;
+ struct ovsdb_log *log;
struct json *json;
/* Read schema from file and convert to JSON. */
@@ -152,11 +152,11 @@ do_create(int argc UNUSED, char *argv[])
json = ovsdb_schema_to_json(schema);
/* Create database file. */
- check_ovsdb_error(ovsdb_file_open(db_file_name, O_RDWR | O_CREAT | O_EXCL,
- &db_file));
- check_ovsdb_error(ovsdb_file_write(db_file, json));
- check_ovsdb_error(ovsdb_file_commit(db_file));
- ovsdb_file_close(db_file);
+ check_ovsdb_error(ovsdb_log_open(db_file_name, O_RDWR | O_CREAT | O_EXCL,
+ &log));
+ check_ovsdb_error(ovsdb_log_write(log, json));
+ check_ovsdb_error(ovsdb_log_commit(log));
+ ovsdb_log_close(log);
json_destroy(json);
}
diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c
index 6d0f131ea..7caa229da 100644
--- a/ovsdb/ovsdb.c
+++ b/ovsdb/ovsdb.c
@@ -19,7 +19,7 @@
#include <fcntl.h>
-#include "file.h"
+#include "log.h"
#include "json.h"
#include "ovsdb-error.h"
#include "ovsdb-parser.h"
@@ -153,14 +153,14 @@ ovsdb_schema_to_json(const struct ovsdb_schema *schema)
}
struct ovsdb *
-ovsdb_create(struct ovsdb_file *file, struct ovsdb_schema *schema)
+ovsdb_create(struct ovsdb_log *log, struct ovsdb_schema *schema)
{
struct shash_node *node;
struct ovsdb *db;
db = xmalloc(sizeof *db);
db->schema = schema;
- db->file = file;
+ db->log = log;
list_init(&db->triggers);
db->run_triggers = false;
@@ -178,16 +178,16 @@ 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 ovsdb_log *log;
struct json *json;
struct ovsdb *db;
- error = ovsdb_file_open(file_name, read_only ? O_RDONLY : O_RDWR, &file);
+ error = ovsdb_log_open(file_name, read_only ? O_RDONLY : O_RDWR, &log);
if (error) {
return error;
}
- error = ovsdb_file_read(file, &json);
+ error = ovsdb_log_read(log, &json);
if (error) {
return error;
} else if (!json) {
@@ -204,8 +204,8 @@ ovsdb_open(const char *file_name, bool read_only, struct ovsdb **dbp)
}
json_destroy(json);
- db = ovsdb_create(read_only ? NULL : file, schema);
- while ((error = ovsdb_file_read(file, &json)) == NULL && json) {
+ db = ovsdb_create(read_only ? NULL : log, schema);
+ while ((error = ovsdb_log_read(log, &json)) == NULL && json) {
struct ovsdb_txn *txn;
error = ovsdb_txn_from_json(db, json, &txn);
@@ -225,7 +225,7 @@ ovsdb_open(const char *file_name, bool read_only, struct ovsdb **dbp)
}
if (read_only) {
- ovsdb_file_close(file);
+ ovsdb_log_close(log);
}
*dbp = db;
@@ -251,7 +251,7 @@ ovsdb_destroy(struct ovsdb *db)
shash_clear(&db->schema->tables);
ovsdb_schema_destroy(db->schema);
- ovsdb_file_close(db->file);
+ ovsdb_log_close(db->log);
free(db);
}
}
diff --git a/ovsdb/ovsdb.h b/ovsdb/ovsdb.h
index 3f62966a7..d57ebfca6 100644
--- a/ovsdb/ovsdb.h
+++ b/ovsdb/ovsdb.h
@@ -46,7 +46,7 @@ struct json *ovsdb_schema_to_json(const struct ovsdb_schema *);
/* Database. */
struct ovsdb {
struct ovsdb_schema *schema;
- struct ovsdb_file *file; /* Disk file (null for in-memory db). */
+ struct ovsdb_log *log; /* Disk log (null for in-memory db). */
struct shash tables; /* Contains "struct ovsdb_table *"s. */
/* Triggers. */
@@ -54,7 +54,7 @@ struct ovsdb {
bool run_triggers;
};
-struct ovsdb *ovsdb_create(struct ovsdb_file *, struct ovsdb_schema *);
+struct ovsdb *ovsdb_create(struct ovsdb_log *, struct ovsdb_schema *);
struct ovsdb_error *ovsdb_open(const char *file_name, bool read_only,
struct ovsdb **)
WARN_UNUSED_RESULT;