Skip to content

Commit

Permalink
utilities: move some functions from ovs-ctl.in to ovs-lib.in
Browse files Browse the repository at this point in the history
Move the functions related to "force-reload-kmod" and "restart" from
ovs-ctl.in to ovs-lib.in in order to permit other scripts to use them.

Signed-off-by: Timothy Redaelli <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
Tested-by: Greg Rose <[email protected]>
Reviewed-by: Greg Rose <[email protected]>
  • Loading branch information
drizzt authored and blp committed Jan 8, 2018
1 parent 8e3a28c commit 3610943
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 173 deletions.
173 changes: 0 additions & 173 deletions utilities/ovs-ctl.in
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ insert_mod_if_required () {
insert_mods
}

ovs_vsctl () {
ovs-vsctl --no-wait "$@"
}

set_hostname () {
# 'hostname -f' needs network connectivity to work. So we should
# call this only after ovs-vswitchd is running.
Expand Down Expand Up @@ -270,175 +266,6 @@ stop_forwarding () {
fi
}

## ----------------- ##
## force-reload-kmod ##
## ----------------- ##

internal_interfaces () {
# Outputs a list of internal interfaces:
#
# - There is an internal interface for every bridge, whether it
# has an Interface record or not and whether the Interface
# record's 'type' is properly set or not.
#
# - There is an internal interface for each Interface record whose
# 'type' is 'internal'.
#
# But ignore interfaces that don't really exist.
for d in `(ovs_vsctl --bare \
-- --columns=name find Interface type=internal \
-- list-br) | sort -u`
do
if test -e "/sys/class/net/$d"; then
printf "%s " "$d"
fi
done
}

ovs_save () {
bridges=`ovs_vsctl -- --real list-br`
if [ -n "${bridges}" ] && \
"$datadir/scripts/ovs-save" "$1" ${bridges} > "$2"; then
chmod +x "$2"
return 0
fi
[ -z "${bridges}" ] && return 0
}

save_flows_if_required () {
if test X"$DELETE_BRIDGES" != Xyes; then
action "Saving flows" ovs_save save-flows "${script_flows}"
fi
}

save_interfaces () {
"$datadir/scripts/ovs-save" save-interfaces ${ifaces} \
> "${script_interfaces}"
}

flow_restore_wait () {
if test X"$OVS_VSWITCHD" = Xyes; then
ovs_vsctl set open_vswitch . other_config:flow-restore-wait="true"
fi
}

flow_restore_complete () {
if test X"$OVS_VSWITCHD" = Xyes; then
ovs_vsctl --if-exists remove open_vswitch . other_config \
flow-restore-wait="true"
fi
}

restore_flows () {
[ -x "${script_flows}" ] && \
action "Restoring saved flows" "${script_flows}"
}

restore_interfaces () {
[ ! -x "${script_interfaces}" ] && return 0
action "Restoring interface configuration" "${script_interfaces}"
rc=$?
if test $rc = 0; then
level=debug
else
level=err
fi
log="logger -p daemon.$level -t ovs-save"
$log "interface restore script exited with status $rc:"
$log -f "$script_interfaces"
}

init_restore_scripts () {
script_interfaces=`mktemp`
script_flows=`mktemp`
trap 'rm -f "${script_interfaces}" "${script_flows}"' 0
}

force_reload_kmod () {

if test X"$OVS_VSWITCHD" != Xyes; then
log_failure_msg "Reloading of kmod without ovs-vswitchd is an error"
exit 1
fi

ifaces=`internal_interfaces`
action "Detected internal interfaces: $ifaces" true

init_restore_scripts
save_flows_if_required

# Restart the database first, since a large database may take a
# while to load, and we want to minimize forwarding disruption.
stop_ovsdb
start_ovsdb || return 1

stop_forwarding

if action "Saving interface configuration" save_interfaces; then
:
else
log_warning_msg "Failed to save configuration, not replacing kernel module"
start_forwarding
add_managers
exit 1
fi
chmod +x "$script_interfaces"

for dp in `ovs-dpctl dump-dps`; do
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

# Start vswitchd by asking it to wait till flow restore is finished.
flow_restore_wait
start_forwarding || return 1

# Restore saved flows and inform vswitchd that we are done.
restore_flows
flow_restore_complete
add_managers

restore_interfaces

"$datadir/scripts/ovs-check-dead-ifs"
}

## ------- ##
## restart ##
## ------- ##

restart () {
if daemon_is_running ovsdb-server && daemon_is_running ovs-vswitchd; then
init_restore_scripts
if test X"$OVS_VSWITCHD" = Xyes; then
save_flows_if_required
fi
fi

# Restart the database first, since a large database may take a
# while to load, and we want to minimize forwarding disruption.
stop_ovsdb
start_ovsdb || return 1

stop_forwarding

# Start vswitchd by asking it to wait till flow restore is finished.
flow_restore_wait
start_forwarding || return 1

# Restore saved flows and inform vswitchd that we are done.
restore_flows
flow_restore_complete
add_managers
}

## --------------- ##
## enable-protocol ##
## --------------- ##
Expand Down
173 changes: 173 additions & 0 deletions utilities/ovs-lib.in
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,176 @@ upgrade_db () {
fi
fi
}

ovs_vsctl () {
ovs-vsctl --no-wait "$@"
}

## ----------------- ##
## force-reload-kmod ##
## ----------------- ##

internal_interfaces () {
# Outputs a list of internal interfaces:
#
# - There is an internal interface for every bridge, whether it
# has an Interface record or not and whether the Interface
# record's 'type' is properly set or not.
#
# - There is an internal interface for each Interface record whose
# 'type' is 'internal'.
#
# But ignore interfaces that don't really exist.
for d in `(ovs_vsctl --bare \
-- --columns=name find Interface type=internal \
-- list-br) | sort -u`
do
if test -e "/sys/class/net/$d"; then
printf "%s " "$d"
fi
done
}

ovs_save () {
bridges=`ovs_vsctl -- --real list-br`
if [ -n "${bridges}" ] && \
"$datadir/scripts/ovs-save" "$1" ${bridges} > "$2"; then
chmod +x "$2"
return 0
fi
[ -z "${bridges}" ] && return 0
}

save_flows_if_required () {
if test X"$DELETE_BRIDGES" != Xyes; then
action "Saving flows" ovs_save save-flows "${script_flows}"
fi
}

save_interfaces () {
"$datadir/scripts/ovs-save" save-interfaces ${ifaces} \
> "${script_interfaces}"
}

flow_restore_wait () {
if test X"${OVS_VSWITCHD:-yes}" = Xyes; then
ovs_vsctl set open_vswitch . other_config:flow-restore-wait="true"
fi
}

flow_restore_complete () {
if test X"${OVS_VSWITCHD:-yes}" = Xyes; then
ovs_vsctl --if-exists remove open_vswitch . other_config \
flow-restore-wait="true"
fi
}

restore_flows () {
[ -x "${script_flows}" ] && \
action "Restoring saved flows" "${script_flows}"
}

restore_interfaces () {
[ ! -x "${script_interfaces}" ] && return 0
action "Restoring interface configuration" "${script_interfaces}"
rc=$?
if test $rc = 0; then
level=debug
else
level=err
fi
log="logger -p daemon.$level -t ovs-save"
$log "interface restore script exited with status $rc:"
$log -f "$script_interfaces"
}

init_restore_scripts () {
script_interfaces=`mktemp`
script_flows=`mktemp`
trap 'rm -f "${script_interfaces}" "${script_flows}"' 0
}

force_reload_kmod () {

if test X"${OVS_VSWITCHD:-yes}" != Xyes; then
log_failure_msg "Reloading of kmod without ovs-vswitchd is an error"
exit 1
fi

ifaces=`internal_interfaces`
action "Detected internal interfaces: $ifaces" true

init_restore_scripts
save_flows_if_required

# Restart the database first, since a large database may take a
# while to load, and we want to minimize forwarding disruption.
stop_ovsdb
start_ovsdb || return 1

stop_forwarding

if action "Saving interface configuration" save_interfaces; then
:
else
log_warning_msg "Failed to save configuration, not replacing kernel module"
start_forwarding
add_managers
exit 1
fi
chmod +x "$script_interfaces"

for dp in `ovs-dpctl dump-dps`; do
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

# Start vswitchd by asking it to wait till flow restore is finished.
flow_restore_wait
start_forwarding || return 1

# Restore saved flows and inform vswitchd that we are done.
restore_flows
flow_restore_complete
add_managers

restore_interfaces

"$datadir/scripts/ovs-check-dead-ifs"
}

## ------- ##
## restart ##
## ------- ##

restart () {
if daemon_is_running ovsdb-server && daemon_is_running ovs-vswitchd; then
init_restore_scripts
if test X"${OVS_VSWITCHD:-yes}" = Xyes; then
save_flows_if_required
fi
fi

# Restart the database first, since a large database may take a
# while to load, and we want to minimize forwarding disruption.
stop_ovsdb
start_ovsdb || return 1

stop_forwarding

# Start vswitchd by asking it to wait till flow restore is finished.
flow_restore_wait
start_forwarding || return 1

# Restore saved flows and inform vswitchd that we are done.
restore_flows
flow_restore_complete
add_managers
}

0 comments on commit 3610943

Please sign in to comment.