]> git.proxmox.com Git - ovs.git/blobdiff - utilities/ovs-lib.in
utilities: Fix conntrack flush command
[ovs.git] / utilities / ovs-lib.in
index cf6b6d296eb5d5865c1cbdf7c02302e8e4af43c3..92f98ad9228af4eb7b9c20bfc6c5837316bfd81e 100644 (file)
@@ -1,3 +1,5 @@
+# -*- sh -*-
+# vi:syntax=sh
 # This is a shell function library sourced by some Open vSwitch scripts.
 # It is not intended to be invoked on its own.
 
@@ -399,6 +401,14 @@ create_db () {
     action "Creating empty database $DB_FILE" ovsdb_tool create "$DB_FILE" "$DB_SCHEMA"
 }
 
+backup_db () {
+    # Back up the old version.
+    version=`ovsdb_tool db-version "$DB_FILE"`
+    cksum=`ovsdb_tool db-cksum "$DB_FILE" | awk '{print $1}'`
+    backup=$DB_FILE.backup$version-$cksum
+    action "Backing up database to $backup" cp "$DB_FILE" "$backup" || return 1
+}
+
 upgrade_db () {
     DB_FILE="$1"
     DB_SCHEMA="$2"
@@ -409,11 +419,7 @@ upgrade_db () {
         install_dir `dirname $DB_FILE`
         create_db "$DB_FILE" "$DB_SCHEMA"
     elif test X"`ovsdb_tool needs-conversion "$DB_FILE" "$DB_SCHEMA"`" = Xyes; then
-        # Back up the old version.
-        version=`ovsdb_tool db-version "$DB_FILE"`
-        cksum=`ovsdb_tool db-cksum "$DB_FILE" | awk '{print $1}'`
-        backup=$DB_FILE.backup$version-$cksum
-        action "Backing up database to $backup" cp "$DB_FILE" "$backup" || return 1
+        backup_db || return 1
 
         # Compact database.  This is important if the old schema did not enable
         # garbage collection (i.e. if it did not have any tables with "isRoot":
@@ -441,6 +447,54 @@ upgrade_db () {
     fi
 }
 
+upgrade_cluster () {
+    local DB_SCHEMA=$1 DB_SERVER=$2
+    local schema_name=$(ovsdb-tool schema-name $1) || return 1
+
+    action "Waiting for $schema_name to come up" ovsdb-client -t 30 wait "$DB_SERVER" "$schema_name" connected || return $?
+    local db_version=$(ovsdb-client -t 10 get-schema-version "$DB_SERVER" "$schema_name") || return $?
+    local target_version=$(ovsdb-tool schema-version "$DB_SCHEMA") || return $?
+
+    if ovsdb-tool compare-versions "$db_version" == "$target_version"; then
+        :
+    elif ovsdb-tool compare-versions "$db_version" ">" "$target_version"; then
+        log_warning_msg "Database $schema_name has newer schema version ($db_version) than our local schema ($target_version), possibly an upgrade is partially complete?"
+    else
+        action "Upgrading database $schema_name from schema version $db_version to $target_version" ovsdb-client -t 30 convert "$DB_SERVER" "$DB_SCHEMA"
+    fi
+}
+
+create_cluster () {
+    DB_FILE="$1"
+    DB_SCHEMA="$2"
+    LOCAL_ADDR="$3"
+
+    if test ! -e "$DB_FILE"; then
+        action "Creating cluster database $DB_FILE" ovsdb_tool create-cluster "$DB_FILE" "$DB_SCHEMA" "$LOCAL_ADDR"
+    elif ovsdb_tool db-is-standalone "$DB_FILE"; then
+        # Convert standalone database to clustered.
+        backup_db || return 1
+        action "Creating cluster database $DB_FILE from existing one" \
+               ovsdb_tool create-cluster "$DB_FILE" "$backup" "$LOCAL_ADDR"
+    fi
+}
+
+join_cluster() {
+    DB_FILE="$1"
+    SCHEMA_NAME="$2"
+    LOCAL_ADDR="$3"
+    REMOTE_ADDR="$4"
+
+    if test ! -e "$DB_FILE"; then
+        ovsdb_tool join-cluster "$DB_FILE" "$SCHEMA_NAME" "$LOCAL_ADDR" "$REMOTE_ADDR"
+    elif ovsdb_tool db-is-standalone "$DB_FILE"; then
+        # Backup standalone database and join cluster.
+        backup_db || return 1
+        action "Joining $DB_FILE to cluster" \
+               ovsdb_tool join-cluster "$DB_FILE" "$SCHEMA_NAME" "$LOCAL_ADDR"
+    fi
+}
+
 ovs_vsctl () {
     ovs-vsctl --no-wait "$@"
 }
@@ -449,6 +503,10 @@ ovs_vsctl () {
 ## force-reload-kmod ##
 ## ----------------- ##
 
+ovs_kmod_ctl () {
+    "$dir0/ovs-kmod-ctl" "$@"
+}
+
 internal_interfaces () {
     # Outputs a list of internal interfaces:
     #
@@ -547,6 +605,7 @@ force_reload_kmod () {
     stop_ovsdb
     start_ovsdb || return 1
 
+    action "Flush old conntrack entries" ovs-appctl dpctl/flush-conntrack
     stop_forwarding
 
     if action "Saving interface configuration" save_interfaces; then
@@ -563,13 +622,7 @@ force_reload_kmod () {
         action "Removing datapath: $dp" ovs-dpctl del-dp "$dp"
     done
 
-    for vport in `awk '/^vport_/ { print $1 }' /proc/modules`; do
-        action "Removing $vport module" rmmod $vport
-    done
-
-    if test -e /sys/module/openvswitch; then
-        action "Removing openvswitch module" rmmod openvswitch
-    fi
+    ovs_kmod_ctl remove
 
     # Start vswitchd by asking it to wait till flow restore is finished.
     flow_restore_wait