Skip to content

Commit 73f9008

Browse files
authored
Merge pull request #329 from BigVan/main
[feat.] minor changes.
2 parents 27b69e9 + 94933f9 commit 73f9008

File tree

8 files changed

+66
-47
lines changed

8 files changed

+66
-47
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
RELEASE_VERSION="${new_version}rc" #1.1.4rc
5454
fi
5555
RELEASE_VERSION=${RELEASE_VERSION#v}
56+
COMMIT_ID="${RELEASE_VERSION}-$(git rev-parse --short HEAD)"
5657
RELEASE_NO="$(date +%Y%m%d).$(git rev-parse --short HEAD)"
5758
5859
echo "RELEASE_VERSION=${RELEASE_VERSION} RELEASE_NO=${RELEASE_NO}"
@@ -67,7 +68,7 @@ jobs:
6768
echo "OS=${OS}"
6869
6970
70-
docker buildx build --build-arg BUILD_IMAGE=${BUILD_IMAGE} --build-arg OS=${OS} --build-arg RELEASE_VERSION=${RELEASE_VERSION} --build-arg RELEASE_NO=${RELEASE_NO} -f .github/workflows/release/Dockerfile --platform=${{ matrix.platforms }} -o releases/ .
71+
docker buildx build --build-arg COMMIT_ID=${COMMIT_ID} --build-arg BUILD_IMAGE=${BUILD_IMAGE} --build-arg OS=${OS} --build-arg RELEASE_VERSION=${RELEASE_VERSION} --build-arg RELEASE_NO=${RELEASE_NO} -f .github/workflows/release/Dockerfile --platform=${{ matrix.platforms }} -o releases/ .
7172
7273
# remove unused package
7374
if [[ "${OS}" =~ "ubuntu" ]]; then

.github/workflows/release/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ COPY . .
1919
ARG OS
2020
ARG RELEASE_VERSION
2121
ARG RELEASE_NO
22-
RUN ls -l /src && chmod 755 .github/workflows/release/build.sh && .github/workflows/release/build.sh ${OS} ${RELEASE_VERSION} ${RELEASE_NO}
22+
ARG COMMIT_ID
23+
RUN ls -l /src && chmod 755 .github/workflows/release/build.sh && .github/workflows/release/build.sh ${OS} ${RELEASE_VERSION} ${RELEASE_NO} ${COMMIT_ID}
2324

2425
FROM scratch AS release
2526
COPY --from=builder /src/build/overlaybd-*.* /

.github/workflows/release/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
OS=${1}
1919
PACKAGE_VERSION=${2}
2020
RELEASE_NO=${3}
21+
COMMIT_ID=${4}
2122
ARCH=`uname -m`
2223
BUILD_TYPE="Release"
2324
COMPILER=""
@@ -75,6 +76,6 @@ fi
7576
# Build
7677
mkdir build
7778
cd build
78-
${CMAKE} .. -DPACKAGE_VERSION=${PACKAGE_VERSION} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DBUILD_TESTING=0 -DENABLE_DSA=0 -DENABLE_ISAL=0 ${PACKAGE_RELEASE} ${COMPILER}
79+
${CMAKE} .. -DOBD_VER="overlaybd/${COMMIT_ID}" -DPACKAGE_VERSION=${PACKAGE_VERSION} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DBUILD_TESTING=0 -DENABLE_DSA=0 -DENABLE_ISAL=0 ${PACKAGE_RELEASE} ${COMPILER}
7980
make -j8
8081
${CPACK} --verbose

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ if (NOT (${ARCH} STREQUAL x86_64) AND NOT (${ARCH} STREQUAL aarch64) AND NOT (${
1212
message(FATAL_ERROR "Unknown CPU architecture ${ARCH}")
1313
endif ()
1414

15+
option(OBD_VER "Overlaybd version" "overlaybd/0.0.0-undefined")
16+
1517
set(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build/output")
1618
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build/output")
1719

1820
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
1921

2022
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic -Wall -Werror=sign-compare")
21-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpic -Wall -Werror=sign-compare")
23+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpic -Wall -Werror=sign-compare -DOVERLAYBD_VER=${OBD_VER}")
2224

2325
if (${ARCH} STREQUAL aarch64)
2426
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char")
@@ -39,6 +41,7 @@ endif()
3941
set(CMAKE_CXX_STANDARD 14)
4042
set(CMAKE_CXX_STANDARD_REQUIRED on)
4143
set(ENABLE_MIMIC_VDSO off)
44+
4245
option(BUILD_CURL_FROM_SOURCE "Compile static libcurl" off)
4346
option(ORIGIN_EXT2FS "Use original libext2fs" off)
4447
find_package(photon REQUIRED)

src/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include <vector>
2020
#include "overlaybd/config_util.h"
2121

22+
#define MACROTOSTR(x) #x
23+
#define PRINTMACRO(x) MACROTOSTR(x)
24+
static const char OVERLAYBD_VERSION[] = PRINTMACRO(OVERLAYBD_VER);
25+
2226
namespace ImageConfigNS {
2327
const int MAX_LAYER_CNT = 256;
2428

src/image_file.cpp

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ IFile *ImageFile::__open_ro_target_file(const std::string &path) {
102102
}
103103

104104
IFile *ImageFile::__open_ro_target_remote(const std::string &dir, const std::string &data_digest,
105-
const uint64_t size, int layer_index) {
105+
const uint64_t size, int layer_index) {
106106
std::string url;
107107

108108
if (conf.repoBlobUrl() == "") {
@@ -153,8 +153,7 @@ IFile *ImageFile::__open_ro_remote(const std::string &dir, const std::string &di
153153
LOG_ERROR_RETURN(0, nullptr, "empty repoBlobUrl for remote layer");
154154
}
155155
estring url = estring().appends("/", conf.repoBlobUrl(),
156-
(conf.repoBlobUrl().back() != '/') ? "/" : "",
157-
digest);
156+
(conf.repoBlobUrl().back() != '/') ? "/" : "", digest);
158157

159158
LOG_INFO("open file from remotefs: `, size: `", url, size);
160159
IFile *remote_file = image_service.global_fs.remote_fs->open(url.c_str(), O_RDONLY);
@@ -164,8 +163,14 @@ IFile *ImageFile::__open_ro_remote(const std::string &dir, const std::string &di
164163
set_failed("failed to open remote file ", url, ": ", err_msg);
165164
LOG_ERRNO_RETURN(0, nullptr, "failed to open remote file `: `", url, err_msg);
166165
}
167-
remote_file->ioctl(SET_SIZE, size);
168-
remote_file->ioctl(SET_LOCAL_DIR, dir);
166+
if (!dir.empty()) {
167+
remote_file->ioctl(SET_SIZE, size);
168+
remote_file->ioctl(SET_LOCAL_DIR, dir);
169+
} else {
170+
LOG_WARN(
171+
"local dir of layer %d (%s) didn't set, skip background anyway",
172+
layer_index, digest.c_str());
173+
}
169174

170175
IFile *tar_file = new_tar_file_adaptor(remote_file);
171176
if (!tar_file) {
@@ -183,15 +188,15 @@ IFile *ImageFile::__open_ro_remote(const std::string &dir, const std::string &di
183188
LOG_ERRNO_RETURN(0, nullptr, "failed to open switch file `", url);
184189
}
185190

186-
if (conf.HasMember("download") && conf.download().enable() == 1) {
191+
if (conf.HasMember("download") && conf.download().enable() == 1 && !dir.empty()) {
187192
// download from registry, verify sha256 after downloaded.
188193
IFile *srcfile = image_service.global_fs.srcfs->open(url.c_str(), O_RDONLY);
189194
if (srcfile == nullptr) {
190195
LOG_WARN("failed to open source file, ignore download");
191196
} else {
192-
BKDL::BkDownload *obj =
193-
new BKDL::BkDownload(switch_file, srcfile, size, dir, digest, url, m_status,
194-
conf.download().maxMBps(), conf.download().tryCnt(), conf.download().blockSize());
197+
BKDL::BkDownload *obj = new BKDL::BkDownload(
198+
switch_file, srcfile, size, dir, digest, url, m_status, conf.download().maxMBps(),
199+
conf.download().tryCnt(), conf.download().blockSize());
195200
LOG_DEBUG("add to download list for `", dir);
196201
dl_list.push_back(obj);
197202
}
@@ -209,8 +214,8 @@ void ImageFile::start_bk_dl_thread() {
209214
uint64_t extra_range = conf.download().delayExtra();
210215
extra_range = (extra_range <= 0) ? 30 : extra_range;
211216
uint64_t delay_sec = (rand() % extra_range) + conf.download().delay();
212-
LOG_INFO("background download is enabled, delay `, maxMBps `, tryCnt `, blockSize `",
213-
delay_sec, conf.download().maxMBps(), conf.download().tryCnt(), conf.download().blockSize());
217+
LOG_INFO("background download is enabled, delay `, maxMBps `, tryCnt `, blockSize `", delay_sec,
218+
conf.download().maxMBps(), conf.download().tryCnt(), conf.download().blockSize());
214219
dl_thread_jh = photon::thread_enable_join(
215220
photon::thread_create11(&BKDL::bk_download_proc, dl_list, delay_sec, m_status));
216221
}
@@ -256,30 +261,30 @@ void *do_parallel_open_files(ImageFile *imgfile, ParallelOpenTask &tm) {
256261
return nullptr;
257262
}
258263

259-
int ImageFile::open_lower_layer(IFile *&file, ImageConfigNS::LayerConfig &layer,
260-
int index) {
261-
std::string opened;
264+
IFile *ImageFile::open_localfile(ImageConfigNS::LayerConfig &layer, std::string &opened) {
262265
if (layer.file() != "") {
263266
opened = layer.file();
264-
file = __open_ro_file(opened);
265-
} else {
266-
// open downloaded blob or remote blob
267-
if (BKDL::check_downloaded(layer.dir())) {
268-
opened = layer.dir() + "/" + COMMIT_FILE_NAME;
269-
file = __open_ro_file(opened);
270-
} else {
271-
auto sealed = layer.dir() + "/" + SEALED_FILE_NAME;
272-
if (::access(sealed.c_str(), 0) == 0) {
273-
// open sealed blob
274-
opened = sealed;
275-
file = __open_ro_file(opened);
276-
} else {
277-
opened = layer.digest();
278-
file = __open_ro_remote(layer.dir(), layer.digest(), layer.size(), index);
279-
}
280-
}
267+
return __open_ro_file(opened);
268+
}
269+
if (BKDL::check_downloaded(layer.dir())) {
270+
opened = layer.dir() + "/" + COMMIT_FILE_NAME;
271+
return __open_ro_file(opened);
272+
}
273+
auto sealed = layer.dir() + "/" + SEALED_FILE_NAME;
274+
if (::access(sealed.c_str(), 0) == 0) {
275+
// open sealed blob
276+
opened = sealed;
277+
return __open_ro_file(opened);
278+
}
279+
return nullptr;
280+
}
281+
int ImageFile::open_lower_layer(IFile *&file, ImageConfigNS::LayerConfig &layer, int index) {
282+
std::string opened;
283+
file = open_localfile(layer, opened); // try to open localfile if downloaded
284+
if (file == nullptr) {
285+
opened = layer.digest();
286+
file = __open_ro_remote(layer.dir(), layer.digest(), layer.size(), index);
281287
}
282-
283288
if (file == nullptr) {
284289
return -1;
285290
}
@@ -305,8 +310,8 @@ int ImageFile::open_lower_layer(IFile *&file, ImageConfigNS::LayerConfig &layer,
305310
}
306311
target_file = new_gzfile(target_file, gz_index, true);
307312
if (image_service.global_conf.gzipCacheConfig().enable() && layer.targetDigest() != "") {
308-
target_file = image_service.global_fs.gzcache_fs->
309-
open_cached_gzip_file(target_file, layer.targetDigest().c_str());
313+
target_file = image_service.global_fs.gzcache_fs->open_cached_gzip_file(
314+
target_file, layer.targetDigest().c_str());
310315
}
311316
}
312317
if (target_file != nullptr) {
@@ -395,7 +400,8 @@ LSMT::IFileRW *ImageFile::open_upper(ImageConfigNS::UpperConfig &upper) {
395400
}
396401

397402
if (upper.target() != "") {
398-
LOG_INFO("turboOCIv1 upper layer : `, `, `, `", upper.index(), upper.data(), upper.target());
403+
LOG_INFO("turboOCIv1 upper layer : `, `, `, `", upper.index(), upper.data(),
404+
upper.target());
399405
target_file = open_localfile_adaptor(upper.target().c_str(), O_RDWR, 0644);
400406
if (!target_file) {
401407
LOG_ERROR("open(`,flags), `:`", upper.target(), errno, strerror(errno));
@@ -411,16 +417,16 @@ LSMT::IFileRW *ImageFile::open_upper(ImageConfigNS::UpperConfig &upper) {
411417
}
412418
ret = LSMT::open_warpfile_rw(idx_file, data_file, target_file, true);
413419
if (!ret) {
414-
LOG_ERROR("LSMT::open_warpfile_rw(`,`,`,`) return NULL",
415-
(uint64_t)data_file, (uint64_t)idx_file, (uint64_t)target_file, true);
420+
LOG_ERROR("LSMT::open_warpfile_rw(`,`,`,`) return NULL", (uint64_t)data_file,
421+
(uint64_t)idx_file, (uint64_t)target_file, true);
416422
goto ERROR_EXIT;
417423
}
418424
} else {
419425
LOG_INFO("overlaybd upper layer : ` , `", upper.index(), upper.data());
420426
ret = LSMT::open_file_rw(data_file, idx_file, true);
421427
if (!ret) {
422-
LOG_ERROR("LSMT::open_file_rw(`,`,`) return NULL",
423-
(uint64_t)data_file, (uint64_t)idx_file, true);
428+
LOG_ERROR("LSMT::open_file_rw(`,`,`) return NULL", (uint64_t)data_file,
429+
(uint64_t)idx_file, true);
424430
goto ERROR_EXIT;
425431
}
426432
}
@@ -453,8 +459,7 @@ int ImageFile::init_image_file() {
453459
LOG_INFO("Acceleration layer found at `, ignore the last lower", accel_layer);
454460

455461
std::string trace_file = accel_layer + "/trace";
456-
if (Prefetcher::detect_mode(trace_file) ==
457-
Prefetcher::Mode::Replay) {
462+
if (Prefetcher::detect_mode(trace_file) == Prefetcher::Mode::Replay) {
458463
m_prefetcher = new_prefetcher(trace_file, concurrency);
459464
}
460465

@@ -519,8 +524,8 @@ void ImageFile::set_auth_failed() {
519524
}
520525
}
521526

522-
template<typename...Ts>
523-
void ImageFile::set_failed(const Ts&...xs) {
527+
template <typename... Ts>
528+
void ImageFile::set_failed(const Ts &...xs) {
524529
if (m_status == 0) // only set exit in image boot phase
525530
{
526531
m_status = -1;

src/image_file.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class ImageFile : public photon::fs::ForwardFile {
119119
template<typename...Ts> void set_failed(const Ts&...xs);
120120
LSMT::IFileRO *open_lowers(std::vector<ImageConfigNS::LayerConfig> &, bool &);
121121
LSMT::IFileRW *open_upper(ImageConfigNS::UpperConfig &);
122+
123+
IFile *open_localfile(ImageConfigNS::LayerConfig &layer, std::string &opened);
122124
IFile *__open_ro_file(const std::string &);
123125
IFile *__open_ro_target_file(const std::string &);
124126
IFile *__open_ro_remote(const std::string &dir, const std::string &, const uint64_t, int);

src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ int main(int argc, char **argv) {
456456
LOG_INFO("reset netlink done");
457457
}
458458

459+
LOG_INFO("current version: `", OVERLAYBD_VERSION);
460+
459461
std::vector<struct tcmulib_handler> handlers;
460462
struct tcmulib_handler overlaybd_handler;
461463
overlaybd_handler.name = "Handler for overlaybd devices";

0 commit comments

Comments
 (0)