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
1 change: 1 addition & 0 deletions src/bk_download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include "switch_file.h"
#include "image_file.h"

using namespace photon::fs;

Expand Down
1 change: 0 additions & 1 deletion src/bk_download.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class ISwitchFile;
namespace BKDL {

static std::string DOWNLOAD_TMP_NAME = ".download";
static std::string COMMIT_FILE_NAME = "overlaybd.commit";

bool check_downloaded(const std::string &dir);

Expand Down
13 changes: 10 additions & 3 deletions src/image_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,18 @@ int ImageFile::open_lower_layer(IFile *&file, ImageConfigNS::LayerConfig &layer,
} else {
// open downloaded blob or remote blob
if (BKDL::check_downloaded(layer.dir())) {
opened = layer.dir() + "/" + BKDL::COMMIT_FILE_NAME;
opened = layer.dir() + "/" + COMMIT_FILE_NAME;
file = __open_ro_file(opened);
} else {
opened = layer.digest();
file = __open_ro_remote(layer.dir(), layer.digest(), layer.size(), index);
auto sealed = layer.dir() + "/" + SEALED_FILE_NAME;
if (::access(sealed.c_str(), 0) == 0) {
// open sealed blob
opened = sealed;
file = __open_ro_file(opened);
} else {
opened = layer.digest();
file = __open_ro_remote(layer.dir(), layer.digest(), layer.size(), index);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/image_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include <photon/thread/thread11.h>
#include "overlaybd/lsmt/file.h"

static std::string COMMIT_FILE_NAME = "overlaybd.commit";
static std::string SEALED_FILE_NAME = "overlaybd.sealed";

class ImageFile : public photon::fs::ForwardFile {
public:
ImageFile(ImageConfigNS::ImageConfig &_conf, ImageService &is)
Expand Down
29 changes: 23 additions & 6 deletions src/tools/overlaybd-commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(int argc, char **argv) {
std::string data_file_path, index_file_path, commit_file_path, remote_mapping_file;
bool compress_zfile = false;
bool build_fastoci = false;
bool tar = false, rm_old = false;
bool tar = false, rm_old = false, seal = false, commit_sealed = false;

CLI::App app{"this is overlaybd-commit"};
app.add_option("-m", commit_msg, "add some custom message if needed");
Expand All @@ -70,24 +70,41 @@ int main(int argc, char **argv) {
"The size of a data block in KB. Must be a power of two between 4K~64K [4/8/16/32/64](default 4)");
app.add_flag("--fastoci", build_fastoci, "commit using fastoci format")->default_val(false);
app.add_option("data_file", data_file_path, "data file path")->type_name("FILEPATH")->check(CLI::ExistingFile)->required();
app.add_option("index_file", index_file_path, "index file path")->type_name("FILEPATH")->check(CLI::ExistingFile)->required();
app.add_option("commit_file", commit_file_path, "commit file path")->type_name("FILEPATH")->required();
app.add_option("index_file", index_file_path, "index file path")->type_name("FILEPATH");
app.add_option("commit_file", commit_file_path, "commit file path")->type_name("FILEPATH");
app.add_flag("--seal", seal, "seal only, data_file is output itself")->default_val(false);
app.add_flag("--commit_sealed", commit_sealed, "commit sealed, index_file is output")->default_val(false);
CLI11_PARSE(app, argc, argv);

set_log_output_level(1);
photon::init(photon::INIT_EVENT_DEFAULT, photon::INIT_IO_DEFAULT);

IFileSystem *lfs = new_localfs_adaptor();
IFile* fdata = open_file(lfs, data_file_path.c_str(), O_RDONLY, 0);
IFile* findex = open_file(lfs, index_file_path.c_str(), O_RDONLY, 0);

IFile* fdata = open_file(lfs, data_file_path.c_str(), O_RDWR, 0);
IFileRW* fin = nullptr;
if (build_fastoci) {
LOG_INFO("commit LSMTWarpFile with args: {index_file: `, fsmeta: `",
LOG_INFO("commit LSMTWarpFile with args: {index_file: `, fsmeta: `}",
index_file_path, data_file_path);
IFile* findex = open_file(lfs, index_file_path.c_str(), O_RDONLY, 0);
fin = open_warpfile_rw(findex, fdata, nullptr, true);
} if (commit_sealed) {
fin = (IFileRW*)open_file_ro(fdata, true);
commit_file_path = index_file_path; // the second param is for commit path
} else {
IFile* findex = open_file(lfs, index_file_path.c_str(), O_RDONLY, 0);
fin = open_file_rw(fdata, findex, true);
}

if (seal) {
if (fin->close_seal() < 0) {
fprintf(stderr, "failed to perform seal, %d: %s\n", errno, strerror(errno));
return -1;
}
delete fin;
return 0;
}

if (rm_old) {
lfs->unlink(commit_file_path.c_str());
}
Expand Down