Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/bk_download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <set>
#include <string>
#include <thread>
#include <mutex>
#include <sys/file.h>
#include <photon/common/alog.h>
#include <photon/common/alog-stdstring.h>
Expand Down Expand Up @@ -53,6 +54,7 @@ bool check_downloaded(const std::string &dir) {
return false;
}

static std::mutex lock_files_mutex;
static std::set<std::string> lock_files;

void BkDownload::switch_to_local_file() {
Expand Down Expand Up @@ -188,6 +190,7 @@ bool BkDownload::download() {
}

bool BkDownload::lock_file() {
std::lock_guard<std::mutex> lock(lock_files_mutex);
if (lock_files.find(dir) != lock_files.end()) {
LOG_WARN("failed to lock download path:`", dir);
return false;
Expand All @@ -197,6 +200,7 @@ bool BkDownload::lock_file() {
}

void BkDownload::unlock_file() {
std::lock_guard<std::mutex> lock(lock_files_mutex);
lock_files.erase(dir);
}

Expand Down Expand Up @@ -337,7 +341,7 @@ bool BkDownload::download_blob() {
return true;
}

void bk_download_proc(std::list<BKDL::BkDownload *> &dl_list, uint64_t delay_sec, int &running) {
void bk_download_proc(std::list<BKDL::BkDownload *> &dl_list, uint64_t delay_sec, volatile int &running) {
auto tracer = overlaybd_otel::get_tracer("overlaybd");
auto span = tracer->StartSpan("background_download_process");
auto scope = tracer->WithActiveSpan(span);
Expand Down
7 changes: 4 additions & 3 deletions src/bk_download.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <list>
#include <string>
#include <cstdint>
#include <atomic>
#include <photon/fs/filesystem.h>
#include "overlaybd/otel/tracer_common.h"

Expand Down Expand Up @@ -45,7 +46,7 @@ class BkDownload {
}
BkDownload(ISwitchFile *sw_file, photon::fs::IFile *src_file, size_t file_size,
const std::string &dir, const std::string &digest, const std::string &url,
int &running, int32_t limit_MB_ps, int32_t try_cnt, uint32_t bs)
volatile int &running, int32_t limit_MB_ps, int32_t try_cnt, uint32_t bs)
: dir(dir), try_cnt(try_cnt), sw_file(sw_file), src_file(src_file),
file_size(file_size), digest(digest), url(url), running(running),
limit_MB_ps(limit_MB_ps), block_size(bs) {
Expand All @@ -61,12 +62,12 @@ class BkDownload {
size_t file_size;
std::string digest;
std::string url;
int &running;
volatile int &running;
int32_t limit_MB_ps;
uint32_t block_size;
bool force_download = false;
};

void bk_download_proc(std::list<BKDL::BkDownload *> &, uint64_t, int &);
void bk_download_proc(std::list<BKDL::BkDownload *> &, uint64_t, volatile int &);

} // namespace BKDL
2 changes: 1 addition & 1 deletion src/image_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ImageFile : public photon::fs::ForwardFile {
int open_lower_layer(IFile *&file, ImageConfigNS::LayerConfig &layer, int index);

std::string m_exception;
int m_status = 0; // 0: not started, 1: running, -1 exit
volatile int m_status = 0; // 0: not started, 1: running, -1 exit

size_t size;
uint64_t num_lbas;
Expand Down