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
22 changes: 12 additions & 10 deletions include/proxy-wasm/exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Word wasi_unstable_path_filestat_set_times(Word, Word, Word, Word, uint64_t, uin
Word wasi_unstable_path_link(Word, Word, Word, Word, Word, Word);
Word wasi_unstable_path_readlink(Word, Word, Word, Word, Word, Word);
Word wasi_unstable_path_remove_directory(Word, Word, Word);
Word wasi_unstable_path_rename(Word, Word, Word, Word, Word);
Word wasi_unstable_path_rename(Word, Word, Word, Word, Word, Word);
Word wasi_unstable_path_symlink(Word, Word, Word, Word);
Word wasi_unstable_path_unlink_file(Word, Word, Word);
Word wasi_unstable_sock_accept(Word, Word, Word);
Expand Down Expand Up @@ -211,15 +211,17 @@ Word wasi_unstable_path_filestat_get(Word fd, Word flags, Word path, Word path_l

#define FOR_ALL_WASI_FUNCTIONS(_f) \
_f(fd_write) _f(fd_read) _f(fd_seek) _f(fd_close) _f(fd_fdstat_get) _f(fd_fdstat_set_flags) \
_f(fd_fdstat_set_rights) _f(environ_get) _f(environ_sizes_get) _f(args_get) _f(args_sizes_get) \
_f(clock_time_get) _f(clock_res_get) _f(fd_advise) _f(fd_allocate) _f(fd_datasync) \
_f(fd_filestat_set_size) _f(fd_filestat_set_times) _f(fd_pread) _f(fd_pwrite) \
_f(fd_readdir) _f(fd_renumber) _f(fd_sync) _f(fd_tell) _f(path_create_directory) \
_f(path_filestat_set_times) _f(path_link) _f(path_readlink) _f(path_remove_directory) \
_f(path_rename) _f(path_symlink) _f(path_unlink_file) _f(sock_accept) \
_f(sock_recv) _f(sock_send) _f(sock_shutdown) _f(random_get) _f(sched_yield) \
_f(poll_oneoff) _f(proc_exit) _f(path_open) _f(fd_prestat_get) \
_f(fd_prestat_dir_name) _f(path_filestat_get) _f(fd_filestat_get)
_f(fd_fdstat_set_rights) _f(environ_get) _f(environ_sizes_get) _f(args_get) \
_f(args_sizes_get) _f(clock_time_get) _f(clock_res_get) _f(fd_advise) _f(fd_allocate) \
_f(fd_datasync) _f(fd_filestat_set_size) _f(fd_filestat_set_times) _f(fd_pread) \
_f(fd_pwrite) _f(fd_readdir) _f(fd_renumber) _f(fd_sync) _f(fd_tell) \
_f(path_create_directory) _f(path_filestat_set_times) _f(path_link) \
_f(path_readlink) _f(path_remove_directory) _f(path_rename) \
_f(path_symlink) _f(path_unlink_file) _f(sock_accept) _f(sock_recv) \
_f(sock_send) _f(sock_shutdown) _f(random_get) _f(sched_yield) \
_f(poll_oneoff) _f(proc_exit) _f(path_open) \
_f(fd_prestat_get) _f(fd_prestat_dir_name) \
_f(path_filestat_get) _f(fd_filestat_get)

// Helpers to generate a stub to pass to VM, in place of a restricted proxy-wasm capability.
#define _CREATE_PROXY_WASM_STUB(_fn) \
Expand Down
19 changes: 14 additions & 5 deletions include/proxy-wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
bool isFailed() { return failed_ != FailState::Ok; }
FailState fail_state() { return failed_; }

// Rebuild state management
bool shouldRebuild() const { return should_rebuild_; }
void setShouldRebuild(bool should_rebuild) { should_rebuild_ = should_rebuild; }

const std::string &vm_configuration() const;

const std::string &moduleBytecode() const { return module_bytecode_; }
Expand Down Expand Up @@ -317,6 +321,7 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
std::string vm_configuration_;
bool stop_iteration_ = false;
FailState failed_ = FailState::Ok; // Wasm VM fatal error.
bool should_rebuild_ = false; // Wasm VM rebuild flag.

// Plugin Stats/Metrics
uint32_t next_counter_metric_id_ = static_cast<uint32_t>(MetricType::Counter);
Expand Down Expand Up @@ -360,8 +365,8 @@ class WasmHandleBase : public std::enable_shared_from_this<WasmHandleBase> {
recover_vm_callback_ = std::move(f);
}

// Recover the wasm vm and generate a new wasm handle
bool doRecover(std::shared_ptr<WasmHandleBase> &new_handle) {
// Rebuild the wasm vm and generate a new wasm handle
bool rebuild(std::shared_ptr<WasmHandleBase> &new_handle) {
assert(new_handle == nullptr);
if (recover_vm_callback_ == nullptr) {
return true;
Expand Down Expand Up @@ -414,18 +419,22 @@ class PluginHandleBase : public std::enable_shared_from_this<PluginHandleBase> {
recover_plugin_callback_ = std::move(f);
}

// Recover the wasm plugin and generate a new plugin handle
bool doRecover(std::shared_ptr<PluginHandleBase> &new_handle) {
// Rebuild the wasm plugin and generate a new plugin handle
bool rebuild(std::shared_ptr<PluginHandleBase> &new_handle) {
assert(new_handle == nullptr);
if (recover_plugin_callback_ == nullptr) {
return true;
}
std::shared_ptr<WasmHandleBase> new_wasm_handle;
if (!wasm_handle_->doRecover(new_wasm_handle)) {
if (!wasm_handle_->rebuild(new_wasm_handle)) {
std::cerr << "wasmHandle rebuild failed"
<< "\n";
return false;
}
new_handle = recover_plugin_callback_(new_wasm_handle);
if (!new_handle) {
std::cerr << "pluginHandle rebuild failed"
<< "\n";
return false;
}
return true;
Expand Down
Loading
Loading