#!/bin/bash # # xenpciexport Script to start and stop the Xen PCI forwarding to guests. # # Author: ZoltarStark http://www.olivetalks.com # # chkconfig: 2345 97 02 # description: Sets up PCI forwarding for Xen guests. # Source function library. . /etc/rc.d/init.d/functions RETVAL=0 if [ ! -d /proc/xen ]; then exit 0 fi if ! grep -q "control_d" /proc/xen/capabilities ; then exit 0 fi prog="Xen PCI export" # which PCI device to export to the guest SLOT=0000:00:1d.1 case "$1" in start) echo -n $"Starting $prog: " # Export a USB controller to guest modprobe pciback sleep 2 # Unbind the host USB driver echo -n ${SLOT} > /sys/bus/pci/drivers/uhci_hcd/unbind # Add a new slot to the PCI Backend's list echo -n ${SLOT} > /sys/bus/pci/drivers/pciback/new_slot # Now that the backend is watching for the slot, bind to it echo -n ${SLOT} > /sys/bus/pci/drivers/pciback/bind RETVAL=$? ;; stop) echo -n $"Stopping $prog: " # Unbind the guest USB driver echo -n ${SLOT} > /sys/bus/pci/drivers/pciback/unbind # Remove the slot from the PCI Backend's list echo -n ${SLOT} > /sys/bus/pci/drivers/pciback/remove_slot # Now bind the host USB driver to the slot echo -n ${SLOT} > /sys/bus/pci/drivers/uhci_hcd/bind modprobe -r pciback RETVAL=$? ;; status) test -d /sys/bus/pci/drivers/pciback/${SLOT} if [ $? = 0 ] ; then echo PCI is exported to guests else echo PCI is not exported to guests fi exit 0 ;; *) # do not advertise unreasonable commands that there is no reason # to use with this device echo $"Usage: $0 {start|stop|status}" exit 1 esac if [ $RETVAL = 0 ] ; then echo_success echo else echo_failure echo fi exit $RETVAL