Merge pull request #17 from luis-henrix/pr_hardcoded_lib_paths
[ddiss/rapido.git] / blktests_rbd_autorun.sh
1 #!/bin/bash
2 #
3 # Copyright (C) SUSE LINUX GmbH 2017, all rights reserved.
4 #
5 # This library is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published
7 # by the Free Software Foundation; either version 2.1 of the License, or
8 # (at your option) version 3.
9 #
10 # This library is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
13 # License for more details.
14
15 if [ ! -f /vm_autorun.env ]; then
16         echo "Error: autorun scripts must be run from within an initramfs VM"
17         exit 1
18 fi
19
20 . /vm_autorun.env
21
22 set -x
23
24 # path to blktests within the initramfs
25 BLKTESTS_DIR="/blktests"
26 [ -d "$BLKTESTS_DIR" ] || _fatal "blktests missing"
27
28 # this path is reliant on the rbd udev rule to setup the link
29 CEPH_RBD_DEV=/dev/rbd/${CEPH_RBD_POOL}/${CEPH_RBD_IMAGE}
30
31 #### start udevd, otherwise rbd hangs in wait_for_udev_add()
32 ps -eo args | grep -v grep | grep /usr/lib/systemd/systemd-udevd \
33         || /usr/lib/systemd/systemd-udevd --daemon
34
35 ##### map rbd device
36 _ini_parse "/etc/ceph/keyring" "client.${CEPH_USER}" "key"
37 [ -z "$key" ] && _fatal "client.${CEPH_USER} key not found in keyring"
38 if [ -z "$CEPH_MON_NAME" ]; then
39         # pass global section and use mon_host
40         _ini_parse "/etc/ceph/ceph.conf" "global" "mon_host"
41         MON_ADDRESS="$mon_host"
42 else
43         _ini_parse "/etc/ceph/ceph.conf" "mon.${CEPH_MON_NAME}" "mon_addr"
44         MON_ADDRESS="$mon_addr"
45 fi
46
47 echo -n "$MON_ADDRESS name=${CEPH_USER},secret=$key \
48          $CEPH_RBD_POOL $CEPH_RBD_IMAGE -" \
49          > /sys/bus/rbd/add || _fatal "RBD map failed"
50 udevadm settle || _fatal
51
52 # confirm that udev brought up the $pool/$img device path link
53 [ -L $CEPH_RBD_DEV ] || _fatal
54
55 # enable debugfs
56 cat /proc/mounts | grep debugfs &> /dev/null
57 if [ $? -ne 0 ]; then
58         mount -t debugfs debugfs /sys/kernel/debug/
59 fi
60
61 cat /proc/mounts | grep configfs &> /dev/null
62 if [ $? -ne 0 ]; then
63         mount -t configfs configfs /sys/kernel/config/
64 fi
65
66 for i in $DYN_DEBUG_MODULES; do
67         echo "module $i +pf" > /sys/kernel/debug/dynamic_debug/control || _fatal
68 done
69 for i in $DYN_DEBUG_FILES; do
70         echo "file $i +pf" > /sys/kernel/debug/dynamic_debug/control || _fatal
71 done
72
73 echo "TEST_DEVS=(${CEPH_RBD_DEV})" > ${BLKTESTS_DIR}/config
74
75 set +x
76
77 echo "$CEPH_RBD_DEV mapped and ready for ${BLKTESTS_DIR}/check"
78
79 if [ -n "$BLKTESTS_AUTORUN_CMD" ]; then
80         cd ${BLKTESTS_DIR} || _fatal
81         eval "$BLKTESTS_AUTORUN_CMD"
82 fi