nvme_rbd_autorun.sh: don't mount debugfs twice
[ddiss/rapido.git] / nvme_rbd_autorun.sh
1 #!/bin/bash
2 #
3 # Copyright (C) SUSE LINUX GmbH 2016, 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 # this path is reliant on the rbd udev rule to setup the link
25 CEPH_RBD_DEV=/dev/rbd/${CEPH_RBD_POOL}/${CEPH_RBD_IMAGE}
26
27 #### start udevd, otherwise rbd hangs in wait_for_udev_add()
28 ps -eo args | grep -v grep | grep /usr/lib/systemd/systemd-udevd \
29         || /usr/lib/systemd/systemd-udevd --daemon
30
31 ##### map rbd device
32 _ini_parse "/etc/ceph/keyring" "client.${CEPH_USER}" "key"
33 [ -z "$key" ] && _fatal "client.${CEPH_USER} key not found in keyring"
34 if [ -z "$CEPH_MON_NAME" ]; then
35         # pass global section and use mon_host
36         _ini_parse "/etc/ceph/ceph.conf" "global" "mon_host"
37         MON_ADDRESS="$mon_host"
38 else
39         _ini_parse "/etc/ceph/ceph.conf" "mon.${CEPH_MON_NAME}" "mon_addr"
40         MON_ADDRESS="$mon_addr"
41 fi
42
43 echo -n "$MON_ADDRESS name=${CEPH_USER},secret=$key \
44          $CEPH_RBD_POOL $CEPH_RBD_IMAGE -" \
45          > /sys/bus/rbd/add || _fatal "RBD map failed"
46 udevadm settle || _fatal
47
48 # confirm that udev brought up the $pool/$img device path link
49 [ -L $CEPH_RBD_DEV ] || _fatal
50
51 # enable debugfs
52 cat /proc/mounts | grep debugfs &> /dev/null
53 if [ $? -ne 0 ]; then
54         mount -t debugfs debugfs /sys/kernel/debug/
55 fi
56
57 # mount configfs first
58 cat /proc/mounts | grep configfs &> /dev/null
59 if [ $? -ne 0 ]; then
60         mount -t configfs configfs /sys/kernel/config/
61 fi
62
63 for i in $DYN_DEBUG_MODULES; do
64         echo "module $i +pf" > /sys/kernel/debug/dynamic_debug/control || _fatal
65 done
66 for i in $DYN_DEBUG_FILES; do
67         echo "file $i +pf" > /sys/kernel/debug/dynamic_debug/control || _fatal
68 done
69
70 modprobe nvme-core || _fatal
71 modprobe nvme-fabrics || _fatal
72 modprobe nvme-loop || _fatal
73 modprobe nvmet || _fatal
74
75 mkdir -p /sys/kernel/config/nvmet/subsystems/nvmf-test
76 cd /sys/kernel/config/nvmet/subsystems/nvmf-test
77 echo 1 > attr_allow_any_host
78 mkdir namespaces/1
79 cd namespaces/1
80 echo -n $CEPH_RBD_DEV > device_path
81 echo 1 > enable
82
83 mkdir /sys/kernel/config/nvmet/ports/1
84 cd /sys/kernel/config/nvmet/ports/1
85 echo loop > addr_trtype
86
87 ln -s /sys/kernel/config/nvmet/subsystems/nvmf-test subsystems/nvmf-test
88
89 echo "transport=loop,nqn=nvmf-test" > /dev/nvme-fabrics
90
91 set +x
92
93 echo "RBD mapped at: $CEPH_RBD_DEV, NVMe mapped"