diff options
author | Jonathan Bauer | 2015-05-07 18:10:51 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-05-07 18:10:51 +0200 |
commit | deacdfe13b2eac8e84d72a62bb5c161436aa3c19 (patch) | |
tree | ceec94c9da31cb24cd680412357b9fb4d2ab62a9 /testModule/scripts/prepare-disks | |
parent | prepare-disk: check state of disk detection when an instance sees another (diff) | |
download | systemd-init-deacdfe13b2eac8e84d72a62bb5c161436aa3c19.tar.gz systemd-init-deacdfe13b2eac8e84d72a62bb5c161436aa3c19.tar.xz systemd-init-deacdfe13b2eac8e84d72a62bb5c161436aa3c19.zip |
added pids to log messages for better debugging
Diffstat (limited to 'testModule/scripts/prepare-disks')
-rwxr-xr-x | testModule/scripts/prepare-disks | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/testModule/scripts/prepare-disks b/testModule/scripts/prepare-disks index 1992a262..2e68dd9e 100755 --- a/testModule/scripts/prepare-disks +++ b/testModule/scripts/prepare-disks @@ -25,14 +25,14 @@ declare -rg OPENSLX_SYS_MOUNT="/opt/openslx/system" # Usage: mount_sys_part <path_to_sys_partition> mount_sys_part() { if [ ! -b "$1" ]; then - warn "Refusing to mount '$1' as its not a block device!" + warn "($$) Refusing to mount '$1' as its not a block device!" return 1 fi local OPENSLX_SYS_DEVICE="$1" mkdir -p ${OPENSLX_SYS_MOUNT} if ! mount -t auto "${OPENSLX_SYS_DEVICE}" "${OPENSLX_SYS_MOUNT}"; then - warn "Mounting '${OPENSLX_SYS_DEVICE}' to '${OPENSLX_SYS_MOUNT}' failed." + warn "($$) Mounting '${OPENSLX_SYS_DEVICE}' to '${OPENSLX_SYS_MOUNT}' failed." return 1 fi return 0 @@ -58,13 +58,13 @@ format_disk () { mkfs.xfs) fopt="-fq" ;; mkfs.ext4) fopt="-Fq" ;; esac - info "Formatting $TARGET_DEVICE as $fs" + info "($$) Formatting $TARGET_DEVICE as $fs" return $(${MKFS} ${fopt} "${TARGET_DEVICE}") fi [ -n "$found" ] && break done # still here? then we didn't find a proper formatter... - warn "Could not format $PART_DEV as $fs." + warn "($$) Could not format $PART_DEV as $fs." return 1 } @@ -80,17 +80,17 @@ command -v warn >/dev/null || . /lib/dracut-lib.sh # let check the arguments if [ "$#" -ne 2 ]; then - warn "'$0' need 2 arguments: '$0 [OPENSLX_SYS|OPENSLX_TMP] <dev_path>'" + warn "($$) '$0' need 2 arguments: '$0 [OPENSLX_SYS|OPENSLX_TMP] <dev_path>'" exit 1 fi # $1 sane? if [ "x$1" != "xOPENSLX_SYS" ] && [ "x$1" != "xOPENSLX_TMP" ]; then - warn "First arg needs to be either 'OPENSLX_SYS' or 'OPENSLX_TMP', given: $1" + warn "($$) First arg needs to be either 'OPENSLX_SYS' or 'OPENSLX_TMP', given: $1" exit 1 fi # $2 sane? if [ ! -b "/dev/$2" ]; then - warn "Second arg appears not to be a block device!" + warn "($$) Second arg appears not to be a block device!" exit 1 fi @@ -106,7 +106,7 @@ INSTANCES="$(grep "$PART_TYPE" "$OPENSLX_DISK_FLAG" | busybox wc -l)" if [ "$INSTANCES" -ge 1 ]; then # uhoh we are not alone! Need to check # if the other instance actually did its job - warn "'$0' already running for $PART_TYPE ... checking state." + warn "($$) '$0' already running for $PART_TYPE on $PART_DEV... checking state." # here two/three cases depending on which PART_TYPE we are # currently processing. for timeout in 1 1 2; do @@ -116,41 +116,54 @@ if [ "$INSTANCES" -ge 1 ]; then case "$PART_TYPE" in OPENSLX_TMP) # was the tmp partition marker created with a device? - [ -f "${OPENSLX_TMP_MARKER}" ] || continue + if [ ! -f "${OPENSLX_TMP_MARKER}" ]; then + info "($$) Invalid state: no marker for $PART_TYPE" + continue + fi # it was, is it a valid block device? OPENSLX_TMP_DEVICE="$(cat ${OPENSLX_TMP_MARKER})" - [ -b $OPENSLX_TMP_DEVICE ] || continue + if [ -z $OPENSLX_TMP_DEVICE -o ! -b $OPENSLX_TMP_DEVICE ]; then + info "($$) Invalid state: no for device $OPENSLX_TMP_DEVICE" + continue + fi # its detected, its a block device and as mounting is # done later, we can not check for more at this point - info "Valid state for $OPENSLX_TMP_DEVICE" + info "($$) Valid state for $OPENSLX_TMP_DEVICE as $PART_TYPE" exit 0 ;; OPENSLX_SYS) # was the system partition marker created with a device? - [ -f "${OPENSLX_SYS_MARKER}" ] || continue + if [ ! -f "${OPENSLX_SYS_MARKER}" ]; then + info "($$) Invalid state: no marker for $PART_TYPE" + continue + fi # it was, is it a valid block device? OPENSLX_SYS_DEVICE="$(cat ${OPENSLX_SYS_MARKER})" - [ -b $OPENSLX_SYS_DEVICE ] || continue + if [ -z $OPENSLX_SYS_DEVICE -o ! -b $OPENSLX_SYS_DEVICE ]; then + info "($$) Invalid state: no for device $OPENSLX_SYS_DEVICE" + continue + fi # its detected, its a block device, is it mounted? if mount | grep -qE "^$OPENSLX_SYS_DEVICE\ on $OPENSLX_SYS_MOUNT"; then - info "Valid state for $OPENSLX_SYS_DEVICE" + info "($$) Valid state for $OPENSLX_SYS_DEVICE as $PART_TYPE" exit 0 fi # if its not mounted, we want to keep on, so no exit! ;; *) # weird case which should never happen - warn "If you see this, then $0 was called with a bad PART_TYPE: $@" + warn "($$) If you see this, then $0 was called with a bad PART_TYPE: $@" continue ;; esac done - warn "'$PART_TYPE' was found but not device was associated to it!" + warn "($$) Timeout reached!" + warn "($$) '$PART_TYPE' was found but not device was associated to it!" fi # We write our pid to $OPENSLX_DISK_FLAG in order to make sure # we are the only instance of this script running. -info "Processing: $PART_TYPE -> $PART_DEV ($$)" +info "($$) Processing: $PART_TYPE -> $PART_DEV ($$)" echo "$PART_TYPE.$$" >> "$OPENSLX_DISK_FLAG" # if we are still here, then we can go on and process the partition @@ -158,11 +171,11 @@ if [ "$PART_TYPE" = "OPENSLX_TMP" ]; then # always format /tmp partition if ! format_disk "${PART_DEV}" xfs; then # error while formatting, cleanup - warn "Error formatting $PART_DEV ... removing $$" + warn "($$) Error formatting $PART_DEV ... removing $$" sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" exit 1 fi - info "Using '$PART_DEV' as '$PART_TYPE'" + info "($$) Using '$PART_DEV' as '$PART_TYPE'" # mark it for later: in pre-pivot we will check this file # and mount it as $NEWROOT/tmp echo "$PART_DEV" > "$OPENSLX_TMP_MARKER" @@ -174,7 +187,7 @@ if [ "$PART_TYPE" = "OPENSLX_SYS" ]; then # TODO make the formatting of the system partition configurable if ! format_disk "${PART_DEV}" xfs; then # error while formatting, cleanup - warn "Error formatting $PART_DEV ... removing $$" + warn "($$) Error formatting $PART_DEV ... removing $$" sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" exit 1 fi @@ -182,12 +195,12 @@ if [ "$PART_TYPE" = "OPENSLX_SYS" ]; then # mount it now, since qemu-nbd needs it asap! if mount_sys_part "$PART_DEV"; then # mount worked, mark it as done - info "Using '$PART_DEV' as '$PART_TYPE'" + info "($$) Using '$PART_DEV' as '$PART_TYPE'" echo "$PART_DEV" > "$OPENSLX_SYS_MARKER" sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" exit 0 else - warn "'mount_sys_part' failed in $0" + warn "($$) 'mount_sys_part' failed in $0" sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" exit 1 fi |