Blame osbuilder-0002-image-builder-Add-NSDAX_BIN-for-passing-in-compiled-.patch

591da57
From 4004bd8fbe4cef00be62d35697e9ef28edda4df7 Mon Sep 17 00:00:00 2001
591da57
From: Cole Robinson <crobinso@redhat.com>
591da57
Date: Thu, 5 Mar 2020 12:21:16 -0500
591da57
Subject: [PATCH] image-builder: Add NSDAX_BIN for passing in compiled nsdax
591da57
 tool
591da57
591da57
In Fedora we are running the osbuilder scripts on the client machine,
591da57
to generate an initrd for the running host kernel. In this setup,
591da57
there's currently a runtime dependency on gcc for compiling the nsdax
591da57
tool, which is suboptimal.
591da57
591da57
Add NSDAX_BIN environment variable; if specified, image-builder.sh
591da57
will use that path as the nsdax tool. This let's ship a compiled
591da57
nsdax tool to users and drop the runtime gcc dependency
591da57
591da57
Fixes: #417
591da57
591da57
Signed-off-by: Cole Robinson <crobinso@redhat.com>
591da57
---
591da57
 image-builder/image_builder.sh | 25 +++++++++++++++++++------
591da57
 1 file changed, 19 insertions(+), 6 deletions(-)
591da57
591da57
diff --git a/image-builder/image_builder.sh b/image-builder/image_builder.sh
591da57
index 06cc711..e18822d 100755
591da57
--- a/image-builder/image_builder.sh
591da57
+++ b/image-builder/image_builder.sh
591da57
@@ -88,6 +88,7 @@ Options:
591da57
 Extra environment variables:
591da57
 	AGENT_BIN:  Use it to change the expected agent binary name
591da57
 	AGENT_INIT: Use kata agent as init process
591da57
+	NSDAX_BIN:  Use to specify path to pre-compiled 'nsdax' tool.
591da57
 	FS_TYPE:    Filesystem type to use. Only xfs and ext4 are supported.
591da57
 	USE_DOCKER: If set will build image in a Docker Container (requries docker)
591da57
 		    DEFAULT: not set
591da57
@@ -130,6 +131,8 @@ build_with_container() {
591da57
 	local root_free_space="$5"
591da57
 	local agent_bin="$6"
591da57
 	local agent_init="$7"
591da57
+	local container_engine="$8"
591da57
+	local nsdax_bin="$9"
591da57
 	local container_image_name="image-builder-osbuilder"
591da57
 	local shared_files=""
591da57
 
591da57
@@ -158,6 +161,7 @@ build_with_container() {
591da57
 		   --env FS_TYPE="${fs_type}" \
591da57
 		   --env BLOCK_SIZE="${block_size}" \
591da57
 		   --env ROOT_FREE_SPACE="${root_free_space}" \
591da57
+		   --env NSDAX_BIN="${nsdax_bin}" \
591da57
 		   --env DEBUG="${DEBUG}" \
591da57
 		   -v /dev:/dev \
591da57
 		   -v "${script_dir}":"/osbuilder" \
591da57
@@ -411,6 +415,7 @@ set_dax_header() {
591da57
 	local image="$1"
591da57
 	local img_size="$2"
591da57
 	local fs_type="$3"
591da57
+	local nsdax_bin="$4"
591da57
 
591da57
 	# rootfs start + DAX header size
591da57
 	local rootfs_offset=$((rootfs_start + dax_header_sz))
591da57
@@ -425,9 +430,12 @@ set_dax_header() {
591da57
 	info "Set DAX metadata"
591da57
 	# Set metadata header
591da57
 	# Issue: https://github.com/kata-containers/osbuilder/issues/240
591da57
-	gcc -O2 "${script_dir}/nsdax.gpl.c" -o "${script_dir}/nsdax"
591da57
-	"${script_dir}/nsdax" "${header_image}" "${dax_header_bytes}" "${dax_alignment_bytes}"
591da57
-	rm -f "${script_dir}/nsdax"
591da57
+	if [ -z "${nsdax_bin}" ] ; then
591da57
+		nsdax_bin="${script_dir}/nsdax"
591da57
+		gcc -O2 "${script_dir}/nsdax.gpl.c" -o "${nsdax_bin}"
591da57
+		trap "rm ${nsdax_bin}" EXIT
591da57
+	fi
591da57
+	"${nsdax_bin}" "${header_image}" "${dax_header_bytes}" "${dax_alignment_bytes}"
591da57
 	sync
591da57
 
591da57
 	touch "${dax_image}"
591da57
@@ -452,6 +460,7 @@ main() {
591da57
 	local image="${IMAGE:-kata-containers.img}"
591da57
 	local block_size="${BLOCK_SIZE:-4096}"
591da57
 	local root_free_space="${ROOT_FREE_SPACE:-}"
591da57
+	local nsdax_bin="${NSDAX_BIN:-}"
591da57
 
591da57
 	while getopts "ho:r:f:" opt
591da57
 	do
591da57
@@ -471,6 +480,7 @@ main() {
591da57
 		exit 0
591da57
 	fi
591da57
 
591da57
+	local container_engine
591da57
 	if [ -n "${USE_DOCKER}" ]; then
591da57
 		container_engine="docker"
591da57
 	elif [ -n "${USE_PODMAN}" ]; then
591da57
@@ -478,8 +488,11 @@ main() {
591da57
 	fi
591da57
 
591da57
 	if [ -n "$container_engine" ]; then
591da57
-		build_with_container "${rootfs}" "${image}" "${fs_type}" "${block_size}" \
591da57
-						  "${root_free_space}" "${agent_bin}" "${agent_init}" "${container_engine}"
591da57
+		build_with_container "${rootfs}" \
591da57
+			"${image}" "${fs_type}" "${block_size}" \
591da57
+			"${root_free_space}" "${agent_bin}" \
591da57
+			"${agent_init}" "${container_engine}" \
591da57
+			"${nsdax_bin}"
591da57
 		exit $?
591da57
 	fi
591da57
 
591da57
@@ -496,7 +509,7 @@ main() {
591da57
 						"${fs_type}" "${block_size}"
591da57
 
591da57
 	# insert at the beginning of the image the MBR + DAX header
591da57
-	set_dax_header "${image}" "${img_size}" "${fs_type}"
591da57
+	set_dax_header "${image}" "${img_size}" "${fs_type}" "${nsdax_bin}"
591da57
 }
591da57
 
591da57
 main "$@"