datapath: Fix buffer overrun in mask array realloc.
[cascardo/ovs.git] / lib / ovsdb-idl.c
index 4631291..5c4d93b 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 
 #include "bitmap.h"
+#include "coverage.h"
 #include "dynamic-string.h"
 #include "fatal-signal.h"
 #include "json.h"
 
 VLOG_DEFINE_THIS_MODULE(ovsdb_idl);
 
+COVERAGE_DEFINE(txn_uncommitted);
+COVERAGE_DEFINE(txn_unchanged);
+COVERAGE_DEFINE(txn_incomplete);
+COVERAGE_DEFINE(txn_aborted);
+COVERAGE_DEFINE(txn_success);
+COVERAGE_DEFINE(txn_try_again);
+COVERAGE_DEFINE(txn_not_locked);
+COVERAGE_DEFINE(txn_error);
+
 /* An arc from one idl_row to another.  When row A contains a UUID that
  * references row B, this is represented by an arc from A (the source) to B
  * (the destination).
@@ -332,9 +342,6 @@ ovsdb_idl_run(struct ovsdb_idl *idl)
                    && !strcmp(msg->method, "stolen")) {
             /* Someone else stole our lock. */
             ovsdb_idl_parse_lock_notify(idl, msg->params, false);
-        } else if (msg->type == JSONRPC_REPLY && msg->id->type == JSON_STRING
-                   && !strcmp(msg->id->u.string, "echo")) {
-            /* Reply to our echo request.  Ignore it. */
         } else if ((msg->type == JSONRPC_ERROR
                     || msg->type == JSONRPC_REPLY)
                    && ovsdb_idl_txn_process_reply(idl, msg)) {
@@ -397,6 +404,14 @@ ovsdb_idl_has_ever_connected(const struct ovsdb_idl *idl)
     return ovsdb_idl_get_seqno(idl) != 0;
 }
 
+/* Reconfigures 'idl' so that it would reconnect to the database, if
+ * connection was dropped. */
+void
+ovsdb_idl_enable_reconnect(struct ovsdb_idl *idl)
+{
+    jsonrpc_session_enable_reconnect(idl->session);
+}
+
 /* Forces 'idl' to drop its connection to the database and reconnect.  In the
  * meantime, the contents of 'idl' will not change. */
 void
@@ -444,7 +459,7 @@ ovsdb_idl_get_mode(struct ovsdb_idl *idl,
         }
     }
 
-    NOT_REACHED();
+    OVS_NOT_REACHED();
 }
 
 static void
@@ -508,7 +523,7 @@ ovsdb_idl_add_table(struct ovsdb_idl *idl,
         }
     }
 
-    NOT_REACHED();
+    OVS_NOT_REACHED();
 }
 
 /* Turns off OVSDB_IDL_ALERT for 'column' in 'idl'.
@@ -1519,14 +1534,13 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn)
     bool any_updates;
 
     if (txn != txn->idl->txn) {
-        return txn->status;
+        goto coverage_out;
     }
 
     /* If we need a lock but don't have it, give up quickly. */
     if (txn->idl->lock_name && !ovsdb_idl_has_lock(txn->idl)) {
         txn->status = TXN_NOT_LOCKED;
-        ovsdb_idl_txn_disassemble(txn);
-        return txn->status;
+        goto disassemble_out;
     }
 
     operations = json_array_create_1(
@@ -1710,7 +1724,20 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn)
         txn->status = TXN_TRY_AGAIN;
     }
 
+disassemble_out:
     ovsdb_idl_txn_disassemble(txn);
+coverage_out:
+    switch (txn->status) {
+    case TXN_UNCOMMITTED:   COVERAGE_INC(txn_uncommitted);    break;
+    case TXN_UNCHANGED:     COVERAGE_INC(txn_unchanged);      break;
+    case TXN_INCOMPLETE:    COVERAGE_INC(txn_incomplete);     break;
+    case TXN_ABORTED:       COVERAGE_INC(txn_aborted);        break;
+    case TXN_SUCCESS:       COVERAGE_INC(txn_success);        break;
+    case TXN_TRY_AGAIN:     COVERAGE_INC(txn_try_again);      break;
+    case TXN_NOT_LOCKED:    COVERAGE_INC(txn_not_locked);     break;
+    case TXN_ERROR:         COVERAGE_INC(txn_error);          break;
+    }
+
     return txn->status;
 }
 
@@ -2108,7 +2135,7 @@ ovsdb_idl_txn_process_inc_reply(struct ovsdb_idl_txn *txn,
 
     if (txn->inc_index + 2 > results->n) {
         VLOG_WARN_RL(&syntax_rl, "reply does not contain enough operations "
-                     "for increment (has %zu, needs %u)",
+                     "for increment (has %"PRIuSIZE", needs %u)",
                      results->n, txn->inc_index + 2);
         return false;
     }
@@ -2133,7 +2160,7 @@ ovsdb_idl_txn_process_inc_reply(struct ovsdb_idl_txn *txn,
         return false;
     }
     if (rows->u.array.n != 1) {
-        VLOG_WARN_RL(&syntax_rl, "\"select\" reply \"rows\" has %zu elements "
+        VLOG_WARN_RL(&syntax_rl, "\"select\" reply \"rows\" has %"PRIuSIZE" elements "
                      "instead of 1",
                      rows->u.array.n);
         return false;
@@ -2163,7 +2190,7 @@ ovsdb_idl_txn_process_insert_reply(struct ovsdb_idl_txn_insert *insert,
 
     if (insert->op_index >= results->n) {
         VLOG_WARN_RL(&syntax_rl, "reply does not contain enough operations "
-                     "for insert (has %zu, needs %u)",
+                     "for insert (has %"PRIuSIZE", needs %u)",
                      results->n, insert->op_index);
         return false;
     }