From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id C3D515A0278 for ; Fri, 26 Apr 2024 04:01:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1714096870; bh=Ly8AvUwHgeeUFMejFbtXgUzLHSVJj2e6bBpRJdfSWiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pZbZ/z1hfUbZexAT1BKuIxVVvZI9uut+FK/MS1AAfnwo3sI/HnOqSlcQGb/Mk564s hfT+Q8we5FpWFuAdZ5rAWn+bKuImVJ4R8taee+mDl2hIobpQndjgFUfVf2FX5pfjsl Uauoy5vDQX7PL6tc/Z8D28wNHJw1GaiGSs47s7AQyO/xoySPG/mv5dmjpAfOMIV1v3 dxX6ia4vXmd8P+tOUMVE0EMaltNPiFV5O3UpVW4p00TVbGKp6zUrY4Pp5AvCnPeVo4 +jJKjOc/PXllD+hRQKP92ydlLG2hT0C+17bALGwV3ScKVaGWJJ5T05niHzvMuqlMpH WegldgrhO9Grg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4VQbYL6CGrz4x1H; Fri, 26 Apr 2024 12:01:10 +1000 (AEST) From: David Gibson To: Stefano Brivio Subject: [PATCH v2 3/4] Split "auto" compression mode into its own path Date: Fri, 26 Apr 2024 12:01:07 +1000 Message-ID: <20240426020108.1522375-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240426020108.1522375-1-david@gibson.dropbear.id.au> References: <20240426020108.1522375-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 7MOUI3DZZFS5ZOWOCU2BBPSK57GFCP25 X-Message-ID-Hash: 7MOUI3DZZFS5ZOWOCU2BBPSK57GFCP25 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, lvivier@redhat.com, David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: mbuto supports "auto" compression mode where we detect the fastest to decompress and use it. This is structured a bit oddly - cpio_compress() first handles the case of an explicitly selected compressor, then handles the auto-detected case, redundantly implementing the compression once it has picked one. Make this a bit clearer: first handle the "auto" case by calling out to the testing code, and using that to set the parameter for the specific compression path. Signed-off-by: David Gibson --- mbuto | 53 ++++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/mbuto b/mbuto index 49d032c..eb559fb 100755 --- a/mbuto +++ b/mbuto @@ -566,31 +566,11 @@ cpio_init() { fi } -# cpio_compress() - Compress archive, test available methods if none is selected +# compress_select() - Try compressors and pick the fastest to decompress image # $1: Existing CPIO archive -cpio_compress() { - { [ -z "${COMPRESS}" ] || [ "${COMPRESS}" = "none" ]; } && return - - info "Compressing CPIO archive ${1}" - - if [ "${COMPRESS}" != "auto" ]; then - [ "${COMPRESS}" = "lzo" ] && __cmd="lzop" || __cmd="${COMPRESS}" - - cmd_check "${__cmd}" - if [ "${__cmd}" = "lz4" ]; then - "${__cmd}" -l -f -q -9 "${1}" "${1}.lz4" - else - "${__cmd}" -f -q -9 -S .lz4 "${1}" - fi - - mv "${1}.lz4" "${1}" - - return - fi - +compress_select() { if [ ! -f "/boot/config-${KERNEL}" ]; then - "${GZIP}" -9 "${1}" - "${MV}" "${1}.gz" "${1}" + echo "gzip" return fi @@ -639,14 +619,29 @@ cpio_compress() { "${__a}:" "${__size} bytes" "${__time}s" done - [ "${__pick}" = "lzo" ] && __cmd="lzop" || __cmd="${__pick}" - [ "${__cmd}" = "lz4" ] && __opt="-l" || __opt="" - - "${__cmd}" ${__opt} -q -9 -c "${1}" > "${compress_test1}" notice "Picked ${__pick} compression for CPIO" + rm ${compress_test1} ${compress_test2} + echo "${__pick}" +} + +# cpio_compress() - Compress archive, test available methods if none is selected +# $1: Existing CPIO archive +cpio_compress() { + { [ -z "${COMPRESS}" ] || [ "${COMPRESS}" = "none" ]; } && return + [ "${COMPRESS}" = "auto" ] && COMPRESS=$(compress_select "$1") + + info "Compressing CPIO archive ${1}" + + [ "${COMPRESS}" = "lzo" ] && __cmd="lzop" || __cmd="${COMPRESS}" + + cmd_check "${__cmd}" + if [ "${__cmd}" = "lz4" ]; then + "${__cmd}" -l -f -q -9 "${1}" "${1}.lz4" + else + "${__cmd}" -f -q -9 -S .lz4 "${1}" + fi - mv "${compress_test1}" "${OUT}" - rm "${compress_test2}" + mv "${1}.lz4" "${1}" } ################################################################################ -- 2.44.0