XEN-PCIBack: Unterschied zwischen den Versionen

Aus Neobikers Wiki
Zur Navigation springen Zur Suche springen
Die Seite wurde neu angelegt: „= Installation = Skript = '''/etc/init.d/xen-pciback''' Konfigurationsfile = '''/etc/xen/xen-pciback''' <pre> DESC="Bind devices to xen-pciback" NAME=xen-pcib…“
 
 
Zeile 1: Zeile 1:
= Installation =
= Installation =
Skript = '''/etc/init.d/xen-pciback'''
Skript = '''/etc/init.d/xen-pciback'''
Konfigurationsfile =  '''/etc/xen/xen-pciback'''
Konfigurationsfile =  '''/etc/xen/xen-pciback'''
<pre>
<pre>

Aktuelle Version vom 6. Dezember 2020, 13:01 Uhr

Installation

Skript = /etc/init.d/xen-pciback

Konfigurationsfile = /etc/xen/xen-pciback

DESC="Bind devices to xen-pciback"
NAME=xen-pciback
MODULE=xen_pciback

# Default variables
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

SCRIPTNAME=/etc/init.d/$NAME
CONFIGNAME=/etc/xen/$NAME.conf

Konfiguration

lspci listed alle installierten PCI Devices auf.

Die beiden zusätzlichen Netzwerkkarten sollen in DomU eingebunden werden, also werden diese beim booten reserviert.

File: /etc/xen/xen-pciback.conf

# lspci | cut -d: -2f

#00:00.0 # Host bridge
#00:02.0 # VGA compatible controller
#00:03.0 # Audio device
#00:14.0 # USB controller
#00:16.0 # Communication controller
#00:1a.0 # USB controller
#00:1b.0 # Audio device
#00:1c.0 # PCI bridge
#00:1c.6 # PCI bridge
#00:1c.7 # PCI bridge
#00:1d.0 # USB controller
#00:1f.0 # ISA bridge
#00:1f.2 # SATA controller
#00:1f.3 # SMBus
#00:19.0  e1000e   ### Ethernet controller ### GREEN
02:00.0  e1000e   ### Ethernet controller ### RED
03:00.0  e1000e   ### Ethernet controller ### BLUE

Skript

#! /bin/sh
### BEGIN INIT INFO
# Provides:          xen-pciback
# Required-Start:    $remote_fs $syslog xen
# Required-Stop:     $remote_fs $syslog xen
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Bind devices to xen-pciback
# Description:       Bind devices to xen-pciback
### END INIT INFO

#
# Author: neobiker <neobiker@neobiker.de>
#

. /lib/init/vars.sh
. /lib/lsb/init-functions

xen list > /dev/null
if test $? -ne 0
then
        exit 0;
fi

TOOLSTACK=$(/usr/lib/xen-common/bin/xen-toolstack 2>/dev/null)
if [ $? -ne 0 ]; then
        log_warning_msg "No usable Xen toolstack selected"
        exit 0
fi
if [ "$(basename "$TOOLSTACK")" != xm ] && [ "$(basename "$TOOLSTACK")" != xl ]; then
        exit 0
fi

if ! [ -e /proc/xen/privcmd ]; then
        exit 0
fi

DESC="Bind devices to xen-pciback"
NAME=xen-pciback
MODULE=xen_pciback

# Default variables
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

SCRIPTNAME=/etc/init.d/$NAME
CONFIGNAME=/etc/xen/$NAME.conf

ROOT=$(/usr/lib/xen-common/bin/xen-dir 2>/dev/null)
if [ $? -ne 0 ]; then
        log_warning_msg "Not running within Xen or no compatible utils"
        exit 0
fi


#
# Make a device assignable for pci-passthru
#
do_pci_assignable_add()
{
    BDF=$1
    [ -z "$BDF" ] && return 0
    xl pci-assignable-add $BDF
    ret=$?
    if [ $ret -ne 0 ]; then
        log_warning_msg "Xen: couldn't assign PCI ($BDF)"
        return 1
    fi

    log_action_msg "Xen: PCI $BDF assigned to $NAME"
    return 0
}

#
# Remove a device from pci-passthru
#
do_pci_assignable_remove()
{
    BDF=$1
    xl pci-assignable-remove -r $BDF
    if [ $? -ne 0 ]; then
        log_warning_msg "Xen: couldn't remove PCI ($BDF)"
        return 1
    fi
    log_action_msg "Xen: PCI $BDF removed from $NAME"
    return 0
}

#
# Function that starts the daemon/service
#
do_start()
{
        # Exit if the package is not installed
        [ -e "$CONFIGNAME" ] || return 0

        cat $CONFIGNAME 2>/dev/null | awk '{if ($1 !~ /#/) print $0}' | while read PCI ; do
            [ -z "$PCI" ] && continue
            f1=`echo "$PCI" | awk '{print $1}'`
            do_pci_assignable_add $f1
        done || return 2
        return 0
}

#
# Function that stops the daemon/service
#
do_stop()
{
        # Exit if the package is not installed
        [ -e "$CONFIGNAME" ] || return 0

        cat $CONFIGNAME 2>/dev/null |
            awk '{if ($1 !~ /#/) print $0}' |
        while read PCI ; do
            [ -z "$PCI" ] && continue
            BDF=`echo "$PCI" | awk '{print $1}'`
            do_pci_assignable_remove $BDF
        done || return 2
        return 0
}

modprobe -q $MODULE

case "$1" in
  start)
        [ "$VERBOSE" != no ] && log_action_begin_msg "Starting $DESC $NAME"
        do_start
        case "$?" in
                0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                1|2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC $NAME"
        do_stop
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop}" >&2
        exit 0
        ;;
esac
exit 0