Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/api_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,7 @@ int start_api_server(ApiServer *&api_server , ImageService *imgservice, const st
}

int stop_api_server(ApiServer *api_server) {
if (api_server == nullptr) return 0;
safe_delete(api_server);
return 0;
}
4 changes: 2 additions & 2 deletions src/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ add_executable(overlaybd-zfile overlaybd-zfile.cpp)
target_include_directories(overlaybd-zfile PUBLIC ${PHOTON_INCLUDE_DIR})
target_link_libraries(overlaybd-zfile photon_static overlaybd_lib)

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

add_executable(turboOCI-apply turboOCI-apply.cpp)
Expand Down
25 changes: 21 additions & 4 deletions src/tools/overlaybd-apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "../image_service.h"
#include "../image_file.h"
#include "CLI11.hpp"
#include "comm_func.h"
#include "sha256file.h"
#include "qcow2converter.h"


using namespace std;
using namespace photon::fs;
Expand Down Expand Up @@ -82,18 +83,21 @@ class FIFOFile : public VirtualReadOnlyFile {
int main(int argc, char **argv) {
std::string image_config_path, input_path, gz_index_path, config_path, sha256_checksum;
string tarheader;
bool raw = false, mkfs = false, verbose = false;
bool raw = false, mkfs = false, verbose = false, qcow2 = false, extract_rootfs = true;

CLI::App app{"this is overlaybd-apply, apply OCIv1 tar layer to overlaybd format"};
CLI::App app{"this is overlaybd-apply, apply OCIv1 tar layer or qcow2 image to overlaybd format"};
app.add_flag("--raw", raw, "apply to raw image")->default_val(false);
app.add_flag("--mkfs", mkfs, "mkfs before apply")->default_val(false);
app.add_flag("--from_qcow2", qcow2, "convert from qcow2 image file instead of tar")->default_val(false);
app.add_flag("--extract-rootfs,!--no-extract-rootfs", extract_rootfs,
"Only extract rootfs partitions (default: on). "
"Use --no-extract-rootfs to convert entire disk.");

app.add_flag("--verbose", verbose, "output debug info")->default_val(false);
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");
app.add_option("--gz_index_path", gz_index_path, "build gzip index if layer is gzip, only used with turboOCIv1")->type_name("FILEPATH");
app.add_option("--checksum", sha256_checksum, "sha256 checksum for origin uncompressed data");
app.add_option("input_path", input_path, "input OCIv1 tar layer path")->type_name("FILEPATH")->check(CLI::ExistingFile)->required();

app.add_option("image_config_path", image_config_path, "overlaybd image config path")->type_name("FILEPATH")->check(CLI::ExistingFile)->required();
CLI11_PARSE(app, argc, argv);

Expand All @@ -103,6 +107,7 @@ int main(int argc, char **argv) {

ImageService *imgservice = nullptr;
photon::fs::IFile *imgfile = nullptr;

if (raw) {
imgfile = open_file(image_config_path.c_str(), O_RDWR, 0644);
} else {
Expand All @@ -116,6 +121,18 @@ int main(int argc, char **argv) {
delete imgfile;
delete imgservice;
});

if(qcow2){
int ret = convert_qcow2_to_imgfile(input_path.c_str(), imgfile,
DEFAULT_BLOCK_SIZE, verbose, extract_rootfs);
if (ret != 0) {
fprintf(stderr, "qcow2 conversion failed\n");
return -1;
}
Comment thread
xiecl666 marked this conversation as resolved.
printf("qcow2 to overlaybd conversion done\n");
return 0;
}

bool gen_turboOCI = (gz_index_path != "" );

auto target = create_ext4fs(imgfile, mkfs, !gen_turboOCI, "/");
Expand Down
Loading
Loading