Skip to content

Commit 6a38a5f

Browse files
authored
Merge pull request #3157 from flatcar/t-lo/containerd-overlaybd
Add overlaybd sysext
2 parents 7e1612c + d15a7db commit 6a38a5f

File tree

13 files changed

+475
-0
lines changed

13 files changed

+475
-0
lines changed

build_library/extra_sysexts.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
EXTRA_SYSEXTS=(
2+
"overlaybd|sys-fs/overlaybd,app-containers/accelerated-container-image"
23
"incus|app-containers/incus"
34
"nvidia-drivers-535|x11-drivers/nvidia-drivers:0/535|-kernel-open persistenced|amd64"
45
"nvidia-drivers-535-open|x11-drivers/nvidia-drivers:0/535|kernel-open persistenced|amd64"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* Added [overlaybd](https://containerd.github.io/overlaybd/) system extension to support accelerated container images.
2+
The extension includes both [overlaybd](https://github.com/containerd/overlaybd/) as well as [accelerated-container-image](https://github.com/containerd/accelerated-container-image) tools.
3+
Add `overlaybd` to [`/etc/flatcar/enabled-sysext.conf`](https://www.flatcar.org/docs/latest/provisioning/sysext/) to check it out.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
accelerated-container-image-9999.ebuild
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2025 The Flatcar Container Linux Maintainers
2+
# Distributed under the terms of the Apache License 2.0
3+
4+
EAPI=8
5+
6+
inherit git-r3 go-module systemd tmpfiles
7+
8+
DESCRIPTION="Remote container image format (overlaybd) and snapshotter based on block-device"
9+
HOMEPAGE="https://github.com/containerd/accelerated-container-image"
10+
EGIT_REPO_URI="https://github.com/containerd/accelerated-container-image.git"
11+
12+
if [[ ${PV} == 9999* ]]; then
13+
KEYWORDS="~amd64 ~arm64"
14+
else
15+
EGIT_COMMIT="v${PV}"
16+
KEYWORDS="amd64 arm64"
17+
fi
18+
19+
LICENSE="Apache-2.0"
20+
SLOT="0"
21+
22+
# FIXME HACK ALERT: the build pulls go modules during src_compile.
23+
# This fails if network sandbox is enabled.
24+
RESTRICT="${RESTRICT} network-sandbox"
25+
26+
27+
RDEPEND="sys-fs/overlaybd"
28+
29+
src_unpack() {
30+
git-r3_src_unpack
31+
go-module_src_unpack
32+
}
33+
34+
src_install() {
35+
emake install \
36+
DESTDIR="${ED}" \
37+
SN_DESTDIR="${ED}/usr/local/overlaybd/snapshotter" \
38+
SN_CFGDIR="${ED}/usr/local/overlaybd/snapshotter/etc"
39+
40+
sed -i 's,/opt/overlaybd,/usr/local/overlaybd,' \
41+
"${ED}/usr/local/overlaybd/snapshotter/overlaybd-snapshotter.service" || die
42+
43+
# tmpfiles will take care of symlinking /usr/local/overlaybd/snapshotter
44+
# to /opt/overlaybd/snapshotter, where upstream expects the binaries.
45+
# (we need them in /usr to be used in a sysext)
46+
dotmpfiles "${FILESDIR}/10-overlaybd-snapshotter.conf"
47+
48+
systemd_dounit "${ED}/usr/local/overlaybd/snapshotter/overlaybd-snapshotter.service"
49+
systemd_enable_service "multi-user.target" "overlaybd-snapshotter.service"
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
C /etc/overlaybd-snapshotter/config.json - - - - /usr/local/overlaybd/snapshotter/etc/config.json
2+
L /opt/overlaybd/snapshotter - - - - /usr/local/overlaybd/snapshotter
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
3+
<pkgmetadata>
4+
<maintainer type="project">
5+
<email>[email protected]</email>
6+
<name>The Flatcar Container Linux Maintainers</name>
7+
</maintainer>
8+
<upstream>
9+
<remote-id type="github">containerd/accelerated-container-image</remote-id>
10+
</upstream>
11+
</pkgmetadata>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
C /etc/overlaybd/overlaybd.json - - - - /usr/local/overlaybd/etc/overlaybd.json
2+
d /opt/overlaybd - - - - -
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
From de68119855229db8e457043d86bbb38bbd5d55d9 Mon Sep 17 00:00:00 2001
2+
From: James Le Cuirot <[email protected]>
3+
Date: Fri, 25 Jul 2025 17:12:03 +0100
4+
Subject: [PATCH 1/3] Fix cross-compiling by using CMAKE_SYSTEM_PROCESSOR
5+
rather than uname -m
6+
7+
There is no need to check the architecture twice. Also check for arm64
8+
(MacOS) wherever we check for aarch64 (Linux).
9+
10+
Signed-off-by: James Le Cuirot <[email protected]>
11+
--- a/CMakeLists.txt
12+
+++ b/CMakeLists.txt
13+
@@ -9,10 +9,8 @@ enable_language(C)
14+
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
15+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -DNDEBUG -g")
16+
17+
-# Get CPU arch
18+
-execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
19+
-if (NOT (${ARCH} STREQUAL x86_64) AND NOT (${ARCH} STREQUAL aarch64) AND NOT (${ARCH} STREQUAL arm64))
20+
- message(FATAL_ERROR "Unknown CPU architecture ${ARCH}")
21+
+if (NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64) AND NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) AND NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL arm64))
22+
+ message(FATAL_ERROR "Unknown CPU architecture ${CMAKE_SYSTEM_PROCESSOR}")
23+
endif ()
24+
25+
option(OBD_VER "Overlaybd version" "overlaybd/0.0.0-undefined")
26+
@@ -25,7 +23,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
27+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic -Wall -Werror=sign-compare")
28+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpic -Wall -Werror=sign-compare -DOVERLAYBD_VER=${OBD_VER}")
29+
30+
-if (${ARCH} STREQUAL aarch64)
31+
+if ((CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) OR (CMAKE_SYSTEM_PROCESSOR STREQUAL arm64))
32+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crc -fsigned-char -fno-stack-protector -fomit-frame-pointer")
33+
endif ()
34+
35+
--- a/src/overlaybd/zfile/CMakeLists.txt
36+
+++ b/src/overlaybd/zfile/CMakeLists.txt
37+
@@ -2,19 +2,13 @@ file(GLOB SOURCE_ZFILE "*.cpp")
38+
file(GLOB SOURCE_LZ4 "lz4/*.c")
39+
file(GLOB SOURCE_CRC32 "crc32/crc32c.cpp")
40+
41+
-# Get CPU arch
42+
-execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
43+
-if (NOT (${ARCH} STREQUAL x86_64) AND NOT (${ARCH} STREQUAL aarch64))
44+
- message(FATAL_ERROR "Unknown CPU architecture ${ARCH}")
45+
-endif ()
46+
-
47+
set (CMAKE_CXX_STANDARD 17)
48+
add_library(crc32_lib STATIC ${SOURCE_CRC32})
49+
target_include_directories(crc32_lib PUBLIC
50+
${PHOTON_INCLUDE_DIR}
51+
)
52+
53+
-if (${ARCH} STREQUAL x86_64)
54+
+if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
55+
target_compile_options(crc32_lib PUBLIC -msse4.2 -mcrc32)
56+
else()
57+
target_compile_options(crc32_lib PRIVATE -march=native -mcpu=generic+crc)
58+
--
59+
2.49.0
60+
61+
62+
From ee0e074c256ea1bcbcff2ed5a3e311becaf122cc Mon Sep 17 00:00:00 2001
63+
From: James Le Cuirot <[email protected]>
64+
Date: Mon, 28 Jul 2025 12:05:19 +0100
65+
Subject: [PATCH 2/3] Respect aarch64 -march=|-mcpu= flag and check whether
66+
-mcpu=native works
67+
68+
Packagers may specify a target system up front, which should be
69+
respected. The CRC extensions are not strictly necessary as there is a
70+
software fallback.
71+
72+
Otherwise, use -mcpu=native if it works (it won't when cross-compiling)
73+
or -mcpu=generic+crc.
74+
75+
Signed-off-by: James Le Cuirot <[email protected]>
76+
--- a/CMakeLists.txt
77+
+++ b/CMakeLists.txt
78+
@@ -24,7 +24,16 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic -Wall -Werror=sign-compare")
79+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpic -Wall -Werror=sign-compare -DOVERLAYBD_VER=${OBD_VER}")
80+
81+
if ((CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) OR (CMAKE_SYSTEM_PROCESSOR STREQUAL arm64))
82+
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crc -fsigned-char -fno-stack-protector -fomit-frame-pointer")
83+
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char -fno-stack-protector -fomit-frame-pointer")
84+
+ if (NOT CMAKE_CXX_FLAGS MATCHES "-march=|-mcpu=")
85+
+ include(CheckCXXCompilerFlag)
86+
+ check_cxx_compiler_flag(-mcpu=native COMPILER_HAS_NATIVE_FLAG)
87+
+ if (COMPILER_HAS_NATIVE_FLAG)
88+
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=native")
89+
+ else ()
90+
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=generic+crc")
91+
+ endif ()
92+
+ endif ()
93+
endif ()
94+
95+
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc ${CMAKE_CXX_STANDARD_LIBRARIES}")
96+
--- a/src/overlaybd/zfile/CMakeLists.txt
97+
+++ b/src/overlaybd/zfile/CMakeLists.txt
98+
@@ -10,8 +10,6 @@ target_include_directories(crc32_lib PUBLIC
99+
100+
if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
101+
target_compile_options(crc32_lib PUBLIC -msse4.2 -mcrc32)
102+
-else()
103+
- target_compile_options(crc32_lib PRIVATE -march=native -mcpu=generic+crc)
104+
endif()
105+
106+
if(ENABLE_DSA OR ENABLE_ISAL)
107+
--
108+
2.49.0
109+
110+
111+
From 2e4edd416a42fad0e8d7ac21855a4e81f34f1e82 Mon Sep 17 00:00:00 2001
112+
From: James Le Cuirot <[email protected]>
113+
Date: Mon, 28 Jul 2025 12:16:50 +0100
114+
Subject: [PATCH 3/3] Patch Photon after fetching to fix cross issues
115+
116+
Signed-off-by: James Le Cuirot <[email protected]>
117+
--- a/CMake/Findphoton.cmake
118+
+++ b/CMake/Findphoton.cmake
119+
@@ -6,6 +6,7 @@ FetchContent_Declare(
120+
photon
121+
GIT_REPOSITORY https://github.com/alibaba/PhotonLibOS.git
122+
GIT_TAG v0.6.17
123+
+ PATCH_COMMAND patch -p1 -i @FILESDIR@/photon-cross.patch
124+
)
125+
126+
if(BUILD_TESTING)
127+
--
128+
2.49.0
129+
130+
131+
From 32a592ef523a14600ce658a695d827724aeb66c9 Mon Sep 17 00:00:00 2001
132+
From: Krzesimir Nowak <[email protected]>
133+
Date: Fri, 8 Aug 2025 16:47:58 +0200
134+
Subject: [PATCH] Patch libtcmu after fetching to fix memory issues
135+
136+
---
137+
CMake/Findtcmu.cmake | 1 +
138+
1 file changed, 1 insertion(+)
139+
140+
diff --git a/CMake/Findtcmu.cmake b/CMake/Findtcmu.cmake
141+
index 6e8f0ef..5865a9b 100644
142+
--- a/CMake/Findtcmu.cmake
143+
+++ b/CMake/Findtcmu.cmake
144+
@@ -5,6 +5,7 @@ FetchContent_Declare(
145+
tcmu
146+
GIT_REPOSITORY https://github.com/data-accelerator/photon-libtcmu.git
147+
GIT_TAG main
148+
+ PATCH_COMMAND patch -p1 -i @FILESDIR@/tcmu-fix.patch
149+
)
150+
151+
if(BUILD_TESTING)
152+
--
153+
2.49.1
154+
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
From a0ea7bb44f4c863519537605e8118b6ff6afd57e Mon Sep 17 00:00:00 2001
2+
From: James Le Cuirot <[email protected]>
3+
Date: Mon, 28 Jul 2025 10:23:02 +0100
4+
Subject: [PATCH 1/2] Fix cross-compiling by using CMAKE_SYSTEM_PROCESSOR
5+
rather than uname -m
6+
7+
There is no need to check the architecture twice. Also check for arm64
8+
(MacOS) wherever we check for aarch64 (Linux).
9+
10+
Signed-off-by: James Le Cuirot <[email protected]>
11+
--- a/CMakeLists.txt
12+
+++ b/CMakeLists.txt
13+
@@ -38,10 +38,8 @@ set(PHOTON_E2FS_SOURCE "" CACHE STRING "")
14+
set(PHOTON_GFLAGS_SOURCE "https://github.com/gflags/gflags/archive/refs/tags/v2.2.2.tar.gz" CACHE STRING "")
15+
set(PHOTON_GOOGLETEST_SOURCE "https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz" CACHE STRING "")
16+
17+
-# Get CPU arch and number
18+
-execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
19+
-if (NOT (${ARCH} STREQUAL x86_64) AND NOT (${ARCH} STREQUAL aarch64) AND NOT (${ARCH} STREQUAL arm64))
20+
- message(FATAL_ERROR "Unknown CPU architecture ${ARCH}")
21+
+if (NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64) AND NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) AND NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL arm64))
22+
+ message(FATAL_ERROR "Unknown CPU architecture ${CMAKE_SYSTEM_PROCESSOR}")
23+
endif ()
24+
ProcessorCount(NumCPU)
25+
26+
@@ -65,9 +63,9 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
27+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-packed-bitfield-compat")
28+
endif()
29+
30+
-if (${ARCH} STREQUAL x86_64)
31+
+if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
32+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
33+
-elseif (${ARCH} STREQUAL aarch64)
34+
+elseif ((CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) OR (CMAKE_SYSTEM_PROCESSOR STREQUAL arm64))
35+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=generic+crc -fsigned-char -fno-stack-protector -fomit-frame-pointer")
36+
endif ()
37+
38+
--- a/net/security-context/test/CMakeLists.txt
39+
+++ b/net/security-context/test/CMakeLists.txt
40+
@@ -6,9 +6,8 @@ add_executable(test-tls test.cpp)
41+
target_link_libraries(test-tls PRIVATE photon_shared ${testing_libs})
42+
add_test(NAME test-tls COMMAND $<TARGET_FILE:test-tls>)
43+
44+
-if (ENABLE_SASL AND (NOT (APPLE AND (${ARCH} STREQUAL arm64))))
45+
+if (ENABLE_SASL AND NOT (APPLE AND (CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)))
46+
add_executable(test-sasl test-sasl.cpp)
47+
target_link_libraries(test-sasl PRIVATE photon_shared ${testing_libs})
48+
add_test(NAME test-sasl COMMAND $<TARGET_FILE:test-sasl>)
49+
endif ()
50+
-
51+
--
52+
2.49.0
53+
54+
55+
From 467ecb887c8cc9107e8f055c90f02ee04fcb895e Mon Sep 17 00:00:00 2001
56+
From: James Le Cuirot <[email protected]>
57+
Date: Mon, 28 Jul 2025 11:17:24 +0100
58+
Subject: [PATCH 2/2] Respect aarch64 -march=|-mcpu= flag and check whether
59+
-mcpu=native works
60+
61+
Packagers may specify a target system up front, which should be
62+
respected. The CRC extensions are not strictly necessary as there is a
63+
software fallback.
64+
65+
Otherwise, use -mcpu=native if it works (it won't when cross-compiling)
66+
or -mcpu=generic+crc.
67+
68+
Signed-off-by: James Le Cuirot <[email protected]>
69+
--- a/CMakeLists.txt
70+
+++ b/CMakeLists.txt
71+
@@ -66,7 +66,15 @@ endif()
72+
if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
73+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
74+
elseif ((CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) OR (CMAKE_SYSTEM_PROCESSOR STREQUAL arm64))
75+
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=generic+crc -fsigned-char -fno-stack-protector -fomit-frame-pointer")
76+
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char -fno-stack-protector -fomit-frame-pointer")
77+
+ if (NOT CMAKE_CXX_FLAGS MATCHES "-march=|-mcpu=")
78+
+ check_cxx_compiler_flag(-mcpu=native COMPILER_HAS_NATIVE_FLAG)
79+
+ if (COMPILER_HAS_NATIVE_FLAG)
80+
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=native")
81+
+ else ()
82+
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=generic+crc")
83+
+ endif ()
84+
+ endif ()
85+
endif ()
86+
87+
check_cxx_compiler_flag(-mcrc32 COMPILER_HAS_MCRC32_FLAG)
88+
--
89+
2.49.0
90+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
From 0ee2c928de51ef56376c4ab6528ca1e23c13c4a7 Mon Sep 17 00:00:00 2001
2+
From: Krzesimir Nowak <[email protected]>
3+
Date: Fri, 8 Aug 2025 16:29:52 +0200
4+
Subject: [PATCH] fix
5+
6+
---
7+
scsi.cpp | 8 ++++----
8+
1 file changed, 4 insertions(+), 4 deletions(-)
9+
10+
diff --git a/scsi.cpp b/scsi.cpp
11+
index d8c27a9..4c7f480 100644
12+
--- a/scsi.cpp
13+
+++ b/scsi.cpp
14+
@@ -183,7 +183,7 @@ int tcmu_emulate_evpd_inquiry(
15+
{
16+
char data[512];
17+
char *ptr, *p, *wwn;
18+
- size_t len, used = 0;
19+
+ size_t len, used = 4;
20+
uint16_t *tot_len = (uint16_t*) &data[2];
21+
uint32_t padding;
22+
bool next;
23+
@@ -207,7 +207,7 @@ int tcmu_emulate_evpd_inquiry(
24+
25+
ptr[3] = 8 + len + 1;
26+
used += (uint8_t)ptr[3] + 4;
27+
- ptr += used;
28+
+ ptr += (uint8_t)ptr[3] + 4;
29+
30+
/* 2/5: NAA binary */
31+
ptr[0] = 1; /* code set: binary */
32+
@@ -340,9 +340,9 @@ int tcmu_emulate_evpd_inquiry(
33+
finish_page83:
34+
/* Done with descriptor list */
35+
36+
- *tot_len = htobe16(used);
37+
+ *tot_len = htobe16(used - 4);
38+
39+
- tcmu_memcpy_into_iovec(iovec, iov_cnt, data, used + 4);
40+
+ tcmu_memcpy_into_iovec(iovec, iov_cnt, data, used);
41+
42+
free(wwn);
43+
wwn = NULL;
44+
--
45+
2.49.1
46+

0 commit comments

Comments
 (0)