Skip to content

Commit

Permalink
cmd-buildextend-metal: use serial= to mark target disk
Browse files Browse the repository at this point in the history
Instead of using SCSI, use virtio-blk's `serial=` option so allow us to
identify the disk inside `create_disk.sh`. And since we already have
udev running there now, we don't have to walk sysfs anymore looking for
our block device.
  • Loading branch information
jlebon committed Apr 24, 2020
1 parent e3f3ab8 commit ef247f1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/cmd-buildextend-metal
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ if [ -n "${ref_is_temp}" ]; then
ref_arg=${commit}
fi

target_device_opt="scsi-disk,drive=target,wwn=0x2a"
extra_target_device_opts=""
# we need 4096 block size for ECKD DASD and (obviously) metal4k
if [[ $image_type == dasd || $image_type == metal4k ]]; then
target_device_opt="${target_device_opt},physical_block_size=4096,logical_block_size=4096"
extra_target_device_opts="physical_block_size=4096,logical_block_size=4096"
fi
target_drive=("-drive" "if=none,id=target,format=${image_format},file=${path}.tmp,cache=unsafe" \
"-device" "virtio-scsi-${devtype},id=scsitarget" "-device" "${target_device_opt}")
"-device" "virtio-blk,serial=target,drive=target${extra_target_device_opts}")

runvm "${target_drive[@]}" -- \
/usr/lib/coreos-assembler/create_disk.sh \
Expand Down
11 changes: 5 additions & 6 deletions src/cmdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ export basearch
# Get target architecture
arch=$(uname -m)
export arch
devtype=pci

case $arch in
"x86_64") DEFAULT_TERMINAL="ttyS0" ;;
"ppc64le") DEFAULT_TERMINAL="hvc0" ;;
"aarch64") DEFAULT_TERMINAL="ttyAMA0" ;;
"s390x") DEFAULT_TERMINAL="ttysclp0"; devtype=ccw ;;
"x86_64") DEFAULT_TERMINAL="ttyS0" ;;
"ppc64le") DEFAULT_TERMINAL="hvc0" ;;
"aarch64") DEFAULT_TERMINAL="ttyAMA0" ;;
"s390x") DEFAULT_TERMINAL="ttysclp0";;
*) fatal "Architecture $(arch) not supported"
esac
export DEFAULT_TERMINAL devtype
export DEFAULT_TERMINAL

_privileged=
has_privileges() {
Expand Down
18 changes: 1 addition & 17 deletions src/create_disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,7 @@ udevtrig() {
export PATH=$PATH:/sbin:/usr/sbin
arch="$(uname -m)"

if [ -z "${disk:-}" ]; then
# hex 0x2a = 42 in decimal; this is set in cmd-buildextend-metal.
# We use the WWN as an unambiguous way to identify our target disk,
# independent of other devices attached to the VM (caches, etc.)
wwn=000000000000002a
for dev in /sys/block/*; do
if grep -F -e "${wwn}" "${dev}/device/wwid" 2>/dev/null; then
disk="/dev/$(basename ${dev})"
break
fi
done
if [ -z "${disk:-}" ]; then
echo "failed to find disk with wwn ${wwn}" 1>&2
bash
exit 1
fi
fi
disk=$(realpath /dev/disk/by-id/virtio-target)

buildid="${buildid:?--buildid must be defined}"
imgid="${imgid:?--imgid must be defined}"
Expand Down

0 comments on commit ef247f1

Please sign in to comment.