Skip to content

Commit b7029b2

Browse files
authored
Merge pull request #360 from WaberZhuang/main
Fix CI & upper layer bug
2 parents 72a87f8 + 079248c commit b7029b2

File tree

6 files changed

+85
-28
lines changed

6 files changed

+85
-28
lines changed

.github/workflows/project-checks.yml

+47-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,50 @@ jobs:
2525
path: src/github.com/containerd/overlaybd
2626
fetch-depth: 100
2727

28-
- name: Project checks
29-
uses: containerd/[email protected]
30-
with:
31-
working-directory: src/github.com/containerd/overlaybd
28+
- name: set env
29+
shell: bash
30+
run: |
31+
echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
32+
echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
33+
34+
- name: Install dependencies
35+
shell: bash
36+
env:
37+
GO111MODULE: on
38+
run: |
39+
echo "::group::🚧 Get dependencies"
40+
go install -v github.com/vbatts/git-validation@latest
41+
go install -v github.com/containerd/ltag@latest
42+
echo "::endgroup::"
43+
44+
- name: DCO Checks
45+
shell: bash
46+
working-directory: src/github.com/containerd/overlaybd
47+
env:
48+
GITHUB_COMMIT_URL: ${{ github.event.pull_request.commits_url }}
49+
REPO_ACCESS_TOKEN: ""
50+
DCO_VERBOSITY: "-v"
51+
DCO_RANGE: ""
52+
run: |
53+
echo "::group::👮 DCO checks"
54+
set -x
55+
if [[ ! -z "${REPO_ACCESS_TOKEN}" ]]; then
56+
HEADERS=(-H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${REPO_ACCESS_TOKEN}")
57+
else
58+
HEADERS=(-H "Accept: application/vnd.github+json")
59+
fi
60+
if [ -z "${GITHUB_COMMIT_URL}" ]; then
61+
DCO_RANGE=$(jq -r '.after + "..HEAD"' ${GITHUB_EVENT_PATH})
62+
else
63+
DCO_RANGE=$(curl "${HEADERS[@]}" ${GITHUB_COMMIT_URL} | jq -r '.[0].parents[0].sha + "..HEAD"')
64+
fi
65+
git-validation ${DCO_VERBOSITY} ${DCO_RANGE} -run DCO,short-subject,dangling-whitespace
66+
echo "::endgroup::"
67+
68+
- name: Validate file headers
69+
shell: bash
70+
working-directory: src/github.com/containerd/overlaybd
71+
run: |
72+
echo "::group::📚 File headers"
73+
ltag -t "script/validate/template" --excludes "vendor contrib" --check -v
74+
echo "::endgroup::"

.github/workflows/release.yml

+14-7
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ jobs:
3131
uses: actions/checkout@v3
3232
with:
3333
submodules: true
34+
- name: Set up QEMU
35+
uses: docker/setup-qemu-action@v3
3436
- name: Setup buildx instance
35-
uses: docker/setup-buildx-action@v2
36-
with:
37-
use: true
37+
uses: docker/setup-buildx-action@v3
3838
- name: Build
3939
shell: bash
4040
run: |
@@ -84,10 +84,17 @@ jobs:
8484
ls -l releases/
8585
env:
8686
IMAGE: ${{ matrix.images }}
87+
- id: upload_name
88+
name: Upload name
89+
run: |
90+
image=${{ matrix.images }}
91+
platform=${{ matrix.platforms }}
92+
name="releases-${image//\//_}-${platform/\//_}"
93+
echo "name=${name}" >> "$GITHUB_OUTPUT"
8794
- name: Upload
88-
uses: actions/upload-artifact@v3
95+
uses: actions/upload-artifact@v4
8996
with:
90-
name: releases
97+
name: ${{ steps.upload_name.outputs.name }}
9198
path: releases/overlaybd-*.*
9299

93100
dev-release:
@@ -97,7 +104,7 @@ jobs:
97104
needs: [build]
98105
steps:
99106
- name: Download builds and release notes
100-
uses: actions/download-artifact@v3
107+
uses: actions/download-artifact@v4
101108
- name: Display downloaded files
102109
shell: bash
103110
run: ls -l releases
@@ -118,7 +125,7 @@ jobs:
118125
needs: [build]
119126
steps:
120127
- name: Download builds and release notes
121-
uses: actions/download-artifact@v3
128+
uses: actions/download-artifact@v4
122129
- name: Display downloaded files
123130
shell: bash
124131
run: ls -l releases

src/image_file.cpp

+17-9
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ int ImageFile::init_image_file() {
481481
goto ERROR_EXIT;
482482
}
483483

484+
// have only RO layers
484485
if (upper.index() == "" || upper.data() == "") {
485486
LOG_INFO("RW layer path not set. return RO layers.");
486487
m_file = lower_file;
@@ -493,29 +494,36 @@ int ImageFile::init_image_file() {
493494
LOG_ERROR("open upper layer failed.");
494495
goto ERROR_EXIT;
495496
}
496-
// We have to maintain the lower_file because prefetcher need the readonly
497-
// lower_file but not the writable m_file.
498-
//
499-
// Otherwise, lower_file and upper_file will lose the ownership of m_files
500-
// after stack_files(...), so we could safely delete them.
497+
498+
// have only one RW layer
499+
if (!lower_file) {
500+
LOG_INFO("RO layers path not set. return RW layer.");
501+
m_file = upper_file;
502+
read_only = false;
503+
goto SUCCESS_EXIT;
504+
}
505+
506+
// stack_files(..., ownership=true) will destruct lower_file and upper_file
507+
// immediately, but the read-only lower_file is needed by prefetcher, so we
508+
// have to use stack_files(..., ownership=false) instead.
501509
//
502-
// upper_file will be deleted immediately since it's useless.
503-
// lower_file will be held by ImageFile until deconstruct.
510+
// For this reason, lower_file and upper_file must be maintained until m_file
511+
// is deconstructed.
504512
stack_ret = LSMT::stack_files(upper_file, lower_file, false, false);
505513
if (!stack_ret) {
506514
LOG_ERROR("LSMT::stack_files(`, `)", (uint64_t)upper_file, true);
507515
goto ERROR_EXIT;
508516
}
509517
m_file = stack_ret;
510518
read_only = false;
511-
delete upper_file;
512519
m_lower_file = lower_file;
520+
m_upper_file = upper_file;
513521

514522
SUCCESS_EXIT:
515523
if (conf.download().enable() && !record_no_download) {
516524
start_bk_dl_thread();
517525
}
518-
if (m_prefetcher != nullptr) {
526+
if (m_prefetcher && lower_file) {
519527
m_prefetcher->replay(lower_file);
520528
}
521529
return 1;

src/image_file.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ class ImageFile : public photon::fs::ForwardFile {
6262
m_file->close();
6363
delete m_file;
6464
}
65-
if (m_lower_file) {
66-
delete m_lower_file;
67-
}
65+
if (m_lower_file) delete m_lower_file;
66+
if (m_upper_file) delete m_upper_file;
6867
}
6968

7069
int fstat(struct stat *buf) override {
@@ -121,6 +120,7 @@ class ImageFile : public photon::fs::ForwardFile {
121120
photon::join_handle *dl_thread_jh = nullptr;
122121
ImageService &image_service;
123122
photon::fs::IFile *m_lower_file = nullptr;
123+
photon::fs::IFile *m_upper_file = nullptr;
124124

125125
int init_image_file();
126126
template<typename...Ts> void set_failed(const Ts&...xs);

src/overlaybd/lsmt/file.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ IFileRW *stack_files(IFileRW *upper_layer, IFileRO *lower_layers, bool ownership
18071807
rst = new LSMTWarpFile;
18081808
delta++;
18091809
}
1810-
idx = create_combo_index((IMemoryIndex0 *)u->m_index, l->m_index, l->m_files.size(), true);
1810+
idx = create_combo_index((IMemoryIndex0 *)u->m_index, l->m_index, l->m_files.size(), ownership);
18111811
rst->m_index = idx;
18121812
rst->m_findex = u->m_findex;
18131813
rst->m_vsize = u->m_vsize;
@@ -1830,9 +1830,9 @@ IFileRW *stack_files(IFileRW *upper_layer, IFileRO *lower_layers, bool ownership
18301830
}
18311831
rst->m_uuid.push_back(u->m_uuid[0]);
18321832
rst->m_rw_tag = rst->m_files.size() - delta;
1833-
u->m_index = l->m_index = nullptr;
1834-
l->m_file_ownership = u->m_file_ownership = false;
18351833
if (ownership) {
1834+
u->m_index = l->m_index = nullptr;
1835+
l->m_file_ownership = u->m_file_ownership = false;
18361836
delete u;
18371837
delete l;
18381838
}

src/overlaybd/tar/erofs/test/erofs_stress_base.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ LSMT::IFileRW *StressBase::mkfs()
352352

353353
LSMT::IFileRW *img_file = nullptr;
354354
if (i > 0)
355-
img_file = LSMT::stack_files(current_layer, lowers, false, false);
355+
img_file = LSMT::stack_files(current_layer, lowers, true, false);
356356
else
357357
img_file = current_layer;
358358

@@ -362,7 +362,6 @@ LSMT::IFileRW *StressBase::mkfs()
362362
delete img_file;
363363
LOG_ERROR_RETURN(-1, nullptr, "fail to extract tar");
364364
}
365-
delete lowers;
366365
delete tar;
367366
lowers = img_file;
368367
}

0 commit comments

Comments
 (0)