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 ABCD35A026F for ; Fri, 22 Mar 2024 03:27:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1711074461; bh=/lRP4wDUkQe8+UoyQTjOkzRCHeXKfCp97+V1ze2Do/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lu/UAnaDD7JfyyJe0ACwiDG30LLiXRTcRUHGd52brzfRsp9z2dDM9QG1Vl4Iv7MR5 0tpy1YyyyzE+hI+aAx7HTrhmMaE/9+KeSfvSYJzogk7q3tgyXoV8qbL/qy0kHHOYWx f1Lbgp6VJkoOrUbwC65Fwob8qKAtKL8IU/s0ZxUTIrNjbj8h/XFL7FN6jAB1X3VZqD G6Pm52FXhPBDtTDl13XpQYNFNwEmLJax649vwBvhKh2T4MuW0ZvumMhU6xFjWVdFMw +zznZAozh1FM7vHc4/5SS48ahW2GRV87oFwhCGd8byroMx5BNVjg2aN2nW7zQMlMeM 6gD/fRSN8BBNA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4V15p53YgKz4wxv; Fri, 22 Mar 2024 13:27:41 +1100 (AEDT) From: David Gibson To: Stefano Brivio Subject: [PATCH 3/4] Split "auto" compression mode into its own path Date: Fri, 22 Mar 2024 13:27:38 +1100 Message-ID: <20240322022739.2746102-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322022739.2746102-1-david@gibson.dropbear.id.au> References: <20240322022739.2746102-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: W4IWHIZ2AZX2APHYKZ5SGNIDZJCVOSD4 X-Message-ID-Hash: W4IWHIZ2AZX2APHYKZ5SGNIDZJCVOSD4 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: lvivier@redhat.com, passt-dev@passt.top, 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 compressor 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 actually 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..550f76e 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 # $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