From 2e8731aca9110a7f00d051976b99348744e74a52 Mon Sep 17 00:00:00 2001 From: torben Date: Mon, 20 Apr 2015 15:05:44 +0200 Subject: Refactoring. --- testModule/binaries/dnbd3-client | Bin 0 -> 31150 bytes testModule/binaries/qemu-nbd-systemd-mark | Bin 0 -> 7128103 bytes testModule/debugging_tools/dnbd3-client | Bin 31150 -> 0 bytes testModule/debugging_tools/qemu-nbd-systemd-mark | Bin 7131834 -> 7128103 bytes .../qemu-nbd-systemd-mark-alternate | Bin 7128103 -> 0 bytes testModule/debugging_tools/setup-network.sh | 84 +++++++++++++++++++++ testModule/debugging_tools/setup_network.sh | 84 --------------------- testModule/hooks/pre-mount.sh | 11 ++- testModule/module-setup.sh | 11 ++- testModule/systemd-preserve-process-marker.c | 2 +- 10 files changed, 99 insertions(+), 93 deletions(-) create mode 100755 testModule/binaries/dnbd3-client create mode 100755 testModule/binaries/qemu-nbd-systemd-mark delete mode 100755 testModule/debugging_tools/dnbd3-client delete mode 100755 testModule/debugging_tools/qemu-nbd-systemd-mark-alternate create mode 100644 testModule/debugging_tools/setup-network.sh delete mode 100644 testModule/debugging_tools/setup_network.sh (limited to 'testModule') diff --git a/testModule/binaries/dnbd3-client b/testModule/binaries/dnbd3-client new file mode 100755 index 00000000..76924b49 Binary files /dev/null and b/testModule/binaries/dnbd3-client differ diff --git a/testModule/binaries/qemu-nbd-systemd-mark b/testModule/binaries/qemu-nbd-systemd-mark new file mode 100755 index 00000000..03c2a6b1 Binary files /dev/null and b/testModule/binaries/qemu-nbd-systemd-mark differ diff --git a/testModule/debugging_tools/dnbd3-client b/testModule/debugging_tools/dnbd3-client deleted file mode 100755 index 76924b49..00000000 Binary files a/testModule/debugging_tools/dnbd3-client and /dev/null differ diff --git a/testModule/debugging_tools/qemu-nbd-systemd-mark b/testModule/debugging_tools/qemu-nbd-systemd-mark index 26fefe9d..03c2a6b1 100755 Binary files a/testModule/debugging_tools/qemu-nbd-systemd-mark and b/testModule/debugging_tools/qemu-nbd-systemd-mark differ diff --git a/testModule/debugging_tools/qemu-nbd-systemd-mark-alternate b/testModule/debugging_tools/qemu-nbd-systemd-mark-alternate deleted file mode 100755 index 03c2a6b1..00000000 Binary files a/testModule/debugging_tools/qemu-nbd-systemd-mark-alternate and /dev/null differ diff --git a/testModule/debugging_tools/setup-network.sh b/testModule/debugging_tools/setup-network.sh new file mode 100644 index 00000000..3b32a68c --- /dev/null +++ b/testModule/debugging_tools/setup-network.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +echo "Setting up network..." + +echo "Main MAC address is '$MAC'" + +# setup network +source /inc/network.functions + +# set up loopback networking +echo "Setting up loopback" +ip link set dev lo up 2>/dev/null +ip addr add 127.0.0.1/8 dev lo 2>/dev/null + +echo "Setting up bridge" +BRIDGE="br0" + +# Following was supposed to prevent scripts from getting confused by multiple interfaces with same MAC - does not work though +## Flip mac address of original interface - this var is not local so init sees the changes too +#MAC="$(echo "$MAC" | awk -F ':' '{printf $1 ":" $2 ":" $5 ":" $3 ":" $6 ":" $4}')" +#ip link set addr "$MAC" "$SLAVE" + +mkdir -p "${FUTURE_ROOT}/etc/udev/rules.d" + +#IP_OUT=$(ip a | sed -r ':a;N;$!ba;s/: ([a-z0-9]+): /####\1####/g;s/ether ([a-f0-9:]+) /####\1####/g'| grep -E -o '####[^ ]+####' | sed 's/#//g' | grep -B 1 ':') +IP_OUT=$(ip a | grep -B 1 "/ether" | sed -r '/^--$/d;$!N;s#^[0-9]+: ([a-z0-9\.:]+): .*?/ether ([0-9a-fA-Z:]+) .*$#\1==\2#') + +if ! echo "$IP_OUT" | grep -q -- "$MAC"; then + drop_shell "Boot interface not found in interface list. NIC driver missing?" +fi + +for LINE in $IP_OUT; do + IFACE=$(echo "$LINE" | awk -F '==' '{printf $1}') + IFMAC=$(echo "$LINE" | awk -F '==' '{printf $2}' | tr '[A-Z]' '[a-z]') # udev requires mac addesses to be lowercase (a-f), see http://www.debianhelp.co.uk/udev.htm + echo "${IFACE} = ${IFMAC}" + + if [ "x$IFMAC" == "x$MAC" ]; then + brctl addbr "$BRIDGE" || drop_shell "Could not create bridge $BRIDGE" + brctl stp "$BRIDGE" 0 + brctl setfd "$BRIDGE" 0.000000000001 + ip link set addr "$IFMAC" "$BRIDGE" || drop_shell "Could not set mac of $BRIDGE" + ip link set dev "$IFACE" up + wait_for_iface "$IFACE" + brctl addif "$BRIDGE" "$IFACE" || drop_shell "Could not add $IFACE to $BRIDGE" + + # save our variables for retry on fail + echo "IFACE=$IFACE" > /run/network.conf + + # analyze ip information from the kernel command line and put parts + # of it into several variables + if [ -n "$CLIENTIP" ] ; then + # set static ip address + ip addr add "$CLIENTIP/$(ipcalc -s -p "$CLIENTIP" "$SUBNET_MASK" | sed "s/.*=//")" broadcast "$BROADCAST_ADDRESS" dev "$BRIDGE" + ip link set dev "$BRIDGE" up + [ -n "$GATEWAY" ] && ip route add default via "$GATEWAY" dev "$BRIDGE" + else + NOIPYET="yes" + fi + # Ignore this device later on when systemd handles network interfaces (see hacked 99-systemd.rules in systemd data dir) + echo "SUBSYSTEM==\"net\", ACTION==\"add\", KERNEL==\"eth*\", ATTR{address}==\"$IFMAC\", TAG+=\"openslxignore\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/01-ignore-boot-interface.rules" + fi + # youdev + echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$IFMAC\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"$IFACE\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/70-net-boot-nic-name.rules" + # continue... + IFACE="" +done + +wait_for_iface "$BRIDGE" + +# udhcpc +PARAM= +if [ -n "$CLIENTIP" ]; then + PARAM="-r $CLIENTIP" +fi +echo -n "$CLIENTIP" > "/run/firstip" +echo -n "$GATEWAY" > "/run/firstgw" + +# save our variables for retry on fail ff. +echo "CLIENTIP=$CLIENTIP" >> /run/network.conf +echo "GATEWAY=$GATEWAY" >> /run/network.conf +echo "BRIDGE=$BRIDGE" >> /run/network.conf + +udhcpc $PARAM -O domain -O nissrv -O nisdomain -O wpad -O search -t 5 -T 2 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" +# udhcpc return value will be return value of this script diff --git a/testModule/debugging_tools/setup_network.sh b/testModule/debugging_tools/setup_network.sh deleted file mode 100644 index 3b32a68c..00000000 --- a/testModule/debugging_tools/setup_network.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash - -echo "Setting up network..." - -echo "Main MAC address is '$MAC'" - -# setup network -source /inc/network.functions - -# set up loopback networking -echo "Setting up loopback" -ip link set dev lo up 2>/dev/null -ip addr add 127.0.0.1/8 dev lo 2>/dev/null - -echo "Setting up bridge" -BRIDGE="br0" - -# Following was supposed to prevent scripts from getting confused by multiple interfaces with same MAC - does not work though -## Flip mac address of original interface - this var is not local so init sees the changes too -#MAC="$(echo "$MAC" | awk -F ':' '{printf $1 ":" $2 ":" $5 ":" $3 ":" $6 ":" $4}')" -#ip link set addr "$MAC" "$SLAVE" - -mkdir -p "${FUTURE_ROOT}/etc/udev/rules.d" - -#IP_OUT=$(ip a | sed -r ':a;N;$!ba;s/: ([a-z0-9]+): /####\1####/g;s/ether ([a-f0-9:]+) /####\1####/g'| grep -E -o '####[^ ]+####' | sed 's/#//g' | grep -B 1 ':') -IP_OUT=$(ip a | grep -B 1 "/ether" | sed -r '/^--$/d;$!N;s#^[0-9]+: ([a-z0-9\.:]+): .*?/ether ([0-9a-fA-Z:]+) .*$#\1==\2#') - -if ! echo "$IP_OUT" | grep -q -- "$MAC"; then - drop_shell "Boot interface not found in interface list. NIC driver missing?" -fi - -for LINE in $IP_OUT; do - IFACE=$(echo "$LINE" | awk -F '==' '{printf $1}') - IFMAC=$(echo "$LINE" | awk -F '==' '{printf $2}' | tr '[A-Z]' '[a-z]') # udev requires mac addesses to be lowercase (a-f), see http://www.debianhelp.co.uk/udev.htm - echo "${IFACE} = ${IFMAC}" - - if [ "x$IFMAC" == "x$MAC" ]; then - brctl addbr "$BRIDGE" || drop_shell "Could not create bridge $BRIDGE" - brctl stp "$BRIDGE" 0 - brctl setfd "$BRIDGE" 0.000000000001 - ip link set addr "$IFMAC" "$BRIDGE" || drop_shell "Could not set mac of $BRIDGE" - ip link set dev "$IFACE" up - wait_for_iface "$IFACE" - brctl addif "$BRIDGE" "$IFACE" || drop_shell "Could not add $IFACE to $BRIDGE" - - # save our variables for retry on fail - echo "IFACE=$IFACE" > /run/network.conf - - # analyze ip information from the kernel command line and put parts - # of it into several variables - if [ -n "$CLIENTIP" ] ; then - # set static ip address - ip addr add "$CLIENTIP/$(ipcalc -s -p "$CLIENTIP" "$SUBNET_MASK" | sed "s/.*=//")" broadcast "$BROADCAST_ADDRESS" dev "$BRIDGE" - ip link set dev "$BRIDGE" up - [ -n "$GATEWAY" ] && ip route add default via "$GATEWAY" dev "$BRIDGE" - else - NOIPYET="yes" - fi - # Ignore this device later on when systemd handles network interfaces (see hacked 99-systemd.rules in systemd data dir) - echo "SUBSYSTEM==\"net\", ACTION==\"add\", KERNEL==\"eth*\", ATTR{address}==\"$IFMAC\", TAG+=\"openslxignore\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/01-ignore-boot-interface.rules" - fi - # youdev - echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$IFMAC\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"$IFACE\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/70-net-boot-nic-name.rules" - # continue... - IFACE="" -done - -wait_for_iface "$BRIDGE" - -# udhcpc -PARAM= -if [ -n "$CLIENTIP" ]; then - PARAM="-r $CLIENTIP" -fi -echo -n "$CLIENTIP" > "/run/firstip" -echo -n "$GATEWAY" > "/run/firstgw" - -# save our variables for retry on fail ff. -echo "CLIENTIP=$CLIENTIP" >> /run/network.conf -echo "GATEWAY=$GATEWAY" >> /run/network.conf -echo "BRIDGE=$BRIDGE" >> /run/network.conf - -udhcpc $PARAM -O domain -O nissrv -O nisdomain -O wpad -O search -t 5 -T 2 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" -# udhcpc return value will be return value of this script diff --git a/testModule/hooks/pre-mount.sh b/testModule/hooks/pre-mount.sh index ed36db84..86fe94bf 100755 --- a/testModule/hooks/pre-mount.sh +++ b/testModule/hooks/pre-mount.sh @@ -8,9 +8,12 @@ else insmod /usr/lib/modules/3.10.0-229.1.2.el7.x86_64/extra/dnbd3.ko local dnbd3_device_node="$(dnbd3-client -h 132.230.4.1 -i stage4/torben/test \ -r 1 -d /dev/dnbd0)" - dnbd3_device_node='/dev/dnbd0' - qemu-img create -f qcow2 -o backing_file="$dnbd3_device_node",backing_fmt=qcow2 /run/test.qcow2 + # NOTE: Out comment this line if you need more than on dnbd0 device and + # determine it automatically. + dnbd3_device_node=/dev/dnbd0 + qemu-img create -f qcow2 -o \ + backing_file="$dnbd3_device_node",backing_fmt=qcow2 /run/test.qcow2 insmod /usr/lib/modules/3.10.0-229.1.2.el7.x86_64/extra/nbd.ko - /usr/bin/qemu-nbd-systemd-mark-alternate --connect=/dev/nbd0 \ - /run/test.qcow2 --socket /run/qemu-nbd-TEST + /usr/bin/systemd-preserve-process-marker /usr/bin/qemu-nbd \ + --connect=/dev/nbd0 /run/test.qcow2 --socket /run/qemu-nbd-TEST fi diff --git a/testModule/module-setup.sh b/testModule/module-setup.sh index e9bf84f8..fd6d51d7 100644 --- a/testModule/module-setup.sh +++ b/testModule/module-setup.sh @@ -30,12 +30,15 @@ install() { # Loads globally needed useful functions or fixes some native dracut ones. inst "$moddir/library.sh" /usr/lib/test-library.sh - inst "$moddir/binaries/systemd-preserve-process-marker" /usr/bin/systemd-preserve-process-marker + inst "$moddir/binaries/dnbd3-client" /usr/bin/dnbd3-client + inst "$moddir/binaries/systemd-preserve-process-marker" \ + /usr/bin/systemd-preserve-process-marker inst "$moddir/binaries/qemu-nbd" /usr/bin/qemu-nbd - inst "$moddir/binaries/qemu-nbd-systemd-mark-alternate" /usr/bin/qemu-nbd-systemd-mark-alternate - inst "$moddir/kernel_modules/dnbd3.ko" /usr/lib/modules/3.10.0-229.1.2.el7.x86_64/extra/dnbd3.ko - inst "$moddir/kernel_modules/nbd.ko" /usr/lib/modules/3.10.0-229.1.2.el7.x86_64/extra/nbd.ko + inst "$moddir/kernel_modules/dnbd3.ko" \ + /usr/lib/modules/3.10.0-229.1.2.el7.x86_64/extra/dnbd3.ko + inst "$moddir/kernel_modules/nbd.ko" \ + /usr/lib/modules/3.10.0-229.1.2.el7.x86_64/extra/nbd.ko # NOTE: Priority has to be lower than the network cmdline parsing hooks # since we have to modify the some kernel parameter before. diff --git a/testModule/systemd-preserve-process-marker.c b/testModule/systemd-preserve-process-marker.c index 172a5546..2525bc5f 100644 --- a/testModule/systemd-preserve-process-marker.c +++ b/testModule/systemd-preserve-process-marker.c @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) { copy[0][0] = '@'; argv[0][0] = '@'; if (-1 == execvp(argv[1], copy)) { - perror("child process execve failed [%m]"); + perror("Executing child process failed."); return -1; } } -- cgit v1.2.3-55-g7522