Skip to content

Commit

Permalink
ovsdb: Rename ovsdb_file to ovsdb_log.
Browse files Browse the repository at this point in the history
This prepares for introducing a new, higher-level ovsdb_file that
encapsulates ovsdb storage in a file.
  • Loading branch information
blp committed Nov 16, 2009
1 parent 6e79e21 commit 41709cc
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 121 deletions.
2 changes: 1 addition & 1 deletion lib/vlog-modules.def
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ VLOG_MODULE(ofproto)
VLOG_MODULE(openflowd)
VLOG_MODULE(ovsdb)
VLOG_MODULE(ovsdb_client)
VLOG_MODULE(ovsdb_file)
VLOG_MODULE(ovsdb_log)
VLOG_MODULE(ovsdb_jsonrpc_server)
VLOG_MODULE(ovsdb_server)
VLOG_MODULE(ovsdb_tool)
Expand Down
4 changes: 2 additions & 2 deletions ovsdb/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
8 changes: 4 additions & 4 deletions ovsdb/execution.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand All @@ -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");
Expand Down
43 changes: 23 additions & 20 deletions ovsdb/file.c → ovsdb/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include <config.h>

#include "file.h"
#include "log.h"

#include <assert.h>
#include <errno.h>
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -124,7 +126,7 @@ ovsdb_file_open(const char *name, int flags, struct ovsdb_file **filep)
}

void
ovsdb_file_close(struct ovsdb_file *file)
ovsdb_log_close(struct ovsdb_log *file)
{
if (file) {
free(file->name);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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");
}

Expand Down Expand Up @@ -284,7 +286,7 @@ ovsdb_file_read(struct ovsdb_file *file, struct json **jsonp)
}

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;
Expand All @@ -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);
Expand Down Expand Up @@ -351,10 +353,11 @@ ovsdb_file_write(struct ovsdb_file *file, struct json *json)
}

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;
}

20 changes: 10 additions & 10 deletions ovsdb/file.h → ovsdb/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
14 changes: 7 additions & 7 deletions ovsdb/ovsdb-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -144,19 +144,19 @@ 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. */
check_ovsdb_error(ovsdb_schema_from_file(schema_file_name, &schema));
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);
}
Expand Down
20 changes: 10 additions & 10 deletions ovsdb/ovsdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <fcntl.h>

#include "file.h"
#include "log.h"
#include "json.h"
#include "ovsdb-error.h"
#include "ovsdb-parser.h"
Expand Down Expand Up @@ -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;

Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions ovsdb/ovsdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ 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. */
struct list triggers; /* Contains "struct ovsdb_trigger"s. */
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;
Expand Down
2 changes: 1 addition & 1 deletion tests/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TESTSUITE_AT = \
tests/lockfile.at \
tests/reconnect.at \
tests/ovsdb.at \
tests/ovsdb-file.at \
tests/ovsdb-log.at \
tests/ovsdb-types.at \
tests/ovsdb-data.at \
tests/ovsdb-column.at \
Expand Down
Loading

0 comments on commit 41709cc

Please sign in to comment.