Skip to content

add overlaybd-resize tool for userspace ext4 resize on overlaybd images#408

Open
OsentryO wants to merge 1 commit into
containerd:mainfrom
OsentryO:feat/overlaybd-resize
Open

add overlaybd-resize tool for userspace ext4 resize on overlaybd images#408
OsentryO wants to merge 1 commit into
containerd:mainfrom
OsentryO:feat/overlaybd-resize

Conversation

@OsentryO

Copy link
Copy Markdown

Summary

Add overlaybd-resize tool that performs ext4 filesystem resize (shrink/expand) on overlaybd images in userspace, without kernel block device.

Changes

Usage

overlaybd-resize --config /path/to/config.v1.json --size 8G [--data_dir DIR] [--service_config_path PATH] [--verbose]

Supports size units: G, M, T (e.g. 8G, 500M, 1T). Default unit is MB.

Design

Two paths:
- No upper: creates new writable layer with vsize = max(target, 256GB), runs resize_extfs, updates vsize, overwrites config
- Has upper: reuses existing writable layer, expands vsize before resize_extfs (or truncates after for shrink)

Dependencies

- Requires photon with PHOTON_ENABLE_RESIZE=ON (backported to release/0.6 in PR alibaba/PhotonLibOS#1276)
- Requires e2fsprogs with resize optimization (merged in PR data-accelerator/e2fsprogs#10)

Testing

- 10 unit tests covering: basic shrink/expand, relocation, too-small target, non-aligned groups, empty disk, multiple resizes
- Verified on real overlaybd images: wordpress (no lazyinit), swebench (lazyinit), stable-diffusion (30 layers)
  - Shrink 256G→8G: 0.2-0.6s
  - Expand 256G→500G: 0.5-0.7s

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new userspace CLI (overlaybd-resize) to resize ext4 filesystems inside overlaybd images without requiring a kernel block device, along with unit tests and build system integration for the required Photon/e2fsprogs components.

Changes:

  • Adds src/tools/overlaybd-resize.cpp implementing shrink/expand flows for images with or without an existing upper layer.
  • Adds src/test/resize_test.cpp with unit tests covering resize scenarios and data integrity checks.
  • Integrates resize support into the build via CMake updates (Photon/e2fsprogs fetching and new tool/test targets).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/tools/overlaybd-resize.cpp New CLI tool implementing ext4 resize on overlaybd images in userspace.
src/tools/CMakeLists.txt Adds build/install target for overlaybd-resize gated by PHOTON_ENABLE_RESIZE.
src/test/resize_test.cpp New gtest-based unit tests for shrink/expand and edge cases.
src/test/CMakeLists.txt Adds resize_test target and registers it with CTest (gated).
CMake/Findphoton.cmake Updates Photon fetch revision and enables resize-related build flags.
CMake/Finde2fs.cmake Updates e2fsprogs fetch revision and exposes resize build directories for object linking.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +39 to +46
uint64_t multiplier = 1024ULL * 1024; // default MB
if (end && (*end == 'G' || *end == 'g'))
multiplier = 1024ULL * 1024 * 1024;
else if (end && (*end == 'T' || *end == 't'))
multiplier = 1024ULL * 1024 * 1024 * 1024;
else if (end && (*end == 'M' || *end == 'm'))
multiplier = 1024ULL * 1024;

Comment on lines +99 to +105
uint64_t vsize = *(uint64_t *)(buf + 48);
if (vsize == 0 || vsize > (1ULL << 50)) {
fprintf(stderr, "invalid vsize in header: %llu\n", (unsigned long long)vsize);
return -1;
}
return (int64_t)vsize;
}
Comment on lines +276 to +285
ImageService *imgservice = nullptr;
photon::fs::IFile *imgfile = nullptr;
create_overlaybd(service_config_path, config_path, imgservice, imgfile);
if (!imgfile) {
fprintf(stderr, "failed to open overlaybd image\n");
if (is_expand) {
update_vsize(existing_data_path, (uint64_t)current_vsize);
}
return 1;
}
Comment on lines +354 to +364
// Step 3: open image via ImageService
ImageService *imgservice = nullptr;
photon::fs::IFile *imgfile = nullptr;
create_overlaybd(service_config_path, tmp_config, imgservice, imgfile);
if (!imgfile) {
fprintf(stderr, "failed to open overlaybd image\n");
unlink(tmp_config.c_str());
unlink(data_path.c_str());
unlink(index_path.c_str());
return 1;
}
Comment on lines +107 to +123
static std::string parse_upper_data_path(const std::string &config_path) {
FILE *fp = fopen(config_path.c_str(), "r");
if (!fp) return "";
char readbuf[65536];
rapidjson::FileReadStream is(fp, readbuf, sizeof(readbuf));
rapidjson::Document doc;
doc.ParseStream(is);
fclose(fp);

if (doc.HasParseError()) return "";
if (!doc.HasMember("upper")) return "";
if (!doc["upper"].IsObject()) return "";
if (!doc["upper"].HasMember("data")) return "";
if (!doc["upper"]["data"].IsString()) return "";

return doc["upper"]["data"].GetString();
}
Comment thread src/test/resize_test.cpp
Comment on lines +34 to +53
static const char *TEST_IMG = "/tmp/resize_test.img";

static photon::fs::IFile *create_image(uint64_t size_mb) {
auto file = photon::fs::open_localfile_adaptor(
TEST_IMG, O_RDWR | O_CREAT | O_TRUNC, 0644, 0);
if (!file) return nullptr;
if (file->ftruncate(size_mb * MB) < 0) {
delete file;
return nullptr;
}
if (photon::fs::make_extfs(file) < 0) {
delete file;
return nullptr;
}
return file;
}

static void cleanup() {
::unlink(TEST_IMG);
}
Comment thread CMake/Findphoton.cmake
Comment on lines 3 to +5
set(PHOTON_ENABLE_EXTFS ON)
set(PHOTON_ENABLE_RESIZE ON)
add_definitions(-DPHOTON_ENABLE_RESIZE)
Comment on lines +139 to +141
// virtual_size is at offset 48 in HeaderTrailer (after magic0[8] + magic1[16] + size[4] + flags[4] + index_offset[8] + index_size[8])
uint64_t *vsize_ptr = (uint64_t *)(buf + 48);
*vsize_ptr = new_vsize;

CLI::App app{"overlaybd-resize: resize ext4 filesystem on overlaybd image in userspace"};
app.add_option("--config", config_path,
"overlaybd image config (config.v1.json from rpull)")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove'rpull'

app.add_option("--size", size_str,
"target size (e.g. 8G, 500G, 8192M)")
->required();
app.add_option("--data_dir", data_dir,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this...
do resize on the default 'upper' in config.v1.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants