"name": <id> required
"version": <version> required
+ "cksum": <string> optional
"tables": {<id>: <table-schema>, ...} required
The "name" identifies the database as a whole. It must be
present. Open vSwitch semantics for "version" are described in
ovs-vswitchd.conf.db(5).
+ The "cksum" optionally reports an implementation-defined checksum
+ for the database schema.
+
<table-schema>
A JSON object with the following members:
.br
\fBovsdb\-tool \fR[\fIoptions\fR] \fBschema\-version\fI schema\fR
.br
+\fBovsdb\-tool \fR[\fIoptions\fR] \fBdb\-cksum\fI db\fR
+.br
+\fBovsdb\-tool \fR[\fIoptions\fR] \fBschema\-cksum\fI schema\fR
+.br
\fBovsdb\-tool \fR[\fIoptions\fR] \fBquery\fI db transaction\fR
.br
\fBovsdb\-tool \fR[\fIoptions\fR] \fBtransact\fI db transaction\fR
in full.
.
.IP "\fBdb\-version\fI db\fR"
-Reads \fIdb\fR and prints the version number of the schema embedded
-within the database on stdout. A schema version number has the form
-\fIx\fB.\fIy\fB.\fIz\fR. See \fBovs\-vswitchd.conf.db\fR(5) for
-details.
+.IQ "\fBschema\-version\fI schema\fR"
+Prints the version number in the schema embedded within the database
+\fIdb\fR or in the standalone schema \fIschema\fR on stdout. A schema
+version number has the form \fIx\fB.\fIy\fB.\fIz\fR. See
+\fBovs\-vswitchd.conf.db\fR(5) for details.
.IP
Schema version numbers and Open vSwitch version numbers are
independent.
.IP
-If \fIdb\fR was created before schema versioning was introduced, then
-it will not have a version number and this command will print a blank
-line.
+If \fIschema\fR or \fIdb\fR was created before schema versioning was
+introduced, then it will not have a version number and this command
+will print a blank line.
.
-.IP "\fBschema\-version\fI schema\fR"
-Reads \fIschema\fR and prints the schema's version number on stdout.
+.IP "\fBdb\-cksum\fI db\fR"
+.IQ "\fBschema\-cksum\fI schema\fR"
+Prints the checksum in the schema embedded within the database
+\fIdb\fR or of the standalone schema \fIschema\fR on stdout.
.IP
-If \fIschema\fR was created before versioning was introduced, then it
-does not have a version number and this command will print a blank
-line.
+If \fIschema\fR or \fIdb\fR was created before schema versioning was
+introduced, then it will not have a version number and this command
+will print a blank line.
.
.IP "\fBquery\fI db transaction\fR"
Opens \fIdb\fR, executes \fItransaction\fR on it, and prints the
" compact DB [DST] compact DB in-place (or to DST)\n"
" convert DB SCHEMA [DST] convert DB to SCHEMA (to DST)\n"
" db-version DB report version of schema used by DB\n"
+ " db-cksum DB report checksum of schema used by DB\n"
" schema-version SCHEMA report SCHEMA's schema version\n"
+ " schema-cksum SCHEMA report SCHEMA's checksum\n"
" query DB TRNS execute read-only transaction on DB\n"
" transact DB TRNS execute read/write transaction on DB\n"
" show-log DB prints information about DB's log entries\n",
ovsdb_schema_destroy(schema);
}
+static void
+do_db_cksum(int argc OVS_UNUSED, char *argv[])
+{
+ const char *db_file_name = argv[1];
+ struct ovsdb_schema *schema;
+
+ check_ovsdb_error(ovsdb_file_read_schema(db_file_name, &schema));
+ puts(schema->cksum);
+ ovsdb_schema_destroy(schema);
+}
+
static void
do_schema_version(int argc OVS_UNUSED, char *argv[])
{
ovsdb_schema_destroy(schema);
}
+static void
+do_schema_cksum(int argc OVS_UNUSED, char *argv[])
+{
+ const char *schema_file_name = argv[1];
+ struct ovsdb_schema *schema;
+
+ check_ovsdb_error(ovsdb_schema_from_file(schema_file_name, &schema));
+ puts(schema->cksum);
+ ovsdb_schema_destroy(schema);
+}
+
static void
transact(bool read_only, const char *db_file_name, const char *transaction)
{
{ "compact", 1, 2, do_compact },
{ "convert", 2, 3, do_convert },
{ "db-version", 1, 1, do_db_version },
+ { "db-cksum", 1, 1, do_db_cksum },
{ "schema-version", 1, 1, do_schema_version },
+ { "schema-cksum", 1, 1, do_schema_cksum },
{ "query", 2, 2, do_query },
{ "transact", 2, 2, do_transact },
{ "show-log", 1, 1, do_show_log },
-/* Copyright (c) 2009, 2010 Nicira Networks
+/* Copyright (c) 2009, 2010, 2011 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "transaction.h"
struct ovsdb_schema *
-ovsdb_schema_create(const char *name, const char *version)
+ovsdb_schema_create(const char *name, const char *version, const char *cksum)
{
struct ovsdb_schema *schema;
schema = xzalloc(sizeof *schema);
schema->name = xstrdup(name);
schema->version = xstrdup(version);
+ schema->cksum = xstrdup(cksum);
shash_init(&schema->tables);
return schema;
struct ovsdb_schema *new;
struct shash_node *node;
- new = ovsdb_schema_create(old->name, old->version);
+ new = ovsdb_schema_create(old->name, old->version, old->cksum);
SHASH_FOR_EACH (node, &old->tables) {
const struct ovsdb_table_schema *ts = node->data;
shash_destroy(&schema->tables);
free(schema->name);
free(schema->version);
+ free(schema->cksum);
free(schema);
}
ovsdb_schema_from_json(struct json *json, struct ovsdb_schema **schemap)
{
struct ovsdb_schema *schema;
- const struct json *name, *tables, *version_json;
+ const struct json *name, *tables, *version_json, *cksum;
struct ovsdb_error *error;
struct shash_node *node;
struct ovsdb_parser parser;
name = ovsdb_parser_member(&parser, "name", OP_ID);
version_json = ovsdb_parser_member(&parser, "version",
OP_STRING | OP_OPTIONAL);
- ovsdb_parser_member(&parser, "cksum", OP_STRING | OP_OPTIONAL);
+ cksum = ovsdb_parser_member(&parser, "cksum", OP_STRING | OP_OPTIONAL);
tables = ovsdb_parser_member(&parser, "tables", OP_OBJECT);
error = ovsdb_parser_finish(&parser);
if (error) {
version = "";
}
- schema = ovsdb_schema_create(json_string(name), version);
+ schema = ovsdb_schema_create(json_string(name), version,
+ cksum ? json_string(cksum) : "");
SHASH_FOR_EACH (node, json_object(tables)) {
struct ovsdb_table_schema *table;
if (schema->version[0]) {
json_object_put_string(json, "version", schema->version);
}
+ if (schema->cksum[0]) {
+ json_object_put_string(json, "cksum", schema->cksum);
+ }
tables = json_object_create();
-/* Copyright (c) 2009, 2010 Nicira Networks
+/* Copyright (c) 2009, 2010, 2011 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
struct ovsdb_schema {
char *name;
char *version;
+ char *cksum;
struct shash tables; /* Contains "struct ovsdb_table_schema *"s. */
};
struct ovsdb_schema *ovsdb_schema_create(const char *name,
- const char *version);
+ const char *version,
+ const char *cksum);
struct ovsdb_schema *ovsdb_schema_clone(const struct ovsdb_schema *);
void ovsdb_schema_destroy(struct ovsdb_schema *);
"columns": {
"number": {"type": "integer"},
"name": {"type": "string"}}}},
- "version": "5.1.3"}]])
+ "version": "5.1.3",
+ "cksum": "12345678 9"}]])
m4_define([CONSTRAINT_SCHEMA],
[[{"name": "constraints",
[0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
dnl Check that all the crap is in fact in the database log.
AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
- [[{"name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}}}},"version":"5.1.3"}
+ [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}}}},"version":"5.1.3"}
{"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
{"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
{"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
[0], [stdout], [ignore])
dnl Check that all the crap is in fact in the database log.
AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
- [[{"name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}}}},"version":"5.1.3"}
+ [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}}}},"version":"5.1.3"}
{"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
{"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
{"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
AT_CHECK([ovsdb-tool db-version db], [0], [5.1.3
])
AT_CLEANUP
+
+AT_SETUP([ovsdb-tool schema-cksum])
+AT_KEYWORDS([ovsdb file positive])
+AT_DATA([schema], [ORDINAL_SCHEMA
+])
+AT_CHECK([ovsdb-tool schema-cksum schema], [0], [12345678 9
+])
+AT_CLEANUP
+
+AT_SETUP([ovsdb-tool db-cksum])
+AT_KEYWORDS([ovsdb file positive])
+AT_DATA([schema], [ORDINAL_SCHEMA
+])
+touch .db.~lock~
+AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
+AT_CHECK([ovsdb-tool db-cksum db], [0], [12345678 9
+])
+AT_CLEANUP