From 153d299a41b9be4e15dab1ca29bb93a74bd2445d Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Fri, 29 Apr 2016 14:36:26 -0400 Subject: fix paths (in progress) --- src/initrd/samizdat-cdrom-copy | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 src/initrd/samizdat-cdrom-copy (limited to 'src/initrd/samizdat-cdrom-copy') diff --git a/src/initrd/samizdat-cdrom-copy b/src/initrd/samizdat-cdrom-copy new file mode 100755 index 0000000..d4920b9 --- /dev/null +++ b/src/initrd/samizdat-cdrom-copy @@ -0,0 +1,75 @@ +#!/bin/sh +md_name=$1 +lv_name=$2 +lv_dev=$3 +cdrom_loopdev=$4 +cdrom_dev=$5 + +. lvm-create.sh + +mdadm_wait_remove() +{ + # We should perhaps use mdadm --monitor's RebuildFinished event. + + local dev="$1" disk="$2" tries + if ! mdadm --wait "$dev"; then + tries=1000 + while ! mdadm --detail --test "$dev"; do + [ $tries -gt 0 ] || return 1 + sleep 1 + tries=$((tries-1)) + done + fi + + mdadm "$dev" --fail "$disk" || return 1 + tries=100 + while ! mdadm "$dev" --remove "$disk"; do + [ $tries -gt 0 ] || return 1 + sleep 1 + tries=$((tries-1)) + done + return 0 +} + + +Done() +{ + mdadm --grow "$md_name" -n 1 --force + lvm lvrename "$lv_name".tmp "${lv_name#*/}" + losetup -d "$cdrom_loopdev" + [ -e /etc/mtab ] || ln -sf /proc/mounts /etc/mtab + eject "$cdrom_dev" + echo "[$$] Done." +} + +exec >>/var/log/samizdat-cdrom-copy.log 2>&1 +echo "[$$] Waiting for $cdrom_loopdev ($cdrom_dev) to be removed from $md_name." + +if mdadm_wait_remove "$md_name" "$cdrom_loopdev"; then + Done; +else + echo "[$$] Warning: mdadm_wait_remove() returned $?. Doing manual copy with sg_dd (using continue-on-error)." + mdadm -D "$md_name" + mdadm "$md_name" --fail "$lv_dev".tmp + mdadm -D "$md_name" + mdadm "$md_name" --remove "$lv_dev".tmp + mdadm -D "$md_name" + mdadm /dev/md55 --grow -n1 --force + mdadm -D "$md_name" + + sizelimit=$(get_cdrom_sizelimit "$cdrom_dev") + + if sg_dd bs=2048 ${sizelimit:+count=$((sizelimit/2048))} iflag=coe,coe,coe if="$cdrom_dev" of="$lv_dev".tmp retries=42; then + echo "[$$] sg_dd succeeded." + mdadm "$md_name" --grow -n 2 --assume-clean --add "$lv_dev".tmp + mdadm -D "$md_name" + if mdadm_wait_remove "$md_name" "$cdrom_loopdev"; then + Done; + else + echo "[$$] Error: mdadm_wait_remove() returned $? after sg_dd. Cannot eject CDROM!" + fi + else + echo "[$$] Error: sg_dd returned $?. Cannot eject CDROM!" + fi +fi + -- cgit v1.2.3