datapath: Add missing definitions for building GRE on older kernels
[sliver-openvswitch.git] / ovsdb / ovsdb-tool.c
index d6e0ff9..c318be5 100644 (file)
@@ -25,6 +25,7 @@
 #include "command-line.h"
 #include "compiler.h"
 #include "file.h"
+#include "log.h"
 #include "json.h"
 #include "ovsdb.h"
 #include "ovsdb-error.h"
@@ -102,7 +103,8 @@ usage(void)
            "  compact DB [DST]   compact DB in-place (or to DST)\n"
            "  extract-schema DB  print DB's schema on stdout\n"
            "  query DB TRNS      execute read-only transaction on DB\n"
-           "  transact DB TRNS   execute read/write 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",
            program_name, program_name);
     vlog_usage();
     printf("\nOther options:\n"
@@ -144,7 +146,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 +154,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);
 }
@@ -167,7 +169,7 @@ transact(bool read_only, const char *db_file_name, const char *transaction)
     struct json *request, *result;
     struct ovsdb *db;
 
-    check_ovsdb_error(ovsdb_open(db_file_name, read_only, &db));
+    check_ovsdb_error(ovsdb_file_open(db_file_name, read_only, &db));
 
     request = parse_json(transaction);
     result = ovsdb_execute(db, request, 0, NULL);
@@ -189,6 +191,45 @@ do_transact(int argc UNUSED, char *argv[])
     transact(false, argv[1], argv[2]);
 }
 
+static void
+do_show_log(int argc UNUSED, char *argv[])
+{
+    const char *db_file_name = argv[1];
+    struct ovsdb_log *log;
+    unsigned int i;
+
+    check_ovsdb_error(ovsdb_log_open(db_file_name, O_RDONLY, &log));
+    for (i = 0; ; i++) {
+        struct json *json;
+
+        check_ovsdb_error(ovsdb_log_read(log, &json));
+        if (!json) {
+            break;
+        }
+
+        printf("record %u:", i);
+        if (json->type == JSON_OBJECT) {
+            struct json *date, *comment;
+
+            date = shash_find_data(json_object(json), "_date");
+            if (date && date->type == JSON_INTEGER) {
+                time_t t = json_integer(date);
+                char s[128];
+
+                strftime(s, sizeof s, "%Y-%m-%d %H:%M:%S", localtime(&t));
+                printf(" %s", s);
+            }
+
+            comment = shash_find_data(json_object(json), "_comment");
+            if (comment && comment->type == JSON_STRING) {
+                printf(" \"%s\"", json_string(comment));
+            }
+        }
+        json_destroy(json);
+        putchar('\n');
+    }
+}
+
 static void
 do_help(int argc UNUSED, char *argv[] UNUSED)
 {
@@ -199,6 +240,7 @@ static const struct command all_commands[] = {
     { "create", 2, 2, do_create },
     { "query", 2, 2, do_query },
     { "transact", 2, 2, do_transact },
+    { "show-log", 1, 1, do_show_log },
     { "help", 0, INT_MAX, do_help },
     { NULL, 0, 0, NULL },
 };