summaryrefslogtreecommitdiff
path: root/ovsdb
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-02-08 15:23:33 -0800
committerBen Pfaff <blp@nicira.com>2011-02-15 12:24:29 -0800
commit6aa09313722406629133b375871547fb426800ef (patch)
treee949d3551517b8248b1783a4f6d87abf278051af /ovsdb
parente1ebc8cea2991e19456cb9fce54ac8167f6dbf4c (diff)
downloadopenvswitch-6aa09313722406629133b375871547fb426800ef.tar.gz
ovsdb-tool: Add commands for printing the database checksum.
Diffstat (limited to 'ovsdb')
-rw-r--r--ovsdb/SPECS4
-rw-r--r--ovsdb/ovsdb-tool.1.in31
-rw-r--r--ovsdb/ovsdb-tool.c26
-rw-r--r--ovsdb/ovsdb.c18
-rw-r--r--ovsdb/ovsdb.h6
5 files changed, 65 insertions, 20 deletions
diff --git a/ovsdb/SPECS b/ovsdb/SPECS
index 97f988265..2c83cf2a6 100644
--- a/ovsdb/SPECS
+++ b/ovsdb/SPECS
@@ -108,6 +108,7 @@ is represented by <database-schema>, as described below.
"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
@@ -121,6 +122,9 @@ is represented by <database-schema>, as described below.
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:
diff --git a/ovsdb/ovsdb-tool.1.in b/ovsdb/ovsdb-tool.1.in
index 069ab1a4d..79bd2a6af 100644
--- a/ovsdb/ovsdb-tool.1.in
+++ b/ovsdb/ovsdb-tool.1.in
@@ -23,6 +23,10 @@ ovsdb\-tool \- Open vSwitch database management utility
.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
@@ -73,24 +77,27 @@ set to their default values. All of \fIschema\fR's constraints apply
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
diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
index 2e134ce69..3730e6727 100644
--- a/ovsdb/ovsdb-tool.c
+++ b/ovsdb/ovsdb-tool.c
@@ -111,7 +111,9 @@ usage(void)
" 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",
@@ -253,6 +255,17 @@ do_db_version(int argc OVS_UNUSED, char *argv[])
}
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[])
{
const char *schema_file_name = argv[1];
@@ -264,6 +277,17 @@ do_schema_version(int argc OVS_UNUSED, char *argv[])
}
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)
{
struct json *request, *result;
@@ -435,7 +459,9 @@ static const struct command all_commands[] = {
{ "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 },
diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c
index b767d3867..46d06a0ff 100644
--- a/ovsdb/ovsdb.c
+++ b/ovsdb/ovsdb.c
@@ -1,4 +1,4 @@
-/* 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.
@@ -26,13 +26,14 @@
#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;
@@ -44,7 +45,7 @@ ovsdb_schema_clone(const struct ovsdb_schema *old)
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;
@@ -68,6 +69,7 @@ ovsdb_schema_destroy(struct ovsdb_schema *schema)
shash_destroy(&schema->tables);
free(schema->name);
free(schema->version);
+ free(schema->cksum);
free(schema);
}
@@ -129,7 +131,7 @@ struct ovsdb_error *
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;
@@ -141,7 +143,7 @@ ovsdb_schema_from_json(struct json *json, struct ovsdb_schema **schemap)
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) {
@@ -159,7 +161,8 @@ ovsdb_schema_from_json(struct json *json, struct ovsdb_schema **schemap)
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;
@@ -217,6 +220,9 @@ ovsdb_schema_to_json(const struct ovsdb_schema *schema)
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();
diff --git a/ovsdb/ovsdb.h b/ovsdb/ovsdb.h
index 642f686f0..ae743bbc5 100644
--- a/ovsdb/ovsdb.h
+++ b/ovsdb/ovsdb.h
@@ -1,4 +1,4 @@
-/* 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.
@@ -30,11 +30,13 @@ struct uuid;
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 *);