cut_fstests: add missing dependencies
[ddiss/rapido.git] / nvme_local_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 function _zram_hot_add() {
23         [ -e /sys/class/zram-control/hot_add ] \
24                 || _fatal "zram hot_add sysfs path missing (old kernel?)"
25
26         local zram_size="$1"
27         local zram_num=$(cat /sys/class/zram-control/hot_add) \
28                 || _fatal "zram hot add failed"
29         local zram_dev="/dev/zram${zram_num}"
30
31         echo "$zram_size" > \
32                 /sys/devices/virtual/block/zram${zram_num}/disksize \
33                 || _fatal "failed to set size for $zram_dev"
34         echo "$zram_dev"
35 }
36
37 set -x
38
39 #### start udevd
40 ps -eo args | grep -v grep | grep /usr/lib/systemd/systemd-udevd \
41         || /usr/lib/systemd/systemd-udevd --daemon
42
43 cat /proc/mounts | grep debugfs &> /dev/null
44 if [ $? -ne 0 ]; then
45         mount -t debugfs debugfs /sys/kernel/debug/
46 fi
47
48 cat /proc/mounts | grep configfs &> /dev/null
49 if [ $? -ne 0 ]; then
50         mount -t configfs configfs /sys/kernel/config/
51 fi
52
53 modprobe nvme-core
54 modprobe nvme-fabrics
55 modprobe nvme-loop
56 modprobe nvmet
57 modprobe zram num_devices="0"
58
59 for i in $DYN_DEBUG_MODULES; do
60         echo "module $i +pf" > /sys/kernel/debug/dynamic_debug/control || _fatal
61 done
62 for i in $DYN_DEBUG_FILES; do
63         echo "file $i +pf" > /sys/kernel/debug/dynamic_debug/control || _fatal
64 done
65
66 export_blockdev=$(_zram_hot_add "1G")
67 [ -b "$export_blockdev" ] || _fatal "$export_blockdev device not available"
68
69 nvmet_cfs="/sys/kernel/config/nvmet/"
70 nvmet_subsystem="nvmf-test"
71 mkdir -p ${nvmet_cfs}/subsystems/${nvmet_subsystem} || _fatal
72 echo 1 > ${nvmet_cfs}/subsystems/${nvmet_subsystem}/attr_allow_any_host \
73         || _fatal
74 mkdir ${nvmet_cfs}/subsystems/${nvmet_subsystem}/namespaces/1 || _fatal
75 echo -n $export_blockdev \
76         > ${nvmet_cfs}/subsystems/${nvmet_subsystem}/namespaces/1/device_path \
77         || _fatal
78 echo -n 1 \
79         > ${nvmet_cfs}/subsystems/${nvmet_subsystem}/namespaces/1/enable \
80         || _fatal
81
82 mkdir ${nvmet_cfs}/ports/1 || _fatal
83 echo loop > ${nvmet_cfs}/ports/1/addr_trtype || _fatal
84
85 ln -s ${nvmet_cfs}/subsystems/${nvmet_subsystem} \
86         ${nvmet_cfs}/ports/1/subsystems/${nvmet_subsystem} || _fatal
87
88 echo "transport=loop,nqn=${nvmet_subsystem}" > /dev/nvme-fabrics || _fatal
89
90 set +x
91
92 echo "$export_blockdev mapped via NVMe loopback"