요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
#!/bin/sh
#
# This script illustrates the sequence of operations in configfs to
# create a very simple LIO iSCSI target with a file or block device
# backstore.
#
# (C) Copyright 2014 Christophe Vu-Brugier <[email protected]>
#
print_usage() {
cat <<EOF
Usage: $(basename $0) [-p PORTAL] DEVICE|FILE
Export a block device or a file as an iSCSI target with a single LUN
EOF
}
die() {
echo $1
exit 1
}
while getopts "hp:" arg; do
case $arg in
h) print_usage; exit 0;;
p) PORTAL=${OPTARG};;
esac
done
shift $(($OPTIND - 1))
DEVICE=$1
[ -n "$DEVICE" ] || die "Missing device or file argument"
[ -b $DEVICE -o -f $DEVICE ] || die "Invalid device or file: ${DEVICE}"
IQN="iqn.2003-01.org.linux-iscsi.$(hostname):$(basename $DEVICE)"
[ -n "$PORTAL" ] || PORTAL="0.0.0.0:3260"
CONFIGFS=/sys/kernel/config
CORE_DIR=$CONFIGFS/target/core
ISCSI_DIR=$CONFIGFS/target/iscsi
# Load the target modules and mount the config file system
lsmod | grep -q configfs || modprobe configfs
lsmod | grep -q target_core_mod || modprobe target_core_mod
mount | grep -q ^configfs || mount -t configfs none $CONFIGFS
mkdir -p $ISCSI_DIR
# Create a backstore
if [ -b $DEVICE ]; then
BACKSTORE_DIR=$CORE_DIR/iblock_0/data
mkdir -p $BACKSTORE_DIR
echo "udev_path=${DEVICE}" > $BACKSTORE_DIR/control
else
BACKSTORE_DIR=$CORE_DIR/fileio_0/data
mkdir -p $BACKSTORE_DIR
DEVICE_SIZE=$(du -b $DEVICE | cut -f1)
echo "fd_dev_name=${DEVICE}" > $BACKSTORE_DIR/control
echo "fd_dev_size=${DEVICE_SIZE}" > $BACKSTORE_DIR/control
echo 1 > $BACKSTORE_DIR/attrib/emulate_write_cache
fi
echo 1 > $BACKSTORE_DIR/enable
# Create an iSCSI target and a target portal group (TPG)
mkdir $ISCSI_DIR/$IQN
mkdir $ISCSI_DIR/$IQN/tpgt_1/
# Create a LUN
mkdir $ISCSI_DIR/$IQN/tpgt_1/lun/lun_0
ln -s $BACKSTORE_DIR $ISCSI_DIR/$IQN/tpgt_1/lun/lun_0/data
echo 1 > $ISCSI_DIR/$IQN/tpgt_1/enable
# Create a network portal
mkdir $ISCSI_DIR/$IQN/tpgt_1/np/$PORTAL
# Disable authentication
echo 0 > $ISCSI_DIR/$IQN/tpgt_1/attrib/authentication
echo 1 > $ISCSI_DIR/$IQN/tpgt_1/attrib/generate_node_acls
# Allow write access for non authenticated initiators
echo 0 > $ISCSI_DIR/$IQN/tpgt_1/attrib/demo_mode_write_protect
echo "Target ${IQN}, portal ${PORTAL} has been created"
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
목적과 사용법
1-15이 `/bin/sh` script는 configfs 작업 순서를 통해 file 또는 block device backstore를 가진 매우 단순한 LIO iSCSI target을 만드는 예다. 2014년 Christophe Vu-Brugier가 저작권을 표시했다.
사용법은 `target-export-device [-p PORTAL] DEVICE|FILE`이다. block device 또는 file 하나를 단일 LUN의 iSCSI target으로 export하며 `-p`로 network portal을 지정할 수 있다.
script가 받는 입력이다.
#!/bin/sh
#
# This script illustrates the sequence of operations in configfs to
# create a very simple LIO iSCSI target with a file or block device
# backstore.
#
# (C) Copyright 2014 Christophe Vu-Brugier <[email protected]>
#
print_usage() {
cat <<EOF
Usage: $(basename $0) [-p PORTAL] DEVICE|FILE
Export a block device or a file as an iSCSI target with a single LUN
EOF
}
인자 검증과 configfs 경로
16-38`die()`는 error message를 출력하고 status 1로 종료한다. `getopts "hp:"`는 help와 portal option을 처리하고, `shift $(($OPTIND - 1))`로 option을 제거한 뒤 첫 positional argument를 `DEVICE`로 받는다.
인자가 비었으면 `Missing device or file argument`, block device나 regular file이 아니면 `Invalid device or file`로 종료한다.
IQN은 `iqn.2003-01.org.linux-iscsi.$(hostname):$(basename $DEVICE)` 형식으로 만든다. portal을 지정하지 않으면 `0.0.0.0:3260`을 사용한다. configfs root는 `/sys/kernel/config`, core backstore 경로는 `$CONFIGFS/target/core`, iSCSI 경로는 `$CONFIGFS/target/iscsi`다.
입력을 검증하고 target identity와 configfs root를 정한다.
script가 파생하는 주요 값이다.
die() {
echo $1
exit 1
}
while getopts "hp:" arg; do
case $arg in
h) print_usage; exit 0;;
p) PORTAL=${OPTARG};;
esac
done
shift $(($OPTIND - 1))
DEVICE=$1
[ -n "$DEVICE" ] || die "Missing device or file argument"
[ -b $DEVICE -o -f $DEVICE ] || die "Invalid device or file: ${DEVICE}"
IQN="iqn.2003-01.org.linux-iscsi.$(hostname):$(basename $DEVICE)"
[ -n "$PORTAL" ] || PORTAL="0.0.0.0:3260"
CONFIGFS=/sys/kernel/config
CORE_DIR=$CONFIGFS/target/core
ISCSI_DIR=$CONFIGFS/target/iscsi
Module 준비와 backstore 생성
39-59먼저 `configfs`와 `target_core_mod`가 load되어 있는지 `lsmod`로 확인하고 없으면 `modprobe`한다. configfs가 mount되지 않았으면 `/sys/kernel/config`에 mount한 뒤 iSCSI directory를 만든다.
입력이 block device이면 backstore를 `$CORE_DIR/iblock_0/data`에 만들고 `control`에 `udev_path=$DEVICE`를 기록한다.
입력이 file이면 `$CORE_DIR/fileio_0/data`를 만들고 `du -b`로 byte size를 구한다. `control`에 `fd_dev_name`과 `fd_dev_size`를 기록하고 `attrib/emulate_write_cache`를 1로 설정한다.
두 경우 모두 마지막에 backstore의 `enable` file에 1을 기록해 활성화한다.
입력 file type에 따라 iblock 또는 fileio control을 구성한다.
# Load the target modules and mount the config file system
lsmod | grep -q configfs || modprobe configfs
lsmod | grep -q target_core_mod || modprobe target_core_mod
mount | grep -q ^configfs || mount -t configfs none $CONFIGFS
mkdir -p $ISCSI_DIR
# Create a backstore
if [ -b $DEVICE ]; then
BACKSTORE_DIR=$CORE_DIR/iblock_0/data
mkdir -p $BACKSTORE_DIR
echo "udev_path=${DEVICE}" > $BACKSTORE_DIR/control
else
BACKSTORE_DIR=$CORE_DIR/fileio_0/data
mkdir -p $BACKSTORE_DIR
DEVICE_SIZE=$(du -b $DEVICE | cut -f1)
echo "fd_dev_name=${DEVICE}" > $BACKSTORE_DIR/control
echo "fd_dev_size=${DEVICE_SIZE}" > $BACKSTORE_DIR/control
echo 1 > $BACKSTORE_DIR/attrib/emulate_write_cache
fi
echo 1 > $BACKSTORE_DIR/enable
iSCSI target, TPG와 LUN
60-69script는 `$ISCSI_DIR/$IQN`에 iSCSI target을 만들고 그 아래 `tpgt_1` target portal group을 생성한다.
`tpgt_1/lun/lun_0` directory를 만든 뒤 선택한 backstore directory를 `lun_0/data`에 symbolic link한다. 이어 `tpgt_1/enable`에 1을 써 TPG를 활성화한다.
configfs object와 backstore 연결 구조다.
# Create an iSCSI target and a target portal group (TPG)
mkdir $ISCSI_DIR/$IQN
mkdir $ISCSI_DIR/$IQN/tpgt_1/
# Create a LUN
mkdir $ISCSI_DIR/$IQN/tpgt_1/lun/lun_0
ln -s $BACKSTORE_DIR $ISCSI_DIR/$IQN/tpgt_1/lun/lun_0/data
echo 1 > $ISCSI_DIR/$IQN/tpgt_1/enable
Portal과 인증 설정
70-80network portal은 `$ISCSI_DIR/$IQN/tpgt_1/np/$PORTAL` directory를 만들어 등록한다.
예제는 `authentication`을 0으로 꺼 두고 `generate_node_acls`를 1로 설정해 ACL을 자동 생성한다. 인증하지 않은 initiator에도 write access를 허용하도록 `demo_mode_write_protect`를 0으로 설정한다.
마지막으로 생성한 target IQN과 portal을 출력한다. 이 설정은 인증을 끄고 write를 허용하는 최소 예제이므로 실제 배포에서는 접근 제어와 network 노출 범위를 별도로 설계해야 한다.
예제에서 설정하는 접근 제어 값이다.
# Create a network portal
mkdir $ISCSI_DIR/$IQN/tpgt_1/np/$PORTAL
# Disable authentication
echo 0 > $ISCSI_DIR/$IQN/tpgt_1/attrib/authentication
echo 1 > $ISCSI_DIR/$IQN/tpgt_1/attrib/generate_node_acls
# Allow write access for non authenticated initiators
echo 0 > $ISCSI_DIR/$IQN/tpgt_1/attrib/demo_mode_write_protect
echo "Target ${IQN}, portal ${PORTAL} has been created"
요약·해설
target-export-device:1-80block device 또는 file backstore로 단일 LUN LIO iSCSI target을 만드는 configfs shell script의 인자, object 생성 순서와 접근 설정을 설명합니다.