[ovs-dev,v3] ovs-ctl: add option to delete transient ports
diff mbox

Message ID 1441140969-26799-1-git-send-email-cascardo@redhat.com
State Accepted
Headers show

Commit Message

Thadeu Lima de Souza Cascardo Sept. 1, 2015, 8:56 p.m. UTC
When using virtualization, new ports are created and removed all the time. These
ports do not persist after a system reboot, for example. They may be created
again by the virtualization manager, but that will happen after the vswitch is
already running, and the virtualization manager will add them again to the
bridge.

If a reboot happens without properly deleting such ports, all kinds of errors
will happen. The absence of the ports will be logged as errors, and adding those
ports again to the database will fail.

Deleting all bridges may not be an option, if the system cannot persist other
information outside of OVSDB.

This patch introduces the notion of transient ports. Ports may be added as
transient, as a boolean in other_config smap. When openvswitch is started by
using --delete-transient-ports ovs-ctl option, all transient ports will be
removed.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>
---
 utilities/ovs-ctl.8  | 11 ++++++++++-
 utilities/ovs-ctl.in | 10 ++++++++++
 vswitchd/vswitch.xml |  8 ++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

Comments

Ben Pfaff Sept. 1, 2015, 9 p.m. UTC | #1
On Tue, Sep 01, 2015 at 05:56:09PM -0300, Thadeu Lima de Souza Cascardo wrote:
> When using virtualization, new ports are created and removed all the time. These
> ports do not persist after a system reboot, for example. They may be created
> again by the virtualization manager, but that will happen after the vswitch is
> already running, and the virtualization manager will add them again to the
> bridge.
> 
> If a reboot happens without properly deleting such ports, all kinds of errors
> will happen. The absence of the ports will be logged as errors, and adding those
> ports again to the database will fail.
> 
> Deleting all bridges may not be an option, if the system cannot persist other
> information outside of OVSDB.
> 
> This patch introduces the notion of transient ports. Ports may be added as
> transient, as a boolean in other_config smap. When openvswitch is started by
> using --delete-transient-ports ovs-ctl option, all transient ports will be
> removed.
> 
> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>

Applied, thanks!

Patch
diff mbox

diff --git a/utilities/ovs-ctl.8 b/utilities/ovs-ctl.8
index c08c7db..9728d0d 100644
--- a/utilities/ovs-ctl.8
+++ b/utilities/ovs-ctl.8
@@ -90,10 +90,14 @@  Initializes a few values inside the database.
 If the \fB\-\-delete\-bridges\fR option was used, deletes all of the
 bridges from the database.
 .
+.IP 6.
+If the \fB\-\-delete\-transient\-ports\fR option was used, deletes all ports
+that have other_config:transient set to true.
+.
 .PP
 The \fBstart\fR command skips the following step if
 \fBovs\-vswitchd\fR is already running:
-.IP 6.
+.IP 7.
 Starts \fBovs\-vswitchd\fR.
 .
 .SS "Options"
@@ -148,6 +152,11 @@  on every boot.  This option supports that, by deleting all Open
 vSwitch bridges after starting \fBovsdb\-server\fR but before starting
 \fBovs\-vswitchd\fR.
 .
+.IP "\fB\-\-delete\-transient\-ports\fR"
+Deletes all ports that have the other_config:transient value set to true. This
+is important on certain environments where some ports are going to be recreated
+after reboot, but other ports need to be persisted in the database.
+.
 .PP
 The following options are less important:
 .
diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in
index 9bbbe0d..bca8c56 100755
--- a/utilities/ovs-ctl.in
+++ b/utilities/ovs-ctl.in
@@ -177,6 +177,12 @@  check_force_cores () {
     fi
 }
 
+del_transient_ports () {
+    for port in `ovs-vsctl --bare -- --columns=name find port other_config:transient=true`; do
+        ovs_vsctl -- del-port "$port"
+    done
+}
+
 start_ovsdb () {
     check_force_cores
 
@@ -219,6 +225,9 @@  start_ovsdb () {
                 ovs_vsctl del-br $bridge
             done
         fi
+        if test X"$DELETE_TRANSIENT_PORTS" = Xyes; then
+            del_transient_ports
+        fi
     fi
 }
 
@@ -536,6 +545,7 @@  set_defaults () {
     SYSTEM_ID=
 
     DELETE_BRIDGES=no
+    DELETE_TRANSIENT_PORTS=no
 
     DAEMON_CWD=/
     FORCE_COREFILES=yes
diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml
index 457f34a..0ab4a9a 100644
--- a/vswitchd/vswitch.xml
+++ b/vswitchd/vswitch.xml
@@ -1659,6 +1659,14 @@ 
         <code>fake-bridge-</code>,
         e.g. <code>fake-bridge-xs-network-uuids</code>.
       </column>
+
+      <column name="other_config" key="transient"
+              type='{"type": "boolean"}'>
+        <p>
+          If set to <code>true</code>, the port will be removed when
+          <code>ovs-ctl start --delete-transient-ports</code> is used.
+        </p>
+      </column>
     </group>
 
     <column name="bond_active_slave">