mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-06-08 17:37:58 +08:00
fix: Error codes
This commit is contained in:
parent
c335078aac
commit
7e12585429
28
src/disk.sh
28
src/disk.sh
@ -34,7 +34,7 @@ fmt2ext() {
|
|||||||
echo "img"
|
echo "img"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "Unrecognized disk format: $DISK_FMT" && exit 88
|
error "Unrecognized disk format: $DISK_FMT" && exit 78
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ ext2fmt() {
|
|||||||
echo "raw"
|
echo "raw"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "Unrecognized file extension: .$DISK_EXT" && exit 88
|
error "Unrecognized file extension: .$DISK_EXT" && exit 78
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ getSize() {
|
|||||||
qemu-img info "$DISK_FILE" -f "$DISK_FMT" | grep '^virtual size: ' | sed 's/.*(\(.*\) bytes)/\1/'
|
qemu-img info "$DISK_FILE" -f "$DISK_FMT" | grep '^virtual size: ' | sed 's/.*(\(.*\) bytes)/\1/'
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "Unrecognized disk format: $DISK_FMT" && exit 88
|
error "Unrecognized disk format: $DISK_FMT" && exit 78
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ resizeDisk() {
|
|||||||
FAIL="Could not resize $DISK_FMT file of $DISK_DESC ($DISK_FILE) from ${GB}G to $DISK_SPACE .."
|
FAIL="Could not resize $DISK_FMT file of $DISK_DESC ($DISK_FILE) from ${GB}G to $DISK_SPACE .."
|
||||||
|
|
||||||
REQ=$((DATA_SIZE-CUR_SIZE))
|
REQ=$((DATA_SIZE-CUR_SIZE))
|
||||||
(( REQ < 1 )) && error "Shrinking disks is not supported!" && exit 84
|
(( REQ < 1 )) && error "Shrinking disks is not supported!" && exit 71
|
||||||
|
|
||||||
case "${DISK_FMT,,}" in
|
case "${DISK_FMT,,}" in
|
||||||
raw)
|
raw)
|
||||||
@ -97,7 +97,7 @@ resizeDisk() {
|
|||||||
|
|
||||||
# Resize file by changing its length
|
# Resize file by changing its length
|
||||||
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
||||||
error "$FAIL" && exit 85
|
error "$FAIL" && exit 75
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -108,13 +108,13 @@ resizeDisk() {
|
|||||||
|
|
||||||
if (( REQ > SPACE )); then
|
if (( REQ > SPACE )); then
|
||||||
error "Not enough free space to resize $DISK_DESC to $DISK_SPACE in $DIR, it has only $SPACE_GB GB available.."
|
error "Not enough free space to resize $DISK_DESC to $DISK_SPACE in $DIR, it has only $SPACE_GB GB available.."
|
||||||
error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting DISK_FMT to \"qcow2\"." && exit 84
|
error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting DISK_FMT to \"qcow2\"." && exit 74
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Resize file by allocating more space
|
# Resize file by allocating more space
|
||||||
if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then
|
if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then
|
||||||
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
||||||
error "$FAIL" && exit 85
|
error "$FAIL" && exit 75
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ resizeDisk() {
|
|||||||
;;
|
;;
|
||||||
qcow2)
|
qcow2)
|
||||||
if ! qemu-img resize -f "$DISK_FMT" "$DISK_FILE" "$DISK_SPACE" ; then
|
if ! qemu-img resize -f "$DISK_FMT" "$DISK_FILE" "$DISK_SPACE" ; then
|
||||||
error "$FAIL" && exit 85
|
error "$FAIL" && exit 72
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -161,7 +161,7 @@ createDisk() {
|
|||||||
# Create an empty file
|
# Create an empty file
|
||||||
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
||||||
rm -f "$DISK_FILE"
|
rm -f "$DISK_FILE"
|
||||||
error "$FAIL" && exit 87
|
error "$FAIL" && exit 77
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -172,14 +172,14 @@ createDisk() {
|
|||||||
|
|
||||||
if (( DATA_SIZE > SPACE )); then
|
if (( DATA_SIZE > SPACE )); then
|
||||||
error "Not enough free space to create a $DISK_DESC of $DISK_SPACE in $DIR, it has only $SPACE_GB GB available.."
|
error "Not enough free space to create a $DISK_DESC of $DISK_SPACE in $DIR, it has only $SPACE_GB GB available.."
|
||||||
error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting DISK_FMT to \"qcow2\"." && exit 86
|
error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting DISK_FMT to \"qcow2\"." && exit 76
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create an empty file
|
# Create an empty file
|
||||||
if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then
|
if ! fallocate -l "$DISK_SPACE" "$DISK_FILE"; then
|
||||||
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
if ! truncate -s "$DISK_SPACE" "$DISK_FILE"; then
|
||||||
rm -f "$DISK_FILE"
|
rm -f "$DISK_FILE"
|
||||||
error "$FAIL" && exit 87
|
error "$FAIL" && exit 77
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ createDisk() {
|
|||||||
qcow2)
|
qcow2)
|
||||||
if ! qemu-img create -f "$DISK_FMT" -- "$DISK_FILE" "$DISK_SPACE" ; then
|
if ! qemu-img create -f "$DISK_FMT" -- "$DISK_FILE" "$DISK_SPACE" ; then
|
||||||
rm -f "$DISK_FILE"
|
rm -f "$DISK_FILE"
|
||||||
error "$FAIL" && exit 89
|
error "$FAIL" && exit 70
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -219,7 +219,7 @@ addDisk () {
|
|||||||
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
||||||
|
|
||||||
if (( DATA_SIZE < 6442450944 )); then
|
if (( DATA_SIZE < 6442450944 )); then
|
||||||
error "Please increase ${DISK_DESC^^}_SIZE to at least 6 GB." && exit 83
|
error "Please increase ${DISK_DESC^^}_SIZE to at least 6 GB." && exit 73
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -f "$DISK_FILE" ] ; then
|
if ! [ -f "$DISK_FILE" ] ; then
|
||||||
@ -243,7 +243,7 @@ addDisk () {
|
|||||||
|
|
||||||
if ! convertDisk "$PREV_FILE" "$PREV_FMT" "$TMP_FILE" "$DISK_FMT" ; then
|
if ! convertDisk "$PREV_FILE" "$PREV_FMT" "$TMP_FILE" "$DISK_FMT" ; then
|
||||||
rm -f "$TMP_FILE"
|
rm -f "$TMP_FILE"
|
||||||
error "Failed to convert $DISK_DESC to $DISK_FMT format." && exit 89
|
error "Failed to convert $DISK_DESC to $DISK_FMT format." && exit 79
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mv "$TMP_FILE" "$DISK_FILE"
|
mv "$TMP_FILE" "$DISK_FILE"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user