File init.pciback of Package xen.21905

#!/bin/bash
#
# Copyright (c) 2014 SUSE GmbH Nuernberg, Germany.  All rights reserved.
#
# /etc/init.d/pciback
#
### BEGIN INIT INFO
# Provides:          pciback
# Required-Start:    $syslog $network
# Should-Start:      $null
# Required-Stop:     $syslog $network
# Should-Stop:       $null
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Description:       bind PCI devices to pciback
### END INIT INFO

. /etc/rc.status
. /etc/sysconfig/pciback

rc_reset

load_pciback() {
  if ! lsmod | grep -qi "pciback"
  then
    echo "Loading pciback ..."
    modprobe pciback
  fi
}

unload_pciback() {
  if lsmod | grep -qi "pciback"
  then
    echo "Unloading pciback ..."
    modprobe -r pciback
  fi
}

bind_dev_to_pciback() {
  for DEVICE in ${XEN_PCI_HIDE_LIST}
  do
    local DRV=`echo ${DEVICE} | /usr/bin/cut -d "," -f 1`
    local PCIID=`echo ${DEVICE} | /usr/bin/cut -d "," -f 2`

    if ! ls /sys/bus/pci/drivers/pciback/${PCIID} > /dev/null 2>&1
    then
      echo "Binding ${PCIID} ..."
      if ls /sys/bus/pci/drivers/${DRV}/${PCIID} > /dev/null 2>&1
      then
        echo -n ${PCIID} > /sys/bus/pci/drivers/${DRV}/unbind
      fi
      echo -n ${PCIID} > /sys/bus/pci/drivers/pciback/new_slot
      echo -n ${PCIID} > /sys/bus/pci/drivers/pciback/bind
    fi
  done
}

unbind_dev_from_pciback() {
  for DEVICE in ${XEN_PCI_HIDE_LIST}
  do
    local DRV=`echo ${DEVICE} | /usr/bin/cut -d "," -f 1`
    local PCIID=`echo ${DEVICE} | /usr/bin/cut -d "," -f 2`

    if ls /sys/bus/pci/drivers/pciback/${PCIID} > /dev/null
    then
      echo "Unbinding ${PCIID} ..."
      echo -n ${PCIID} > /sys/bus/pci/drivers/pciback/unbind
    fi
  done
}

test "uname -r" | grep xen && exit 0

case $1 in
  start)
    echo "Starting pciback ..."
    echo 
    load_pciback
    bind_dev_to_pciback

    rc_status -v -r
  ;;
  stop)
    echo "Stopping pciback ..."
    echo 
    unbind_dev_from_pciback
    unload_pciback

    rc_status -v
  ;;
  reload|restart)
    echo "Stopping pciback ..."
    echo 
    unbind_dev_from_pciback
    unload_pciback
    echo "Starting pciback ..."
    echo 
    load_pciback
    bind_dev_to_pciback
  ;;
  status)
    if lsmod | grep -qi pciback
    then
      echo
      echo "pciback:  loaded"
      echo
      echo "Currently bound devices ..."
      echo "-----------------------------"
      ls /sys/bus/pci/drivers/pciback | grep ^0000
      echo
    else
      echo "pciback:  not loaded"
    fi
  ;;
  *)
    echo "Usage: $0 [start|stop|restart|reload|status]"
    exit 1
  ;;
esac
openSUSE Build Service is sponsored by