Skip to content

Commit 04ef279

Browse files
authored
Add Wasm rebuild support and fix WASI path_rename signature (#10)
- Add rebuild mechanism for WasmHandle and PluginHandle with shouldRebuild flag - Fix wasi_unstable_path_rename signature to include new_path_len parameter - Rename doRecover to rebuild for better clarity - Add destructor cleanup with clearWasmInContext - Code formatting improvements 🤖 Generated with [Qoder][https://qoder.com] Co-developed-by: Claude <[email protected]> Signed-off-by: zty98751 <[email protected]>
1 parent 913c1b0 commit 04ef279

File tree

5 files changed

+227
-173
lines changed

5 files changed

+227
-173
lines changed

include/proxy-wasm/exports.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Word wasi_unstable_path_filestat_set_times(Word, Word, Word, Word, uint64_t, uin
174174
Word wasi_unstable_path_link(Word, Word, Word, Word, Word, Word);
175175
Word wasi_unstable_path_readlink(Word, Word, Word, Word, Word, Word);
176176
Word wasi_unstable_path_remove_directory(Word, Word, Word);
177-
Word wasi_unstable_path_rename(Word, Word, Word, Word, Word);
177+
Word wasi_unstable_path_rename(Word, Word, Word, Word, Word, Word);
178178
Word wasi_unstable_path_symlink(Word, Word, Word, Word);
179179
Word wasi_unstable_path_unlink_file(Word, Word, Word);
180180
Word wasi_unstable_sock_accept(Word, Word, Word);
@@ -211,15 +211,17 @@ Word wasi_unstable_path_filestat_get(Word fd, Word flags, Word path, Word path_l
211211

212212
#define FOR_ALL_WASI_FUNCTIONS(_f) \
213213
_f(fd_write) _f(fd_read) _f(fd_seek) _f(fd_close) _f(fd_fdstat_get) _f(fd_fdstat_set_flags) \
214-
_f(fd_fdstat_set_rights) _f(environ_get) _f(environ_sizes_get) _f(args_get) _f(args_sizes_get) \
215-
_f(clock_time_get) _f(clock_res_get) _f(fd_advise) _f(fd_allocate) _f(fd_datasync) \
216-
_f(fd_filestat_set_size) _f(fd_filestat_set_times) _f(fd_pread) _f(fd_pwrite) \
217-
_f(fd_readdir) _f(fd_renumber) _f(fd_sync) _f(fd_tell) _f(path_create_directory) \
218-
_f(path_filestat_set_times) _f(path_link) _f(path_readlink) _f(path_remove_directory) \
219-
_f(path_rename) _f(path_symlink) _f(path_unlink_file) _f(sock_accept) \
220-
_f(sock_recv) _f(sock_send) _f(sock_shutdown) _f(random_get) _f(sched_yield) \
221-
_f(poll_oneoff) _f(proc_exit) _f(path_open) _f(fd_prestat_get) \
222-
_f(fd_prestat_dir_name) _f(path_filestat_get) _f(fd_filestat_get)
214+
_f(fd_fdstat_set_rights) _f(environ_get) _f(environ_sizes_get) _f(args_get) \
215+
_f(args_sizes_get) _f(clock_time_get) _f(clock_res_get) _f(fd_advise) _f(fd_allocate) \
216+
_f(fd_datasync) _f(fd_filestat_set_size) _f(fd_filestat_set_times) _f(fd_pread) \
217+
_f(fd_pwrite) _f(fd_readdir) _f(fd_renumber) _f(fd_sync) _f(fd_tell) \
218+
_f(path_create_directory) _f(path_filestat_set_times) _f(path_link) \
219+
_f(path_readlink) _f(path_remove_directory) _f(path_rename) \
220+
_f(path_symlink) _f(path_unlink_file) _f(sock_accept) _f(sock_recv) \
221+
_f(sock_send) _f(sock_shutdown) _f(random_get) _f(sched_yield) \
222+
_f(poll_oneoff) _f(proc_exit) _f(path_open) \
223+
_f(fd_prestat_get) _f(fd_prestat_dir_name) \
224+
_f(path_filestat_get) _f(fd_filestat_get)
223225

224226
// Helpers to generate a stub to pass to VM, in place of a restricted proxy-wasm capability.
225227
#define _CREATE_PROXY_WASM_STUB(_fn) \

include/proxy-wasm/wasm.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
8585
bool isFailed() { return failed_ != FailState::Ok; }
8686
FailState fail_state() { return failed_; }
8787

88+
// Rebuild state management
89+
bool shouldRebuild() const { return should_rebuild_; }
90+
void setShouldRebuild(bool should_rebuild) { should_rebuild_ = should_rebuild; }
91+
8892
const std::string &vm_configuration() const;
8993

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

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

363-
// Recover the wasm vm and generate a new wasm handle
364-
bool doRecover(std::shared_ptr<WasmHandleBase> &new_handle) {
368+
// Rebuild the wasm vm and generate a new wasm handle
369+
bool rebuild(std::shared_ptr<WasmHandleBase> &new_handle) {
365370
assert(new_handle == nullptr);
366371
if (recover_vm_callback_ == nullptr) {
367372
return true;
@@ -414,18 +419,22 @@ class PluginHandleBase : public std::enable_shared_from_this<PluginHandleBase> {
414419
recover_plugin_callback_ = std::move(f);
415420
}
416421

417-
// Recover the wasm plugin and generate a new plugin handle
418-
bool doRecover(std::shared_ptr<PluginHandleBase> &new_handle) {
422+
// Rebuild the wasm plugin and generate a new plugin handle
423+
bool rebuild(std::shared_ptr<PluginHandleBase> &new_handle) {
419424
assert(new_handle == nullptr);
420425
if (recover_plugin_callback_ == nullptr) {
421426
return true;
422427
}
423428
std::shared_ptr<WasmHandleBase> new_wasm_handle;
424-
if (!wasm_handle_->doRecover(new_wasm_handle)) {
429+
if (!wasm_handle_->rebuild(new_wasm_handle)) {
430+
std::cerr << "wasmHandle rebuild failed"
431+
<< "\n";
425432
return false;
426433
}
427434
new_handle = recover_plugin_callback_(new_wasm_handle);
428435
if (!new_handle) {
436+
std::cerr << "pluginHandle rebuild failed"
437+
<< "\n";
429438
return false;
430439
}
431440
return true;

0 commit comments

Comments
 (0)