From patchwork Wed May 8 09:52:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 139994 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8B07743FDC; Wed, 8 May 2024 11:52:21 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 53A8340A6E; Wed, 8 May 2024 11:52:21 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id C1C2E402AF for ; Wed, 8 May 2024 11:52:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715161939; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=W7GfasfR9qvQg3LdWOX4EnVLULGSXsrlft/TH1knyI4=; b=iAME6t58ldIv4MXKDjk4ku/6zC+Lq7j7DinX2WhXRh1leE/Le7180jK/dLiolBv5vYv4lN KHvTsPMgQPtpTp7LeaG5415TT9ogenUdTsiOu5jWwt9q/jmw2Pgit3wMkB9r4EqwNmTzKq ZWGCtfA5Wqk9aLkEWamcMIuLa6+UHs0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-599-dnbyhh3YOPmNxVBJZCSiLQ-1; Wed, 08 May 2024 05:52:17 -0400 X-MC-Unique: dnbyhh3YOPmNxVBJZCSiLQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7C43C8015D7; Wed, 8 May 2024 09:52:17 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBAA828E2; Wed, 8 May 2024 09:52:16 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Yu Jiang , Bruce Richardson Subject: [PATCH] eal/unix: support ZSTD compression for firmwares Date: Wed, 8 May 2024 11:52:14 +0200 Message-ID: <20240508095214.2541115-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Ubuntu 24.04 started to compress firmwares with ZSTD compression. Bugzilla ID: 1437 Signed-off-by: David Marchand --- lib/eal/unix/eal_firmware.c | 42 +++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/eal/unix/eal_firmware.c b/lib/eal/unix/eal_firmware.c index 1d47e879c8..065e251f9d 100644 --- a/lib/eal/unix/eal_firmware.c +++ b/lib/eal/unix/eal_firmware.c @@ -16,6 +16,21 @@ #include "eal_firmware.h" #include "eal_private.h" +#ifndef RTE_HAS_LIBARCHIVE +/* Fake definitions for the compression_algorithms array below. */ +struct archive; +extern int archive_read_support_filter_xz(struct archive *a); +extern int archive_read_support_filter_zstd(struct archive *a); +#endif + +static struct { + const char *suffix; + int (*support_callback)(struct archive *a); +} compression_algorithms[] = { + { "xz", archive_read_support_filter_xz, }, + { "zst", archive_read_support_filter_zstd, }, +}; + #ifdef RTE_HAS_LIBARCHIVE struct firmware_read_ctx { @@ -26,7 +41,7 @@ static int firmware_open(struct firmware_read_ctx *ctx, const char *name, size_t blocksize) { struct archive_entry *e; - int err; + unsigned int i; ctx->a = archive_read_new(); if (ctx->a == NULL) @@ -35,9 +50,12 @@ firmware_open(struct firmware_read_ctx *ctx, const char *name, size_t blocksize) if (archive_read_support_format_raw(ctx->a) != ARCHIVE_OK) goto error; - err = archive_read_support_filter_xz(ctx->a); - if (err != ARCHIVE_OK && err != ARCHIVE_WARN) - goto error; + for (i = 0; i < RTE_DIM(compression_algorithms); i++) { + int err = compression_algorithms[i].support_callback(ctx->a); + if (err != ARCHIVE_OK && err != ARCHIVE_WARN) + EAL_LOG(WARNING, "could not initialise libarchive for %s compression", + compression_algorithms[i].suffix); + } if (archive_read_open_filename(ctx->a, name, blocksize) != ARCHIVE_OK) goto error; @@ -148,16 +166,22 @@ rte_firmware_read(const char *name, void **buf, size_t *bufsz) ret = firmware_read(name, buf, bufsz); if (ret < 0) { - snprintf(path, sizeof(path), "%s.xz", name); - path[PATH_MAX - 1] = '\0'; + unsigned int i; + + for (i = 0; i < RTE_DIM(compression_algorithms); i++) { + snprintf(path, sizeof(path), "%s.%s", name, + compression_algorithms[i].suffix); + path[PATH_MAX - 1] = '\0'; + if (access(path, F_OK) != 0) + continue; #ifndef RTE_HAS_LIBARCHIVE - if (access(path, F_OK) == 0) { EAL_LOG(WARNING, "libarchive not linked, %s cannot be decompressed", path); - } #else - ret = firmware_read(path, buf, bufsz); + ret = firmware_read(path, buf, bufsz); #endif + break; + } } return ret; }