Skip to content

Commit

Permalink
Resize file backed images after writting cloud image with qemu-img
Browse files Browse the repository at this point in the history
Fixes #535
  • Loading branch information
mateuszkwiatkowski committed Nov 29, 2023
1 parent e45b81d commit 8a23858
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/vm-core
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ core::create(){
case "${_disk_dev}" in
zvol)
zfs::make_zvol "${VM_DS_ZFS_DATASET}/${_name}/${_disk}" "${_disk_size}" "0" "${_zfs_opts}"
[ $_num -eq 0 ] && [ ! -z "$_img" ] && core::write_img "/dev/zvol/${VM_DS_ZFS_DATASET}/${_name}/${_disk}" "${_img}"
[ $_num -eq 0 ] && [ ! -z "$_img" ] && core::write_img "/dev/zvol/${VM_DS_ZFS_DATASET}/${_name}/${_disk}" "${_img}" "${_disk_dev}" "${_disk_size}"
;;
sparse-zvol)
zfs::make_zvol "${VM_DS_ZFS_DATASET}/${_name}/${_disk}" "${_disk_size}" "1" "${_zfs_opts}"
[ $_num -eq 0 ] && [ ! -z "$_img" ] && core::write_img "/dev/zvol/${VM_DS_ZFS_DATASET}/${_name}/${_disk}" "${_img}"
[ $_num -eq 0 ] && [ ! -z "$_img" ] && core::write_img "/dev/zvol/${VM_DS_ZFS_DATASET}/${_name}/${_disk}" "${_img}" "${_disk_dev}" "${_disk_size}"
;;
custom)
;;
Expand All @@ -242,7 +242,7 @@ core::create(){

# make sure only owner can read the disk image
chmod 600 "${VM_DS_PATH}/${_name}/${_disk}"
[ $_num -eq 0 ] && [ ! -z "$_img" ] && core::write_img "${VM_DS_PATH}/${_name}/${_disk}" "${_img}"
[ $_num -eq 0 ] && [ ! -z "$_img" ] && core::write_img "${VM_DS_PATH}/${_name}/${_disk}" "${_img}" "file" "${_disk_size}"
;;
esac

Expand Down Expand Up @@ -336,6 +336,8 @@ core::write_img(){
shift $?
_disk_dev="${1}"
_img="$2"
_disk_type="$3"
_size="$4"
timeout=30
i=0

Expand All @@ -355,6 +357,14 @@ core::write_img(){
if [ $? -ne 0 ]; then
util::err "failed to write img file with qemu-img"
fi

# if disk type is file then we need to resize it
if [ "${_disk_type}" = "file" ]; then
qemu-img resize "${_disk_dev}" "${_size}"
if [ $? -ne 0 ]; then
util::err "failed to resize img file with qemu-img"
fi
fi
}

# 'vm add'
Expand Down

0 comments on commit 8a23858

Please sign in to comment.