From 2d79e9d39529aa6cef46fe0779ee5a8a29cb9b16 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Wed, 25 Mar 2015 21:34:13 +0000 Subject: [PATCH] Short circuit qemu-img convert for raw images We currently use qemu-img convert with a raw source and dest when building raw images. We can just mv the file for increased speed. Change-Id: I3da095cb9ecad7224a121a434a9fb204132bf6df --- bin/disk-image-create | 16 +++++++++++++--- lib/img-functions | 8 ++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bin/disk-image-create b/bin/disk-image-create index db218b86..61337051 100755 --- a/bin/disk-image-create +++ b/bin/disk-image-create @@ -45,7 +45,7 @@ function show_options () { echo "Options:" echo " -a i386|amd64|armhf -- set the architecture of the image(default amd64)" echo " -o imagename -- set the imagename of the output image file(default image)" - echo " -t qcow2,tar -- set the image types of the output image files (default qcow2)" + echo " -t qcow2,tar,raw -- set the image types of the output image files (default qcow2)" echo " File types should be comma separated" echo " -x -- turn on tracing" echo " -u -- uncompressed; do not compress the image - larger but faster" @@ -247,14 +247,24 @@ done unmount_image +has_raw_type= if [ "$IS_RAMDISK" == "0" ]; then for IMAGE_TYPE in ${IMAGE_TYPES[@]} ; do - compress_and_save_image $IMAGE_NAME.$IMAGE_TYPE + # We have to do raw last because it is destructive + if [ "$IMAGE_NAME" = "raw" ]; then + has_raw_type=1 + else + compress_and_save_image $IMAGE_NAME.$IMAGE_TYPE + fi done fi +if [ -n "$has_raw_type" ]; then + IMAGE_TYPE="raw" + compress_and_save_image $IMAGE_NAME.$IMAGE_TYPE +fi # Always cleanup after ourselves -rm $TMP_IMAGE_PATH +rm -f $TMP_IMAGE_PATH cleanup_dirs case "$IMAGE_ELEMENT" in diff --git a/lib/img-functions b/lib/img-functions index 35a820d1..6e94423b 100644 --- a/lib/img-functions +++ b/lib/img-functions @@ -115,8 +115,12 @@ function compress_and_save_image () { else EXTRA_OPTIONS="" fi - echo "Converting image using qemu-img convert" - qemu-img convert ${COMPRESS_IMAGE:+-c} -f raw $TMP_IMAGE_PATH -O $IMAGE_TYPE $EXTRA_OPTIONS $1-new + if [ "$IMAGE_TYPE" = "raw" ]; then + mv $TMP_IMAGE_PATH $1-new + else + echo "Converting image using qemu-img convert" + qemu-img convert ${COMPRESS_IMAGE:+-c} -f raw $TMP_IMAGE_PATH -O $IMAGE_TYPE $EXTRA_OPTIONS $1-new + fi OUT_IMAGE_PATH=$1-new finish_image $1