4141#include " CLI11.hpp"
4242#include " comm_func.h"
4343#include " sha256file.h"
44+ #include " qcow2converter.h"
45+
4446
4547using namespace std ;
4648using namespace photon ::fs;
@@ -81,6 +83,7 @@ class FIFOFile : public VirtualReadOnlyFile {
8183
8284int 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