Skip to content

Commit e71ea3c

Browse files
authored
fs_lvm[_ssh]/mkimage: move FS check to top (#3635)
Also, prevent dd "No space left on device" messages (normal as copying from an infinite stream of zeroes) from appearing in logs
1 parent 4468a4f commit e71ea3c

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/tm_mad/fs_lvm/mkimage

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ LV_NAME="lv-one-$VM_ID-$DISK_ID"
7878
VG_NAME="vg-one-$DS_SYS_ID"
7979
DEV="/dev/${VG_NAME}/${LV_NAME}"
8080

81+
if [ -n "$FS" ] && ! contains "${SUPPORTED_FS}" "${FS}" ","; then
82+
log_error "Unsupported file system type: ${FS}. Supported types are: ${SUPPORTED_FS}"
83+
exit 1
84+
fi
85+
8186
# Execute lvcreate with a lock in the frontend
8287
CREATE_CMD=$(cat <<EOF
8388
set -e -o pipefail
@@ -92,9 +97,6 @@ exclusive "${LOCK}" 120 ssh_exec_and_log "$DST_HOST" "$CREATE_CMD" \
9297
"Error creating LV named $LV_NAME"
9398

9499
MKIMAGE_CMD=$(cat <<EOF
95-
# prints function content
96-
$(type contains| grep -v 'is a function')
97-
98100
set -e -o pipefail
99101
export PATH=/usr/sbin:/sbin:\$PATH
100102
@@ -104,19 +106,12 @@ MKIMAGE_CMD=$(cat <<EOF
104106
105107
# zero the volume
106108
if [ "${ZERO_LVM_ON_CREATE}" = "yes" ]; then
107-
${DD} if=/dev/zero of="${DEV}" bs=${DD_BLOCK_SIZE:-64k} || :
109+
${DD} if=/dev/zero of="${DEV}" bs=${DD_BLOCK_SIZE:-64k} 2> /dev/null || :
108110
fi
109111
110112
[ "$FORMAT" = "swap" ] && mkswap ${DEV}
111113
112-
if [ ! -z "$FS" ]; then
113-
contains "${SUPPORTED_FS}" "${FS}" ","
114-
115-
if [ $? != 0 ]; then
116-
log_error "Unsupported file system type: ${FS}. Supported types are: ${SUPPORTED_FS}"
117-
exit -1
118-
fi
119-
114+
if [ -n "$FS" ]; then
120115
FS_OPTS=$(eval $(echo "echo \$FS_OPTS_$FS"))
121116
$MKFS -t ${FS} ${FS_OPTS} ${DEV}
122117
fi
@@ -128,4 +123,5 @@ EOF
128123

129124
ssh_exec_and_log "$DST_HOST" "$MKIMAGE_CMD" \
130125
"Could not create image $DST_PATH"
126+
131127
exit 0

0 commit comments

Comments
 (0)