Skip to content

Commit 902145d

Browse files
committed
feat:support convert qcow2 img to overlaybd
1 parent 14043c2 commit 902145d

4 files changed

Lines changed: 1116 additions & 3 deletions

File tree

src/tools/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ add_executable(overlaybd-zfile overlaybd-zfile.cpp)
1616
target_include_directories(overlaybd-zfile PUBLIC ${PHOTON_INCLUDE_DIR})
1717
target_link_libraries(overlaybd-zfile photon_static overlaybd_lib)
1818

19-
add_executable(overlaybd-apply overlaybd-apply.cpp)
19+
add_executable(overlaybd-apply overlaybd-apply.cpp qcow2converter.cpp)
2020
target_include_directories(overlaybd-apply PUBLIC ${PHOTON_INCLUDE_DIR} ${RAPIDJSON_INCLUDE_DIRS})
2121
target_link_libraries(overlaybd-apply photon_static overlaybd_lib overlaybd_image_lib checksum_lib)
2222
set_target_properties(overlaybd-apply PROPERTIES INSTALL_RPATH "/opt/overlaybd/lib")

src/tools/overlaybd-apply.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "CLI11.hpp"
4242
#include "comm_func.h"
4343
#include "sha256file.h"
44+
#include "qcow2converter.h"
45+
4446

4547
using namespace std;
4648
using namespace photon::fs;
@@ -81,6 +83,7 @@ class FIFOFile : public VirtualReadOnlyFile {
8183

8284
int main(int argc, char **argv) {
8385
std::string image_config_path, input_path, gz_index_path, config_path, sha256_checksum;
86+
std::string qcow2_path;
8487
string tarheader;
8588
bool raw = false, mkfs = false, verbose = false;
8689

@@ -92,8 +95,8 @@ int main(int argc, char **argv) {
9295
app.add_option("--service_config_path", config_path, "overlaybd image service config path")->type_name("FILEPATH")->check(CLI::ExistingFile)->default_val("/etc/overlaybd/overlaybd.json");
9396
app.add_option("--gz_index_path", gz_index_path, "build gzip index if layer is gzip, only used with turboOCIv1")->type_name("FILEPATH");
9497
app.add_option("--checksum", sha256_checksum, "sha256 checksum for origin uncompressed data");
95-
app.add_option("input_path", input_path, "input OCIv1 tar layer path")->type_name("FILEPATH")->check(CLI::ExistingFile)->required();
96-
98+
app.add_option("input_path", input_path, "input OCIv1 tar layer path")->type_name("FILEPATH")->check(CLI::ExistingFile);
99+
app.add_option("--from_qcow2", qcow2_path, "convert from qcow2 image file instead of tar")->type_name("FILEPATH")->check(CLI::ExistingFile);
97100
app.add_option("image_config_path", image_config_path, "overlaybd image config path")->type_name("FILEPATH")->check(CLI::ExistingFile)->required();
98101
CLI11_PARSE(app, argc, argv);
99102

@@ -103,6 +106,33 @@ int main(int argc, char **argv) {
103106

104107
ImageService *imgservice = nullptr;
105108
photon::fs::IFile *imgfile = nullptr;
109+
110+
// --- qcow2 mode: convert qcow2 directly to overlaybd LSMT layer ---
111+
if (!qcow2_path.empty()) {
112+
create_overlaybd(config_path, image_config_path, imgservice, imgfile);
113+
if (imgfile == nullptr) {
114+
fprintf(stderr, "failed to create image file\n");
115+
exit(-1);
116+
}
117+
118+
int ret = convert_qcow2_to_imgfile(qcow2_path.c_str(), imgfile,
119+
DEFAULT_BLOCK_SIZE, verbose, true);
120+
delete imgfile;
121+
delete imgservice;
122+
123+
if (ret != 0) {
124+
fprintf(stderr, "qcow2 conversion failed\n");
125+
exit(-1);
126+
}
127+
printf("qcow2 to overlaybd conversion done\n");
128+
return 0;
129+
}
130+
131+
// --- tar mode: normal overlaybd-apply flow ---
132+
if (input_path.empty()) {
133+
fprintf(stderr, "Either input_path (tar) or --from_qcow2 is required\n");
134+
exit(-1);
135+
}
106136
if (raw) {
107137
imgfile = open_file(image_config_path.c_str(), O_RDWR, 0644);
108138
} else {

0 commit comments

Comments
 (0)