X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=xenserver%2Fetc_xensource_scripts_vif;h=78434fb6ccd54002a08d0f3707af54efcf5b8a18;hb=67680b012be30d9c26eab999b83b08c6eb32dbd2;hp=1a38dc4c990df06bdd1b9bc3ca5cb8cc239b32d0;hpb=bc39196036f8e33d15274855087f0c47be2095ee;p=sliver-openvswitch.git diff --git a/xenserver/etc_xensource_scripts_vif b/xenserver/etc_xensource_scripts_vif index 1a38dc4c9..78434fb6c 100755 --- a/xenserver/etc_xensource_scripts_vif +++ b/xenserver/etc_xensource_scripts_vif @@ -25,31 +25,21 @@ IP="/sbin/ip" vsctl="/usr/bin/ovs-vsctl" -# XAPI before build 29381 (approximately) did not provide some of the -# data in XenStore that we rely on. -. /etc/xensource-inventory -if test "$PRODUCT_VERSION" = "5.5.0" || test "${BUILD_NUMBER%p}" -le 26131 -then - xs550=true -else - xs550=false -fi - handle_promiscuous() { local arg=$(xenstore-read "${PRIVATE}/other-config/promiscuous" 2>/dev/null) if [ $? -eq 0 -a -n "${arg}" ] ; then - case $NETWORK_MODE in - bridge) - case "${arg}" in - true|on) echo 1 > /sys/class/net/${dev}/brport/promisc ;; - *) echo 0 > /sys/class/net/${dev}/brport/promisc ;; - esac - ;; - vswitch) - logger -t script-vif "${dev}: Promiscuous ports are not supported via Open vSwitch." - ;; - esac + case $NETWORK_MODE in + bridge) + case "${arg}" in + true|on) echo 1 > /sys/class/net/${dev}/brport/promisc ;; + *) echo 0 > /sys/class/net/${dev}/brport/promisc ;; + esac + ;; + openvswitch) + logger -t script-vif "${dev}: Promiscuous ports are not supported via Open vSwitch." + ;; + esac fi } @@ -70,8 +60,8 @@ handle_mtu() { local mtu=$(xenstore-read "${PRIVATE}/MTU" 2>/dev/null) if [ $? -eq 0 -a -n "${mtu}" ]; then - logger -t scripts-vif "Setting ${dev} MTU ${mtu}" - ${IP} link set "${dev}" mtu ${mtu} || logger -t scripts-vif "Failed to ip link set ${dev} mtu ${mtu}. Error code $?" + logger -t scripts-vif "Setting ${dev} MTU ${mtu}" + ${IP} link set "${dev}" mtu ${mtu} || logger -t scripts-vif "Failed to ip link set ${dev} mtu ${mtu}. Error code $?" fi } @@ -89,53 +79,25 @@ handle_vswitch_vif_details() { local vm=$(xenstore-read "/local/domain/$DOMID/vm" 2>/dev/null) if [ $? -eq 0 -a -n "${vm}" ] ; then - local vm_uuid=$(xenstore-read "$vm/uuid" 2>/dev/null) + local vm_uuid=$(xenstore-read "$vm/uuid" 2>/dev/null) fi if [ -n "${vm_uuid}" ] ; then - set_vif_external_id "vm-uuid" "${vm_uuid}" + set_vif_external_id "xs-vm-uuid" "${vm_uuid}" fi local vif_uuid=$(xenstore-read "${PRIVATE}/vif-uuid" 2>/dev/null) - if $xs550 && [ -z "${vif_uuid}" ] && [ -n "${vm_uuid}" ]; then - vif_uuid=$(xe vif-list --minimal vm-uuid="${vm_uuid}" device=$DEVID) - fi if [ -n "${vif_uuid}" ] ; then - set_vif_external_id "vif-uuid" "${vif_uuid}" + set_vif_external_id "xs-vif-uuid" "${vif_uuid}" fi local vif_details= local net_uuid=$(xenstore-read "${PRIVATE}/network-uuid" 2>/dev/null) - if $xs550 && [ -z "${net_uuid}" ] && [ -n "${vif_uuid}" ]; then - net_uuid=$(xe vif-param-get uuid="${vif_uuid}" param-name=network-uuid) - fi if [ -n "${net_uuid}" ] ; then - set_vif_external_id "network-uuid" "${net_uuid}" + set_vif_external_id "xs-network-uuid" "${net_uuid}" fi - local address=$(xenstore-read "/local/domain/$DOMID/device/vif/$DEVID/mac" 2>/dev/null) if [ -n "${address}" ] ; then - set_vif_external_id "vif-mac" "${address}" - fi -} - -xs550_set_internal_network_uuid() -{ - if $xs550; then - # vNetManager needs to know the network UUID(s) associated with each - # datapath. Normally interface-reconfigure adds them, but XAPI does - # not use interface-reconfigure for internal networks. Instead, XAPI - # calls the addbr ioctl internally, so we have to do it here instead - # for internal networks. This is only acceptable because xapi is lazy - # about creating internal networks: it only creates one just before it - # adds the first vif to it. There may still be a brief delay between - # the initial ovs-vswitchd connection to vNetManager and setting this - # configuration variable, but vNetManager can tolerate that. - local bridge=$1 - local net_uuid=$(xenstore-read "${PRIVATE}/network-uuid" 2>/dev/null) - if [ -n "${net_uuid}" ] ; then - logger -t scripts-vif "${bridge} network-uuids ${net_uuid}" - echo "-- br-set-external-id $bridge network-uuids ${net_uuid}" - fi + set_vif_external_id "attached-mac" "${address}" fi } @@ -143,13 +105,13 @@ add_to_bridge() { local address=$(xenstore-read "${PRIVATE}/bridge-MAC") if [ $? -ne 0 -o -z "${address}" ]; then - logger -t scripts-vif "Failed to read ${PRIVATE}/bridge-MAC from xenstore" - exit 1 + logger -t scripts-vif "Failed to read ${PRIVATE}/bridge-MAC from xenstore" + exit 1 fi local bridge=$(xenstore-read "${PRIVATE}/bridge") if [ $? -ne 0 -o -z "${bridge}" ]; then - logger -t scripts-vif "Failed to read ${PRIVATE}/bridge from xenstore" - exit 1 + logger -t scripts-vif "Failed to read ${PRIVATE}/bridge from xenstore" + exit 1 fi logger -t scripts-vif "Adding ${dev} to ${bridge} with address ${address}" @@ -160,37 +122,58 @@ add_to_bridge() ${IP} addr flush "${dev}" || logger -t scripts-vif "Failed to ip addr flush ${dev}" case $NETWORK_MODE in - bridge) - ${BRCTL} setfd "${bridge}" 0 || logger -t scripts-vif "Failed to brctl setfd ${bridge} 0" - ${BRCTL} addif "${bridge}" "${dev}" || logger -t scripts-vif "Failed to brctl addif ${bridge} ${dev}" - ;; - vswitch) - if [ "$TYPE" = "vif" ] ; then - local vif_details=$(handle_vswitch_vif_details) - fi - - $vsctl -- --if-exists del-port $dev -- add-port $bridge $dev $vif_details $(xs550_set_internal_network_uuid $bridge) - ;; + bridge) + ${BRCTL} setfd "${bridge}" 0 || logger -t scripts-vif "Failed to brctl setfd ${bridge} 0" + ${BRCTL} addif "${bridge}" "${dev}" || logger -t scripts-vif "Failed to brctl addif ${bridge} ${dev}" + ;; + openvswitch) + if [ "$TYPE" = "vif" ] ; then + local vif_details=$(handle_vswitch_vif_details $bridge) + fi + + $vsctl --timeout=30 -- --if-exists del-port $dev -- add-port $bridge $dev $vif_details + ;; esac - + ${IP} link set "${dev}" up || logger -t scripts-vif "Failed to ip link set ${dev} up" } remove_from_bridge() { case $NETWORK_MODE in - bridge) - # Nothing to do - ;; - vswitch) - # If ovs-brcompatd is running, it might already have deleted the - # port. Use --if-exists to suppress the error that would otherwise - # arise in that case. - $vsctl -- --if-exists del-port $dev - ;; + bridge) + # Nothing to do + ;; + openvswitch) + $vsctl --timeout=30 -- del-port $dev + ;; esac } +call_hook_script() { + local domid=$1 + local action=$2 + # Call the VIF hotplug hook if present + if [ -x /etc/xapi.d/vif-hotplug ]; then + local vm=$(xenstore-read "/local/domain/$domid/vm" 2>/dev/null) + if [ $? -eq 0 -a -n "${vm}" ] ; then + local vm_uuid=$(xenstore-read "$vm/uuid" 2>/dev/null) + fi + if [ -n "${vm_uuid}" ] ; then + logger -t scripts-vif "VM UUID ${vm_uuid}" + fi + + local vif_uuid=$(xenstore-read "${PRIVATE}/vif-uuid" 2>/dev/null) + if [ -n "${vif_uuid}" ] ; then + logger -t scripts-vif "VIF UUID ${vif_uuid}" + fi + if [ -n "${vif_uuid}" -a -n "${vm_uuid}" ] ; then + logger -t scripts-vif "Calling VIF hotplug hook for VM ${vm_uuid}, VIF ${vif_uuid}" + /etc/xapi.d/vif-hotplug -action "${action}" -vifuuid "${vif_uuid}" -vmuuid "${vm_uuid}" + fi + fi +} + NETWORK_MODE=$(cat /etc/xensource/network.conf) ACTION=$1 @@ -202,28 +185,34 @@ else fi case $NETWORK_MODE in - bridge|vswitch) ;; + bridge|openvswitch) ;; + vswitch) NETWORK_MODE=openvswitch ;; *) - logger -t scripts-vif "Unknown network mode $NETWORK_MODE" - exit 1 - ;; + logger -t scripts-vif "Unknown network mode $NETWORK_MODE" + exit 1 + ;; esac case ${TYPE} in vif) - DOMID=`echo ${XENBUS_PATH} | cut -f 3 -d '/'` - DEVID=`echo ${XENBUS_PATH} | cut -f 4 -d '/'` - dev=vif${DOMID}.${DEVID} - ;; + if [ -z ${XENBUS_PATH} ]; then + DOMID=$3 + DEVID=$4 + else + DOMID=`echo ${XENBUS_PATH} | cut -f 3 -d '/'` + DEVID=`echo ${XENBUS_PATH} | cut -f 4 -d '/'` + fi + dev=vif${DOMID}.${DEVID} + ;; tap) - dev=$INTERFACE - DOMID=`echo ${dev#tap} | cut -f 1 -d '.'` - DEVID=`echo ${dev#tap} | cut -f 2 -d '.'` - ;; + dev=$INTERFACE + DOMID=`echo ${dev#tap} | cut -f 1 -d '.'` + DEVID=`echo ${dev#tap} | cut -f 2 -d '.'` + ;; *) - logger -t scripts-vif "unknown interface type ${TYPE}" - exit 1 - ;; + logger -t scripts-vif "unknown interface type ${TYPE}" + exit 1 + ;; esac XAPI=/xapi/${DOMID}/hotplug/vif/${DEVID} @@ -233,37 +222,44 @@ PRIVATE=/xapi/${DOMID}/private/vif/${DEVID} logger -t scripts-vif "Called as \"$@\" domid:$DOMID devid:$DEVID mode:$NETWORK_MODE" case "${ACTION}" in online) - if [ "${TYPE}" = "vif" ] ; then - handle_ethtool rx - handle_ethtool tx - handle_ethtool sg - handle_ethtool tso - handle_ethtool ufo - handle_ethtool gso - - handle_mtu - add_to_bridge - handle_promiscuous - - xenstore-write "${HOTPLUG}/vif" "${dev}" - xenstore-write "${HOTPLUG}/hotplug" "online" - - # xs-xen.pq.hq:91e986b8e49f netback-wait-for-hotplug - xenstore-write "/local/domain/0/backend/vif/${DOMID}/${DEVID}/hotplug-status" "connected" - fi - ;; + if [ "${TYPE}" = "vif" ] ; then + handle_ethtool rx + handle_ethtool tx + handle_ethtool sg + handle_ethtool tso + handle_ethtool ufo + handle_ethtool gso + + handle_mtu + add_to_bridge + handle_promiscuous + + xenstore-write "${HOTPLUG}/vif" "${dev}" + xenstore-write "${HOTPLUG}/hotplug" "online" + + # xs-xen.pq.hq:91e986b8e49f netback-wait-for-hotplug + xenstore-write "/local/domain/0/backend/vif/${DOMID}/${DEVID}/hotplug-status" "connected" + call_hook_script $DOMID "${ACTION}" + fi + ;; add) - if [ "${TYPE}" = "tap" ] ; then - add_to_bridge - fi - ;; + if [ "${TYPE}" = "tap" ] ; then + add_to_bridge + fi + ;; remove) - if [ "${TYPE}" = "vif" ] ;then - xenstore-rm "${HOTPLUG}/hotplug" - fi - logger -t scripts-vif "${dev} has been removed" - remove_from_bridge - ;; + if [ "${TYPE}" = "vif" ] ;then + xenstore-rm "${HOTPLUG}/hotplug" + call_hook_script $DOMID "${ACTION}" + fi + logger -t scripts-vif "${dev} has been removed" + remove_from_bridge + ;; + +move) + if [ "${TYPE}" = "vif" ] ;then + add_to_bridge + fi esac