k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/test/images/volume/iscsi/run_iscsi_target.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2018 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # This script does not run any daemon, it only configures iSCSI target (=server) 18 # in kernel. It is possible to run this script multiple times on a single 19 # node, each run will create its own IQN and LUN. 20 21 # Kubernetes must provide unique name. 22 IQN=$1 23 24 function start() 25 { 26 # Create new IQN (iSCSI Qualified Name) 27 targetcli /iscsi create "$IQN" 28 # Run it in demo mode, i.e. no authentication 29 targetcli /iscsi/"$IQN"/tpg1 set attribute authentication=0 demo_mode_write_protect=0 generate_node_acls=1 cache_dynamic_acls=1 30 31 # Create unique "block volume" (i.e. flat file) on the *host*. 32 # Having it in the container confuses kernel from some reason 33 # and it's not able to server multiple LUNs from different 34 # containers. 35 # /srv/iscsi must be bind-mount from the host. 36 cp /block /srv/iscsi/"$IQN" 37 38 # Make the block volume available through our IQN as LUN 0 39 targetcli /backstores/fileio create block-"$IQN" /srv/iscsi/"$IQN" 40 targetcli /iscsi/"$IQN"/tpg1/luns create /backstores/fileio/block-"$IQN" 41 42 echo "iscsi target started" 43 } 44 45 function stop() 46 { 47 echo "stopping iscsi target" 48 # Remove IQN 49 targetcli /iscsi/"$IQN"/tpg1/luns/ delete 0 50 targetcli /iscsi delete "$IQN" 51 # Remove block device mapping 52 targetcli /backstores/fileio delete block-"$IQN" 53 /bin/rm -f /srv/iscsi/"$IQN" 54 echo "iscsi target stopped" 55 exit 0 56 } 57 58 59 trap stop TERM 60 start 61 62 while true; do 63 sleep 1 64 done