3 # Copyright (C) SUSE LINUX GmbH 2017, all rights reserved.
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.
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.
15 if [ ! -f /vm_autorun.env ]; then
16 echo "Error: autorun scripts must be run from within an initramfs VM"
22 function _zram_hot_add() {
23 [ -e /sys/class/zram-control/hot_add ] \
24 || _fatal "zram hot_add sysfs path missing (old kernel?)"
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}"
32 /sys/devices/virtual/block/zram${zram_num}/disksize \
33 || _fatal "failed to set size for $zram_dev"
40 ps -eo args | grep -v grep | grep /usr/lib/systemd/systemd-udevd \
41 || /usr/lib/systemd/systemd-udevd --daemon
43 cat /proc/mounts | grep debugfs &> /dev/null
45 mount -t debugfs debugfs /sys/kernel/debug/
48 cat /proc/mounts | grep configfs &> /dev/null
50 mount -t configfs configfs /sys/kernel/config/
57 modprobe zram num_devices="0"
59 for i in $DYN_DEBUG_MODULES; do
60 echo "module $i +pf" > /sys/kernel/debug/dynamic_debug/control || _fatal
62 for i in $DYN_DEBUG_FILES; do
63 echo "file $i +pf" > /sys/kernel/debug/dynamic_debug/control || _fatal
66 export_blockdev=$(_zram_hot_add "1G")
67 [ -b "$export_blockdev" ] || _fatal "$export_blockdev device not available"
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 \
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 \
79 > ${nvmet_cfs}/subsystems/${nvmet_subsystem}/namespaces/1/enable \
82 mkdir ${nvmet_cfs}/ports/1 || _fatal
83 echo loop > ${nvmet_cfs}/ports/1/addr_trtype || _fatal
85 ln -s ${nvmet_cfs}/subsystems/${nvmet_subsystem} \
86 ${nvmet_cfs}/ports/1/subsystems/${nvmet_subsystem} || _fatal
88 echo "transport=loop,nqn=${nvmet_subsystem}" > /dev/nvme-fabrics || _fatal
92 echo "$export_blockdev mapped via NVMe loopback"