From 0968934647f87555bd3abf3eb6bde79999a9f26b Mon Sep 17 00:00:00 2001 From: Caio Ramos Casimiro Date: Fri, 9 Aug 2024 13:00:18 +0100 Subject: [PATCH] chore(shm) rename ngx_wasm_shm to ngx_wa_shm --- config | 12 +-- lib/resty/wasmx/shm.lua | 16 +-- src/common/lua/ngx_wasm_lua_ffi.c | 24 ++--- src/common/lua/ngx_wasm_lua_ffi.h | 6 +- src/common/metrics/ngx_wa_histogram.c | 4 +- src/common/metrics/ngx_wa_metrics.c | 48 ++++----- src/common/metrics/ngx_wa_metrics.h | 6 +- src/common/proxy_wasm/ngx_proxy_wasm_host.c | 55 +++++----- .../shm/{ngx_wasm_shm.c => ngx_wa_shm.c} | 44 ++++---- .../shm/{ngx_wasm_shm.h => ngx_wa_shm.h} | 24 ++--- .../{ngx_wasm_shm_kv.c => ngx_wa_shm_kv.c} | 102 +++++++++--------- .../{ngx_wasm_shm_kv.h => ngx_wa_shm_kv.h} | 22 ++-- ...gx_wasm_shm_queue.c => ngx_wa_shm_queue.c} | 54 +++++----- src/common/shm/ngx_wa_shm_queue.h | 19 ++++ src/common/shm/ngx_wasm_shm_queue.h | 19 ---- src/ngx_wasmx.c | 2 +- src/ngx_wasmx.h | 4 +- src/wasm/ngx_wasm_core_module.c | 6 +- src/wasm/ngx_wasm_directives.c | 20 ++-- t/04-openresty/ffi/shm/001-get_zones.t | 4 +- t/04-openresty/ffi/shm/002-get_keys.t | 4 +- t/04-openresty/ffi/shm/003-kv_get.t | 4 +- 22 files changed, 249 insertions(+), 250 deletions(-) rename src/common/shm/{ngx_wasm_shm.c => ngx_wa_shm.c} (67%) rename src/common/shm/{ngx_wasm_shm.h => ngx_wa_shm.h} (63%) rename src/common/shm/{ngx_wasm_shm_kv.c => ngx_wa_shm_kv.c} (76%) rename src/common/shm/{ngx_wasm_shm_kv.h => ngx_wa_shm_kv.h} (61%) rename src/common/shm/{ngx_wasm_shm_queue.c => ngx_wa_shm_queue.c} (79%) create mode 100644 src/common/shm/ngx_wa_shm_queue.h delete mode 100644 src/common/shm/ngx_wasm_shm_queue.h diff --git a/config b/config index e96f960bf..3c8e10dc9 100644 --- a/config +++ b/config @@ -140,9 +140,9 @@ NGX_WASMX_DEPS="\ $ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm.h \ $ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_maps.h \ $ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_properties.h \ - $ngx_addon_dir/src/common/shm/ngx_wasm_shm.h \ - $ngx_addon_dir/src/common/shm/ngx_wasm_shm_kv.h \ - $ngx_addon_dir/src/common/shm/ngx_wasm_shm_queue.h \ + $ngx_addon_dir/src/common/shm/ngx_wa_shm.h \ + $ngx_addon_dir/src/common/shm/ngx_wa_shm_kv.h \ + $ngx_addon_dir/src/common/shm/ngx_wa_shm_queue.h \ $ngx_addon_dir/src/common/metrics/ngx_wa_metrics.h" NGX_WASMX_SRCS="\ @@ -155,9 +155,9 @@ NGX_WASMX_SRCS="\ $ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_maps.c \ $ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_properties.c \ $ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_util.c \ - $ngx_addon_dir/src/common/shm/ngx_wasm_shm.c \ - $ngx_addon_dir/src/common/shm/ngx_wasm_shm_kv.c \ - $ngx_addon_dir/src/common/shm/ngx_wasm_shm_queue.c \ + $ngx_addon_dir/src/common/shm/ngx_wa_shm.c \ + $ngx_addon_dir/src/common/shm/ngx_wa_shm_kv.c \ + $ngx_addon_dir/src/common/shm/ngx_wa_shm_queue.c \ $ngx_addon_dir/src/common/metrics/ngx_wa_metrics.c \ $ngx_addon_dir/src/common/metrics/ngx_wa_histogram.c" diff --git a/lib/resty/wasmx/shm.lua b/lib/resty/wasmx/shm.lua index e3e9724f8..786e35c4a 100644 --- a/lib/resty/wasmx/shm.lua +++ b/lib/resty/wasmx/shm.lua @@ -47,22 +47,22 @@ ffi.cdef [[ NGX_WASM_SHM_TYPE_KV, NGX_WASM_SHM_TYPE_QUEUE, NGX_WASM_SHM_TYPE_METRICS, - } ngx_wasm_shm_type_e; + } ngx_wa_shm_type_e; typedef enum { NGX_WASM_SHM_EVICTION_LRU, NGX_WASM_SHM_EVICTION_SLRU, NGX_WASM_SHM_EVICTION_NONE, - } ngx_wasm_shm_eviction_e; + } ngx_wa_shm_eviction_e; typedef struct { - ngx_wasm_shm_type_e type; - ngx_wasm_shm_eviction_e eviction; + ngx_wa_shm_type_e type; + ngx_wa_shm_eviction_e eviction; ngx_str_t name; ngx_log_t *log; ngx_slab_pool_t *shpool; void *data; - } ngx_wasm_shm_t; + } ngx_wa_shm_t; typedef enum { NGX_WA_METRIC_COUNTER, @@ -98,14 +98,14 @@ ffi.cdef [[ } ngx_wa_metric_t; - typedef void (*ngx_wa_ffi_shm_get_zones_handler_pt)(ngx_wasm_shm_t *shm); + typedef void (*ngx_wa_ffi_shm_get_zones_handler_pt)(ngx_wa_shm_t *shm); int ngx_wa_ffi_shm_get_zones(ngx_wa_ffi_shm_get_zones_handler_pt handler); - int ngx_wa_ffi_shm_get_keys(ngx_wasm_shm_t *shm, + int ngx_wa_ffi_shm_get_keys(ngx_wa_shm_t *shm, ngx_uint_t n, ngx_str_t **keys); - int ngx_wa_ffi_shm_get_kv_value(ngx_wasm_shm_t *shm, + int ngx_wa_ffi_shm_get_kv_value(ngx_wa_shm_t *shm, ngx_str_t *k, ngx_str_t **v, uint32_t *cas); diff --git a/src/common/lua/ngx_wasm_lua_ffi.c b/src/common/lua/ngx_wasm_lua_ffi.c index 19f16fa05..216261f64 100644 --- a/src/common/lua/ngx_wasm_lua_ffi.c +++ b/src/common/lua/ngx_wasm_lua_ffi.c @@ -4,7 +4,7 @@ #include "ddebug.h" #include -#include +#include #include @@ -262,11 +262,11 @@ ngx_http_wasm_ffi_set_host_properties_handlers(ngx_http_request_t *r, ngx_int_t ngx_wa_ffi_shm_get_zones(ngx_wa_ffi_shm_get_zones_handler_pt handler) { - ngx_uint_t i; - ngx_cycle_t *cycle = (ngx_cycle_t *) ngx_cycle; - ngx_array_t *shms = ngx_wasmx_shms(cycle); - ngx_wasm_shm_mapping_t *mappings; - ngx_wasm_shm_t *shm; + ngx_uint_t i; + ngx_cycle_t *cycle = (ngx_cycle_t *) ngx_cycle; + ngx_array_t *shms = ngx_wasmx_shms(cycle); + ngx_wa_shm_t *shm; + ngx_wa_shm_mapping_t *mappings; if (!handler) { return NGX_ERROR; @@ -291,7 +291,7 @@ static void shm_kv_retrieve_keys(ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel, ngx_int_t *total, ngx_int_t limit, ngx_str_t **keys) { - ngx_wasm_shm_kv_node_t *n = (ngx_wasm_shm_kv_node_t *) node; + ngx_wa_shm_kv_node_t *n = (ngx_wa_shm_kv_node_t *) node; if (!node || node == sentinel || (limit > 0 && *total == limit)) { return; @@ -309,10 +309,10 @@ shm_kv_retrieve_keys(ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel, ngx_int_t -ngx_wa_ffi_shm_get_keys(ngx_wasm_shm_t *shm, ngx_uint_t n, ngx_str_t **keys) +ngx_wa_ffi_shm_get_keys(ngx_wa_shm_t *shm, ngx_uint_t n, ngx_str_t **keys) { - ngx_int_t total = 0; - ngx_wasm_shm_kv_t *kv; + ngx_int_t total = 0; + ngx_wa_shm_kv_t *kv; if (!shm || shm->type == NGX_WASM_SHM_TYPE_QUEUE) { return NGX_ERROR; @@ -331,14 +331,14 @@ ngx_wa_ffi_shm_get_keys(ngx_wasm_shm_t *shm, ngx_uint_t n, ngx_str_t **keys) ngx_int_t -ngx_wa_ffi_shm_get_kv_value(ngx_wasm_shm_t *shm, ngx_str_t *k, ngx_str_t **v, +ngx_wa_ffi_shm_get_kv_value(ngx_wa_shm_t *shm, ngx_str_t *k, ngx_str_t **v, uint32_t *cas) { if (!shm || !k || !v || !cas) { return NGX_ERROR; } - return ngx_wasm_shm_kv_get_locked(shm, k, NULL, v, cas); + return ngx_wa_shm_kv_get_locked(shm, k, NULL, v, cas); } diff --git a/src/common/lua/ngx_wasm_lua_ffi.h b/src/common/lua/ngx_wasm_lua_ffi.h index 9f2bfec2f..7df08c11f 100644 --- a/src/common/lua/ngx_wasm_lua_ffi.h +++ b/src/common/lua/ngx_wasm_lua_ffi.h @@ -24,7 +24,7 @@ typedef struct { } ngx_wasm_ffi_filter_t; -typedef void (*ngx_wa_ffi_shm_get_zones_handler_pt)(ngx_wasm_shm_t *shm); +typedef void (*ngx_wa_ffi_shm_get_zones_handler_pt)(ngx_wa_shm_t *shm); ngx_int_t ngx_http_wasm_ffi_plan_new(ngx_wavm_t *vm, @@ -47,9 +47,9 @@ ngx_int_t ngx_http_wasm_ffi_set_host_properties_handlers(ngx_http_request_t *r, ngx_int_t ngx_wa_ffi_shm_get_zones(ngx_wa_ffi_shm_get_zones_handler_pt handler); -ngx_int_t ngx_wa_ffi_shm_get_keys(ngx_wasm_shm_t *shm, ngx_uint_t n, +ngx_int_t ngx_wa_ffi_shm_get_keys(ngx_wa_shm_t *shm, ngx_uint_t n, ngx_str_t **keys); -ngx_int_t ngx_wa_ffi_shm_get_kv_value(ngx_wasm_shm_t *shm, ngx_str_t *k, +ngx_int_t ngx_wa_ffi_shm_get_kv_value(ngx_wa_shm_t *shm, ngx_str_t *k, ngx_str_t **v, uint32_t *cas); ngx_int_t ngx_wa_ffi_shm_get_metric(ngx_str_t *k, u_char *m_buf, size_t mbs, u_char *h_buf, size_t hbs); diff --git a/src/common/metrics/ngx_wa_histogram.c b/src/common/metrics/ngx_wa_histogram.c index ad3e394f1..b2d6184e3 100644 --- a/src/common/metrics/ngx_wa_histogram.c +++ b/src/common/metrics/ngx_wa_histogram.c @@ -49,7 +49,7 @@ histogram_grow(ngx_wa_metrics_t *metrics, ngx_wa_metrics_histogram_t *h, size = old_size + sizeof(ngx_wa_metrics_bin_t) * n; if (metrics->shm->eviction == NGX_WASM_SHM_EVICTION_NONE) { - ngx_wasm_shm_lock(metrics->shm); + ngx_wa_shm_lock(metrics->shm); } new_h = ngx_slab_calloc_locked(metrics->shm->shpool, size); @@ -69,7 +69,7 @@ histogram_grow(ngx_wa_metrics_t *metrics, ngx_wa_metrics_histogram_t *h, error: if (metrics->shm->eviction == NGX_WASM_SHM_EVICTION_NONE) { - ngx_wasm_shm_unlock(metrics->shm); + ngx_wa_shm_unlock(metrics->shm); } return rc; diff --git a/src/common/metrics/ngx_wa_metrics.c b/src/common/metrics/ngx_wa_metrics.c index e94b379d2..9b6b7d552 100644 --- a/src/common/metrics/ngx_wa_metrics.c +++ b/src/common/metrics/ngx_wa_metrics.c @@ -73,7 +73,7 @@ realloc_histogram(ngx_wa_metrics_t *metrics, ngx_wa_metric_t *old_m, ngx_str_t *val; ngx_wa_metric_t *m; - rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas); + rc = ngx_wa_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas); if (rc != NGX_OK) { return rc; } @@ -90,11 +90,11 @@ static ngx_int_t realloc_metrics(ngx_wa_metrics_t *metrics, ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) { - uint32_t mid; - ngx_int_t rc; - ngx_uint_t val; - ngx_wasm_shm_kv_node_t *n = (ngx_wasm_shm_kv_node_t *) node; - ngx_wa_metric_t *m = (ngx_wa_metric_t *) n->value.data; + uint32_t mid; + ngx_int_t rc; + ngx_uint_t val; + ngx_wa_shm_kv_node_t *n = (ngx_wa_shm_kv_node_t *) node; + ngx_wa_metric_t *m = (ngx_wa_metric_t *) n->value.data; if (node == sentinel) { return NGX_OK; @@ -167,7 +167,7 @@ ngx_wa_metrics_alloc(ngx_cycle_t *cycle) metrics->config.slab_size = NGX_CONF_UNSET_SIZE; metrics->config.max_metric_name_length = NGX_CONF_UNSET_SIZE; - metrics->shm = ngx_pcalloc(cycle->pool, sizeof(ngx_wasm_shm_t)); + metrics->shm = ngx_pcalloc(cycle->pool, sizeof(ngx_wa_shm_t)); if (metrics->shm == NULL) { ngx_pfree(cycle->pool, metrics); return NULL; @@ -217,7 +217,7 @@ ngx_wa_metrics_init_conf(ngx_wa_metrics_t *metrics, ngx_conf_t *cf) return NGX_CONF_ERROR; } - metrics->mapping->zone->init = ngx_wasm_shm_init_zone; + metrics->mapping->zone->init = ngx_wa_shm_init_zone; metrics->mapping->zone->data = metrics->shm; metrics->mapping->zone->noreuse = 0; @@ -235,9 +235,9 @@ ngx_wa_metrics_init_conf(ngx_wa_metrics_t *metrics, ngx_conf_t *cf) ngx_int_t ngx_wa_metrics_init(ngx_cycle_t *cycle) { - ngx_int_t rc; - ngx_wasm_shm_kv_t *old_shm_kv; - ngx_wa_metrics_t *metrics = ngx_wasmx_metrics(cycle); + ngx_int_t rc; + ngx_wa_shm_kv_t *old_shm_kv; + ngx_wa_metrics_t *metrics = ngx_wasmx_metrics(cycle); if (metrics->old_metrics && !metrics->mapping->zone->noreuse) { /* reuse old kv store */ @@ -245,7 +245,7 @@ ngx_wa_metrics_init(ngx_cycle_t *cycle) return NGX_OK; } - rc = ngx_wasm_shm_kv_init(metrics->shm); + rc = ngx_wa_shm_kv_init(metrics->shm); if (rc != NGX_OK) { return rc; } @@ -256,7 +256,7 @@ ngx_wa_metrics_init(ngx_cycle_t *cycle) metrics->mapping->zone->noreuse = 0; /* realloc old kv store */ - old_shm_kv = ngx_wasm_shm_get_kv(metrics->old_metrics->shm); + old_shm_kv = ngx_wa_shm_get_kv(metrics->old_metrics->shm); return realloc_metrics(metrics, old_shm_kv->rbtree.root, old_shm_kv->rbtree.sentinel); @@ -296,9 +296,9 @@ ngx_wa_metrics_define(ngx_wa_metrics_t *metrics, ngx_str_t *name, mid = ngx_crc32_long(name->data, name->len); - ngx_wasm_shm_lock(metrics->shm); + ngx_wa_shm_lock(metrics->shm); - rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &p, &cas); + rc = ngx_wa_shm_kv_get_locked(metrics->shm, NULL, &mid, &p, &cas); if (rc == NGX_OK) { ngx_log_debug1(NGX_LOG_DEBUG_WASM, metrics->shm->log, 0, "wasm returning existing metric id \"%uD\"", mid); @@ -321,7 +321,7 @@ ngx_wa_metrics_define(ngx_wa_metrics_t *metrics, ngx_str_t *name, val.len = size; val.data = buf; - rc = ngx_wasm_shm_kv_set_locked(metrics->shm, name, &val, 0, &written); + rc = ngx_wa_shm_kv_set_locked(metrics->shm, name, &val, 0, &written); if (rc != NGX_OK) { goto error; } @@ -332,7 +332,7 @@ ngx_wa_metrics_define(ngx_wa_metrics_t *metrics, ngx_str_t *name, error: - ngx_wasm_shm_unlock(metrics->shm); + ngx_wa_shm_unlock(metrics->shm); if (rc == NGX_OK) { ngx_wasm_log_error(NGX_LOG_INFO, metrics->shm->log, 0, @@ -365,11 +365,11 @@ ngx_wa_metrics_increment(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_int_t n) #if 0 if (metrics->shm->eviction != NGX_WASM_EVICTION_NONE) { slot = 0; - ngx_wasm_shm_lock(metrics->shm); + ngx_wa_shm_lock(metrics->shm); } #endif - rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas); + rc = ngx_wa_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas); if (rc != NGX_OK) { goto error; } @@ -394,7 +394,7 @@ ngx_wa_metrics_increment(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_int_t n) #if 0 if (metrics->shm->eviction != NGX_WASM_EVICTION_NONE) { - ngx_wasm_shm_unlock(metrics->shm); + ngx_wa_shm_unlock(metrics->shm); } #endif @@ -425,11 +425,11 @@ ngx_wa_metrics_record(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_int_t n) #if 0 if (metrics->shm->eviction != NGX_WASM_EVICTION_NONE) { slot = 0; - ngx_wasm_shm_lock(metrics->shm); + ngx_wa_shm_lock(metrics->shm); } #endif - rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas); + rc = ngx_wa_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas); if (rc != NGX_OK) { goto error; } @@ -458,7 +458,7 @@ ngx_wa_metrics_record(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_int_t n) #if 0 if (metrics->shm->eviction != NGX_WASM_EVICTION_NONE) { - ngx_wasm_shm_unlock(metrics->shm); + ngx_wa_shm_unlock(metrics->shm); } #endif @@ -482,7 +482,7 @@ ngx_wa_metrics_get(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_wa_metric_t *o) ngx_str_t *n; ngx_wa_metric_t *m; - rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &n, &cas); + rc = ngx_wa_shm_kv_get_locked(metrics->shm, NULL, &mid, &n, &cas); if (rc != NGX_OK) { goto done; } diff --git a/src/common/metrics/ngx_wa_metrics.h b/src/common/metrics/ngx_wa_metrics.h index 5ff21e803..a3204d96a 100644 --- a/src/common/metrics/ngx_wa_metrics.h +++ b/src/common/metrics/ngx_wa_metrics.h @@ -2,7 +2,7 @@ #define _NGX_WA_METRICS_H_INCLUDED_ -#include +#include #define ngx_wa_metrics_counter(m) m->slots[0].counter @@ -68,10 +68,10 @@ typedef struct { struct ngx_wa_metrics_s { ngx_uint_t workers; - ngx_wasm_shm_t *shm; + ngx_wa_shm_t *shm; ngx_wa_metrics_t *old_metrics; ngx_wa_metrics_conf_t config; - ngx_wasm_shm_mapping_t *mapping; + ngx_wa_shm_mapping_t *mapping; }; diff --git a/src/common/proxy_wasm/ngx_proxy_wasm_host.c b/src/common/proxy_wasm/ngx_proxy_wasm_host.c index 981b1638c..331eec334 100644 --- a/src/common/proxy_wasm/ngx_proxy_wasm_host.c +++ b/src/common/proxy_wasm/ngx_proxy_wasm_host.c @@ -8,8 +8,8 @@ #include #include #include -#include -#include +#include +#include #include #ifdef NGX_WASM_HTTP #include @@ -1248,7 +1248,7 @@ ngx_proxy_wasm_hfuncs_get_shared_data(ngx_wavm_instance_t *instance, ngx_str_t *value; uint32_t *value_data, *value_size, *cas; uint32_t wbuf_ptr; - ngx_wasm_shm_kv_key_t resolved; + ngx_wa_shm_kv_key_t resolved; ngx_proxy_wasm_exec_t *pwexec = ngx_proxy_wasm_instance2pwexec(instance); key.len = args[1].of.i32; @@ -1261,7 +1261,7 @@ ngx_proxy_wasm_hfuncs_get_shared_data(ngx_wavm_instance_t *instance, /* resolve key namespace */ - rc = ngx_wasm_shm_kv_resolve_key(&key, &resolved); + rc = ngx_wa_shm_kv_resolve_key(&key, &resolved); if (rc == NGX_ABORT) { return ngx_proxy_wasm_result_trap(pwexec, "attempt to get " "key/value from a queue", rets, @@ -1280,11 +1280,11 @@ ngx_proxy_wasm_hfuncs_get_shared_data(ngx_wavm_instance_t *instance, /* get */ - ngx_wasm_shm_lock(resolved.shm); + ngx_wa_shm_lock(resolved.shm); - rc = ngx_wasm_shm_kv_get_locked(resolved.shm, &key, NULL, &value, cas); + rc = ngx_wa_shm_kv_get_locked(resolved.shm, &key, NULL, &value, cas); - ngx_wasm_shm_unlock(resolved.shm); + ngx_wa_shm_unlock(resolved.shm); if (rc == NGX_DECLINED) { return ngx_proxy_wasm_result_notfound(rets); @@ -1319,7 +1319,7 @@ ngx_proxy_wasm_hfuncs_set_shared_data(ngx_wavm_instance_t *instance, uint32_t cas; ngx_int_t rc, written; ngx_str_t key, value; - ngx_wasm_shm_kv_key_t resolved; + ngx_wa_shm_kv_key_t resolved; ngx_proxy_wasm_exec_t *pwexec = ngx_proxy_wasm_instance2pwexec(instance); key.len = args[1].of.i32; @@ -1334,7 +1334,7 @@ ngx_proxy_wasm_hfuncs_set_shared_data(ngx_wavm_instance_t *instance, /* resolve key namespace */ - rc = ngx_wasm_shm_kv_resolve_key(&key, &resolved); + rc = ngx_wa_shm_kv_resolve_key(&key, &resolved); if (rc == NGX_ABORT) { /* TODO: format with key */ return ngx_proxy_wasm_result_trap(pwexec, "attempt to set " @@ -1354,7 +1354,7 @@ ngx_proxy_wasm_hfuncs_set_shared_data(ngx_wavm_instance_t *instance, /* set */ - ngx_wasm_shm_lock(resolved.shm); + ngx_wa_shm_lock(resolved.shm); /* * If the filter passes a NULL value pointer, treat it as a delete request. @@ -1362,11 +1362,11 @@ ngx_proxy_wasm_hfuncs_set_shared_data(ngx_wavm_instance_t *instance, * - Setting an empty value (ptr != NULL, len == 0) * - Deleting a k/v pair (ptr == NULL, len == 0) */ - rc = ngx_wasm_shm_kv_set_locked(resolved.shm, - &key, value.data ? &value : NULL, - cas, &written); + rc = ngx_wa_shm_kv_set_locked(resolved.shm, + &key, value.data ? &value : NULL, + cas, &written); - ngx_wasm_shm_unlock(resolved.shm); + ngx_wa_shm_unlock(resolved.shm); if (rc == NGX_ERROR) { /* TODO: format with key */ @@ -1396,7 +1396,7 @@ ngx_proxy_wasm_hfuncs_register_shared_queue(ngx_wavm_instance_t *instance, uint32_t *token; ngx_int_t zone_idx; ngx_str_t queue_name; - ngx_wasm_shm_t *shm; + ngx_wa_shm_t *shm; ngx_shm_zone_t *zone; ngx_cycle_t *cycle = (ngx_cycle_t *) ngx_cycle; ngx_proxy_wasm_exec_t *pwexec = ngx_proxy_wasm_instance2pwexec(instance); @@ -1406,14 +1406,14 @@ ngx_proxy_wasm_hfuncs_register_shared_queue(ngx_wavm_instance_t *instance, queue_name.len); token = NGX_WAVM_HOST_LIFT(instance, args[2].of.i32, uint32_t); - zone_idx = ngx_wasm_shm_lookup_index(&queue_name); + zone_idx = ngx_wa_shm_lookup_index(&queue_name); if (zone_idx == NGX_WASM_SHM_INDEX_NOTFOUND) { /* TODO: format with queue name */ return ngx_proxy_wasm_result_trap(pwexec, "could not find queue", rets, NGX_WAVM_BAD_USAGE); } - zone = ((ngx_wasm_shm_mapping_t *) + zone = ((ngx_wa_shm_mapping_t *) ngx_wasmx_shms(cycle)->elts)[zone_idx].zone; shm = zone->data; @@ -1439,7 +1439,7 @@ ngx_proxy_wasm_hfuncs_enqueue_shared_queue(ngx_wavm_instance_t *instance, ngx_uint_t token; ngx_str_t data; ngx_shm_zone_t *zone; - ngx_wasm_shm_t *shm; + ngx_wa_shm_t *shm; ngx_proxy_wasm_exec_t *pwexec = ngx_proxy_wasm_instance2pwexec(instance); token = args[0].of.i32; @@ -1448,7 +1448,7 @@ ngx_proxy_wasm_hfuncs_enqueue_shared_queue(ngx_wavm_instance_t *instance, /* resolve queue */ - rc = ngx_wasm_shm_queue_resolve(instance->log, token, &zone); + rc = ngx_wa_shm_queue_resolve(instance->log, token, &zone); if (rc == NGX_DECLINED) { /* TODO: format with token */ return ngx_proxy_wasm_result_trap(pwexec, "could not find queue", rets, @@ -1468,9 +1468,9 @@ ngx_proxy_wasm_hfuncs_enqueue_shared_queue(ngx_wavm_instance_t *instance, /* push */ - ngx_wasm_shm_lock(shm); - rc = ngx_wasm_shm_queue_push_locked(shm, &data); - ngx_wasm_shm_unlock(shm); + ngx_wa_shm_lock(shm); + rc = ngx_wa_shm_queue_push_locked(shm, &data); + ngx_wa_shm_unlock(shm); if (rc == NGX_ABORT) { /* TODO: format with queue name */ @@ -1511,7 +1511,7 @@ ngx_proxy_wasm_hfuncs_dequeue_shared_queue(ngx_wavm_instance_t *instance, ngx_uint_t token; ngx_str_t data; ngx_shm_zone_t *zone; - ngx_wasm_shm_t *shm; + ngx_wa_shm_t *shm; uint32_t *wasm_data_ptr; uint32_t *wasm_data_size; ngx_proxy_wasm_exec_t *pwexec = ngx_proxy_wasm_instance2pwexec(instance); @@ -1522,7 +1522,7 @@ ngx_proxy_wasm_hfuncs_dequeue_shared_queue(ngx_wavm_instance_t *instance, /* resolve queue */ - rc = ngx_wasm_shm_queue_resolve(instance->log, token, &zone); + rc = ngx_wa_shm_queue_resolve(instance->log, token, &zone); if (rc == NGX_DECLINED) { /* TODO: format with token */ return ngx_proxy_wasm_result_trap(pwexec, "could not find queue", rets, @@ -1542,10 +1542,9 @@ ngx_proxy_wasm_hfuncs_dequeue_shared_queue(ngx_wavm_instance_t *instance, /* pop */ - ngx_wasm_shm_lock(shm); - rc = ngx_wasm_shm_queue_pop_locked(shm, &data, - shared_queue_alloc, instance); - ngx_wasm_shm_unlock(shm); + ngx_wa_shm_lock(shm); + rc = ngx_wa_shm_queue_pop_locked(shm, &data, shared_queue_alloc, instance); + ngx_wa_shm_unlock(shm); if (rc == NGX_ERROR) { return ngx_proxy_wasm_result_err(rets); diff --git a/src/common/shm/ngx_wasm_shm.c b/src/common/shm/ngx_wa_shm.c similarity index 67% rename from src/common/shm/ngx_wasm_shm.c rename to src/common/shm/ngx_wa_shm.c index 6b56a1bb3..03d69c1de 100644 --- a/src/common/shm/ngx_wasm_shm.c +++ b/src/common/shm/ngx_wa_shm.c @@ -4,14 +4,14 @@ #include "ddebug.h" #include -#include -#include +#include +#include ngx_int_t -ngx_wasm_shm_init_zone(ngx_shm_zone_t *shm_zone, void *data) +ngx_wa_shm_init_zone(ngx_shm_zone_t *shm_zone, void *data) { - ngx_wasm_shm_t *shm = shm_zone->data; + ngx_wa_shm_t *shm = shm_zone->data; dd("zone: %p", shm_zone->shm.addr); @@ -22,13 +22,13 @@ ngx_wasm_shm_init_zone(ngx_shm_zone_t *shm_zone, void *data) ngx_int_t -ngx_wasm_shm_init(ngx_cycle_t *cycle) +ngx_wa_shm_init(ngx_cycle_t *cycle) { - size_t i; - ngx_int_t rc; - ngx_array_t *shms = ngx_wasmx_shms(cycle); - ngx_wasm_shm_mapping_t *mappings = shms->elts; - ngx_wasm_shm_t *shm; + size_t i; + ngx_int_t rc; + ngx_array_t *shms = ngx_wasmx_shms(cycle); + ngx_wa_shm_mapping_t *mappings = shms->elts; + ngx_wa_shm_t *shm; for (i = 0; i < shms->nelts; i++ ) { shm = mappings[i].zone->data; @@ -40,14 +40,14 @@ ngx_wasm_shm_init(ngx_cycle_t *cycle) switch (shm->type) { case NGX_WASM_SHM_TYPE_KV: - rc = ngx_wasm_shm_kv_init(shm); + rc = ngx_wa_shm_kv_init(shm); if (rc != NGX_OK) { return rc; } dd("kv init done"); break; case NGX_WASM_SHM_TYPE_QUEUE: - rc = ngx_wasm_shm_queue_init(shm); + rc = ngx_wa_shm_queue_init(shm); if (rc != NGX_OK) { return rc; } @@ -71,13 +71,13 @@ ngx_wasm_shm_init(ngx_cycle_t *cycle) ngx_int_t -ngx_wasm_shm_init_process(ngx_cycle_t *cycle) +ngx_wa_shm_init_process(ngx_cycle_t *cycle) { #if (NGX_DEBUG) - size_t i; - ngx_array_t *shms = ngx_wasmx_shms(cycle); - ngx_wasm_shm_mapping_t *mappings = shms->elts; - ngx_wasm_shm_t *shm; + size_t i; + ngx_array_t *shms = ngx_wasmx_shms(cycle); + ngx_wa_shm_mapping_t *mappings = shms->elts; + ngx_wa_shm_t *shm; for (i = 0; i < shms->nelts; i++ ) { shm = mappings[i].zone->data; @@ -95,12 +95,12 @@ ngx_wasm_shm_init_process(ngx_cycle_t *cycle) ngx_int_t -ngx_wasm_shm_lookup_index(ngx_str_t *name) +ngx_wa_shm_lookup_index(ngx_str_t *name) { - size_t i; - ngx_array_t *shms; - ngx_cycle_t *cycle = (ngx_cycle_t *) ngx_cycle; - ngx_wasm_shm_mapping_t *elements; + size_t i; + ngx_array_t *shms; + ngx_cycle_t *cycle = (ngx_cycle_t *) ngx_cycle; + ngx_wa_shm_mapping_t *elements; shms = ngx_wasmx_shms(cycle); elements = shms->elts; diff --git a/src/common/shm/ngx_wasm_shm.h b/src/common/shm/ngx_wa_shm.h similarity index 63% rename from src/common/shm/ngx_wasm_shm.h rename to src/common/shm/ngx_wa_shm.h index b8af8eb52..2ac18b680 100644 --- a/src/common/shm/ngx_wasm_shm.h +++ b/src/common/shm/ngx_wa_shm.h @@ -13,47 +13,47 @@ typedef enum { NGX_WASM_SHM_TYPE_KV, NGX_WASM_SHM_TYPE_QUEUE, NGX_WASM_SHM_TYPE_METRICS, -} ngx_wasm_shm_type_e; +} ngx_wa_shm_type_e; typedef enum { NGX_WASM_SHM_EVICTION_LRU, NGX_WASM_SHM_EVICTION_SLRU, NGX_WASM_SHM_EVICTION_NONE, -} ngx_wasm_shm_eviction_e; +} ngx_wa_shm_eviction_e; typedef struct { - ngx_wasm_shm_type_e type; - ngx_wasm_shm_eviction_e eviction; + ngx_wa_shm_type_e type; + ngx_wa_shm_eviction_e eviction; ngx_str_t name; ngx_log_t *log; ngx_slab_pool_t *shpool; void *data; -} ngx_wasm_shm_t; +} ngx_wa_shm_t; typedef struct { ngx_str_t name; ngx_shm_zone_t *zone; -} ngx_wasm_shm_mapping_t; +} ngx_wa_shm_mapping_t; -ngx_int_t ngx_wasm_shm_init(ngx_cycle_t *cycle); -ngx_int_t ngx_wasm_shm_init_zone(ngx_shm_zone_t *shm_zone, void *data); -ngx_int_t ngx_wasm_shm_init_process(ngx_cycle_t *cycle); -ngx_int_t ngx_wasm_shm_lookup_index(ngx_str_t *name); +ngx_int_t ngx_wa_shm_init(ngx_cycle_t *cycle); +ngx_int_t ngx_wa_shm_init_zone(ngx_shm_zone_t *shm_zone, void *data); +ngx_int_t ngx_wa_shm_init_process(ngx_cycle_t *cycle); +ngx_int_t ngx_wa_shm_lookup_index(ngx_str_t *name); static ngx_inline void -ngx_wasm_shm_lock(ngx_wasm_shm_t *shm) +ngx_wa_shm_lock(ngx_wa_shm_t *shm) { ngx_shmtx_lock(&shm->shpool->mutex); } static ngx_inline void -ngx_wasm_shm_unlock(ngx_wasm_shm_t *shm) +ngx_wa_shm_unlock(ngx_wa_shm_t *shm) { ngx_shmtx_unlock(&shm->shpool->mutex); } diff --git a/src/common/shm/ngx_wasm_shm_kv.c b/src/common/shm/ngx_wa_shm_kv.c similarity index 76% rename from src/common/shm/ngx_wasm_shm_kv.c rename to src/common/shm/ngx_wa_shm_kv.c index a463c3ae9..d59dd09dc 100644 --- a/src/common/shm/ngx_wasm_shm_kv.c +++ b/src/common/shm/ngx_wa_shm_kv.c @@ -4,7 +4,7 @@ #include "ddebug.h" #include -#include +#include /* as defined in nginx/src/core/ngx_slab.c */ @@ -15,8 +15,8 @@ #define NGX_WASM_SLRU_NQUEUES(pool) (NGX_WASM_SLAB_SLOTS(pool) + 1) -ngx_wasm_shm_kv_t * -ngx_wasm_shm_get_kv(ngx_wasm_shm_t *shm) +ngx_wa_shm_kv_t * +ngx_wa_shm_get_kv(ngx_wa_shm_t *shm) { ngx_wa_assert(shm->type == NGX_WASM_SHM_TYPE_KV || \ shm->type == NGX_WASM_SHM_TYPE_METRICS); @@ -25,14 +25,14 @@ ngx_wasm_shm_get_kv(ngx_wasm_shm_t *shm) ngx_int_t -ngx_wasm_shm_kv_init(ngx_wasm_shm_t *shm) +ngx_wa_shm_kv_init(ngx_wa_shm_t *shm) { - size_t size, i; - ngx_uint_t n; - ngx_wasm_shm_kv_t *kv; + size_t size, i; + ngx_uint_t n; + ngx_wa_shm_kv_t *kv; n = 0; - size = sizeof(ngx_wasm_shm_kv_t); + size = sizeof(ngx_wa_shm_kv_t); if (shm->eviction == NGX_WASM_SHM_EVICTION_SLRU) { n = NGX_WASM_SLRU_NQUEUES(shm->shpool); @@ -65,7 +65,7 @@ ngx_wasm_shm_kv_init(ngx_wasm_shm_t *shm) static ngx_uint_t -slru_index_for_size(ngx_wasm_shm_t *shm, size_t size) +slru_index_for_size(ngx_wa_shm_t *shm, size_t size) { size_t s; ngx_uint_t shift; @@ -83,7 +83,7 @@ slru_index_for_size(ngx_wasm_shm_t *shm, size_t size) /** * The above condition will always be true as long as - * sizeof(ngx_wasm_shm_kv_node_t) > shm->shpool->min_size. We do not assert + * sizeof(ngx_wa_shm_kv_node_t) > shm->shpool->min_size. We do not assert * it unconditionally because min_size depends on the Nginx page size * configuration. The fallback case is to use the first queue for small * items, strictly following the Nginx slot selection algorithm. @@ -93,17 +93,17 @@ slru_index_for_size(ngx_wasm_shm_t *shm, size_t size) static ngx_queue_t* -queue_for_node(ngx_wasm_shm_t *shm, ngx_wasm_shm_kv_node_t *n) +queue_for_node(ngx_wa_shm_t *shm, ngx_wa_shm_kv_node_t *n) { - size_t size; - ngx_wasm_shm_kv_t *kv = ngx_wasm_shm_get_kv(shm); + size_t size; + ngx_wa_shm_kv_t *kv = ngx_wa_shm_get_kv(shm); if (shm->eviction == NGX_WASM_SHM_EVICTION_LRU) { return &kv->eviction.lru_queue; } if (shm->eviction == NGX_WASM_SHM_EVICTION_SLRU) { - size = sizeof(ngx_wasm_shm_kv_node_t) + size = sizeof(ngx_wa_shm_kv_node_t) + n->key.str.len + n->value.len; @@ -116,18 +116,18 @@ queue_for_node(ngx_wasm_shm_t *shm, ngx_wasm_shm_kv_node_t *n) } -static ngx_wasm_shm_kv_node_t * -ngx_wasm_shm_rbtree_lookup(ngx_rbtree_t *rbtree, uint32_t key_hash) +static ngx_wa_shm_kv_node_t * +ngx_wa_shm_rbtree_lookup(ngx_rbtree_t *rbtree, uint32_t key_hash) { - ngx_wasm_shm_kv_node_t *n; - ngx_rbtree_node_t *node, *sentinel; + ngx_rbtree_node_t *node, *sentinel; + ngx_wa_shm_kv_node_t *n; node = rbtree->root; sentinel = rbtree->sentinel; while (node != sentinel) { - n = (ngx_wasm_shm_kv_node_t *) node; + n = (ngx_wa_shm_kv_node_t *) node; if (key_hash != node->key) { node = (key_hash < node->key) ? node->left : node->right; @@ -142,18 +142,18 @@ ngx_wasm_shm_rbtree_lookup(ngx_rbtree_t *rbtree, uint32_t key_hash) ngx_int_t -ngx_wasm_shm_kv_get_locked(ngx_wasm_shm_t *shm, ngx_str_t *key, +ngx_wa_shm_kv_get_locked(ngx_wa_shm_t *shm, ngx_str_t *key, uint32_t *key_hash, ngx_str_t **value_out, uint32_t *cas) { - ngx_wasm_shm_kv_t *kv = ngx_wasm_shm_get_kv(shm); - ngx_wasm_shm_kv_node_t *n; + ngx_wa_shm_kv_t *kv = ngx_wa_shm_get_kv(shm); + ngx_wa_shm_kv_node_t *n; if (key_hash) { - n = ngx_wasm_shm_rbtree_lookup(&kv->rbtree, *key_hash); + n = ngx_wa_shm_rbtree_lookup(&kv->rbtree, *key_hash); } else { - n = ngx_wasm_shm_rbtree_lookup(&kv->rbtree, - ngx_crc32_long(key->data, key->len)); + n = ngx_wa_shm_rbtree_lookup(&kv->rbtree, + ngx_crc32_long(key->data, key->len)); } if (n == NULL) { @@ -180,12 +180,12 @@ ngx_wasm_shm_kv_get_locked(ngx_wasm_shm_t *shm, ngx_str_t *key, static ngx_int_t -queue_expire(ngx_wasm_shm_t *shm, ngx_queue_t *queue, ngx_queue_t *q) +queue_expire(ngx_wa_shm_t *shm, ngx_queue_t *queue, ngx_queue_t *q) { - ngx_wasm_shm_kv_node_t *node; - ngx_wasm_shm_kv_t *kv = ngx_wasm_shm_get_kv(shm); + ngx_wa_shm_kv_node_t *node; + ngx_wa_shm_kv_t *kv = ngx_wa_shm_get_kv(shm); - node = ngx_queue_data(q, ngx_wasm_shm_kv_node_t, queue); + node = ngx_queue_data(q, ngx_wa_shm_kv_node_t, queue); ngx_queue_remove(q); @@ -198,12 +198,12 @@ queue_expire(ngx_wasm_shm_t *shm, ngx_queue_t *queue, ngx_queue_t *q) static ngx_int_t -slru_expire(ngx_wasm_shm_t *shm, size_t size) +slru_expire(ngx_wa_shm_t *shm, size_t size) { - ngx_int_t i; - ngx_uint_t n, start; - ngx_queue_t *q, *queue; - ngx_wasm_shm_kv_t *kv = ngx_wasm_shm_get_kv(shm); + ngx_int_t i; + ngx_uint_t n, start; + ngx_queue_t *q, *queue; + ngx_wa_shm_kv_t *kv = ngx_wa_shm_get_kv(shm); n = NGX_WASM_SLRU_NQUEUES(shm->shpool); start = slru_index_for_size(shm, size); @@ -235,10 +235,10 @@ slru_expire(ngx_wasm_shm_t *shm, size_t size) static ngx_int_t -lru_expire(ngx_wasm_shm_t *shm) +lru_expire(ngx_wa_shm_t *shm) { - ngx_wasm_shm_kv_t *kv = ngx_wasm_shm_get_kv(shm); - ngx_queue_t *q, *lru_queue = &kv->eviction.lru_queue; + ngx_wa_shm_kv_t *kv = ngx_wa_shm_get_kv(shm); + ngx_queue_t *q, *lru_queue = &kv->eviction.lru_queue; q = ngx_queue_last(lru_queue); if (q == ngx_queue_sentinel(lru_queue)) { @@ -250,7 +250,7 @@ lru_expire(ngx_wasm_shm_t *shm) static ngx_inline void -node_queue_remove(ngx_wasm_shm_t *shm, ngx_wasm_shm_kv_node_t *n) +node_queue_remove(ngx_wa_shm_t *shm, ngx_wa_shm_kv_node_t *n) { if (shm->eviction == NGX_WASM_SHM_EVICTION_LRU || shm->eviction == NGX_WASM_SHM_EVICTION_SLRU) @@ -261,16 +261,16 @@ node_queue_remove(ngx_wasm_shm_t *shm, ngx_wasm_shm_kv_node_t *n) ngx_int_t -ngx_wasm_shm_kv_set_locked(ngx_wasm_shm_t *shm, ngx_str_t *key, +ngx_wa_shm_kv_set_locked(ngx_wa_shm_t *shm, ngx_str_t *key, ngx_str_t *value, uint32_t cas, ngx_int_t *written) { - size_t size; - uint32_t key_hash = ngx_crc32_long(key->data, key->len); - ngx_wasm_shm_kv_t *kv = ngx_wasm_shm_get_kv(shm); - ngx_wasm_shm_kv_node_t *n, *old; + size_t size; + uint32_t key_hash = ngx_crc32_long(key->data, key->len); + ngx_wa_shm_kv_t *kv = ngx_wa_shm_get_kv(shm); + ngx_wa_shm_kv_node_t *n, *old; old = NULL; - n = ngx_wasm_shm_rbtree_lookup(&kv->rbtree, key_hash); + n = ngx_wa_shm_rbtree_lookup(&kv->rbtree, key_hash); if (cas != (n == NULL ? 0 : n->cas)) { *written = 0; @@ -303,7 +303,7 @@ ngx_wasm_shm_kv_set_locked(ngx_wasm_shm_t *shm, ngx_str_t *key, } if (n == NULL) { - size = sizeof(ngx_wasm_shm_kv_node_t) + key->len + value->len; + size = sizeof(ngx_wa_shm_kv_node_t) + key->len + value->len; for ( ;; ) { n = ngx_slab_calloc_locked(shm->shpool, size); @@ -331,7 +331,7 @@ ngx_wasm_shm_kv_set_locked(ngx_wasm_shm_t *shm, ngx_str_t *key, return NGX_ERROR; } - n->key.str.data = (u_char *) n + sizeof(ngx_wasm_shm_kv_node_t); + n->key.str.data = (u_char *) n + sizeof(ngx_wa_shm_kv_node_t); n->key.str.len = key->len; n->key.node.key = ngx_crc32_long(key->data, key->len); n->value.data = n->key.str.data + key->len; @@ -380,7 +380,7 @@ ngx_wasm_shm_kv_set_locked(ngx_wasm_shm_t *shm, ngx_str_t *key, ngx_int_t -ngx_wasm_shm_kv_resolve_key(ngx_str_t *key, ngx_wasm_shm_kv_key_t *out) +ngx_wa_shm_kv_resolve_key(ngx_str_t *key, ngx_wa_shm_kv_key_t *out) { size_t i; ngx_int_t zone_idx = NGX_WASM_SHM_INDEX_NOTFOUND; @@ -389,7 +389,7 @@ ngx_wasm_shm_kv_resolve_key(ngx_str_t *key, ngx_wasm_shm_kv_key_t *out) ngx_cycle_t *cycle = (ngx_cycle_t *) ngx_cycle; static const ngx_str_t default_namespace = ngx_string("*"); - ngx_memzero(out, sizeof(ngx_wasm_shm_kv_key_t)); + ngx_memzero(out, sizeof(ngx_wa_shm_kv_key_t)); zone_array = ngx_wasmx_shms(cycle); if (zone_array == NULL) { @@ -407,7 +407,7 @@ ngx_wasm_shm_kv_resolve_key(ngx_str_t *key, ngx_wasm_shm_kv_key_t *out) } if (out->namespace.len) { - zone_idx = ngx_wasm_shm_lookup_index(&out->namespace); + zone_idx = ngx_wa_shm_lookup_index(&out->namespace); } if (zone_idx == NGX_WASM_SHM_INDEX_NOTFOUND) { @@ -419,13 +419,13 @@ ngx_wasm_shm_kv_resolve_key(ngx_str_t *key, ngx_wasm_shm_kv_key_t *out) out->namespace.len = default_namespace.len; out->key = *key; - zone_idx = ngx_wasm_shm_lookup_index(&out->namespace); + zone_idx = ngx_wa_shm_lookup_index(&out->namespace); if (zone_idx == NGX_WASM_SHM_INDEX_NOTFOUND) { return NGX_DECLINED; } } - zone = ((ngx_wasm_shm_mapping_t *) zone_array->elts)[zone_idx].zone; + zone = ((ngx_wa_shm_mapping_t *) zone_array->elts)[zone_idx].zone; out->zone = zone; out->shm = zone->data; diff --git a/src/common/shm/ngx_wasm_shm_kv.h b/src/common/shm/ngx_wa_shm_kv.h similarity index 61% rename from src/common/shm/ngx_wasm_shm_kv.h rename to src/common/shm/ngx_wa_shm_kv.h index d711b6b57..45ad9dc8d 100644 --- a/src/common/shm/ngx_wasm_shm_kv.h +++ b/src/common/shm/ngx_wa_shm_kv.h @@ -2,7 +2,7 @@ #define _NGX_WASM_SHM_KV_H_INCLUDED_ -#include +#include typedef struct { @@ -12,15 +12,15 @@ typedef struct { ngx_queue_t lru_queue; ngx_queue_t slru_queues[0]; } eviction; -} ngx_wasm_shm_kv_t; +} ngx_wa_shm_kv_t; typedef struct { ngx_str_t namespace; ngx_str_t key; ngx_shm_zone_t *zone; - ngx_wasm_shm_t *shm; -} ngx_wasm_shm_kv_key_t; + ngx_wa_shm_t *shm; +} ngx_wa_shm_kv_key_t; typedef struct { @@ -28,18 +28,18 @@ typedef struct { ngx_str_t value; uint32_t cas; ngx_queue_t queue; -} ngx_wasm_shm_kv_node_t; +} ngx_wa_shm_kv_node_t; -ngx_wasm_shm_kv_t * ngx_wasm_shm_get_kv(ngx_wasm_shm_t *shm); +ngx_wa_shm_kv_t * ngx_wa_shm_get_kv(ngx_wa_shm_t *shm); -ngx_int_t ngx_wasm_shm_kv_init(ngx_wasm_shm_t *shm); -ngx_int_t ngx_wasm_shm_kv_get_locked(ngx_wasm_shm_t *shm, +ngx_int_t ngx_wa_shm_kv_init(ngx_wa_shm_t *shm); +ngx_int_t ngx_wa_shm_kv_get_locked(ngx_wa_shm_t *shm, ngx_str_t *key, uint32_t *key_hash, ngx_str_t **value_out, uint32_t *cas); -ngx_int_t ngx_wasm_shm_kv_set_locked(ngx_wasm_shm_t *shm, +ngx_int_t ngx_wa_shm_kv_set_locked(ngx_wa_shm_t *shm, ngx_str_t *key, ngx_str_t *value, uint32_t cas, ngx_int_t *written); -ngx_int_t ngx_wasm_shm_kv_resolve_key(ngx_str_t *key, - ngx_wasm_shm_kv_key_t *out); +ngx_int_t ngx_wa_shm_kv_resolve_key(ngx_str_t *key, + ngx_wa_shm_kv_key_t *out); #endif /* _NGX_WASM_SHM_KV_H_INCLUDED_ */ diff --git a/src/common/shm/ngx_wasm_shm_queue.c b/src/common/shm/ngx_wa_shm_queue.c similarity index 79% rename from src/common/shm/ngx_wasm_shm_queue.c rename to src/common/shm/ngx_wa_shm_queue.c index 6471d5ab7..6435a578a 100644 --- a/src/common/shm/ngx_wasm_shm_queue.c +++ b/src/common/shm/ngx_wa_shm_queue.c @@ -4,7 +4,7 @@ #include "ddebug.h" #include -#include +#include typedef struct { @@ -13,11 +13,11 @@ typedef struct { ngx_uint_t push_ptr; ngx_uint_t pop_ptr; ngx_uint_t rising_occupancy; -} ngx_wasm_shm_queue_t; +} ngx_wa_shm_queue_t; -static ngx_inline ngx_wasm_shm_queue_t * -ngx_wasm_shm_get_queue(ngx_wasm_shm_t *shm) +static ngx_inline ngx_wa_shm_queue_t * +ngx_wa_shm_get_queue(ngx_wa_shm_t *shm) { ngx_wa_assert(shm->type == NGX_WASM_SHM_TYPE_QUEUE); return shm->data; @@ -25,14 +25,14 @@ ngx_wasm_shm_get_queue(ngx_wasm_shm_t *shm) static ngx_inline size_t -queue_capacity(ngx_wasm_shm_queue_t *queue) +queue_capacity(ngx_wa_shm_queue_t *queue) { return queue->buffer_end - queue->buffer; } static ngx_inline size_t -queue_occupancy(ngx_wasm_shm_queue_t *queue) +queue_occupancy(ngx_wa_shm_queue_t *queue) { if (queue->push_ptr > queue->pop_ptr) { return queue->push_ptr - queue->pop_ptr; @@ -47,7 +47,7 @@ queue_occupancy(ngx_wasm_shm_queue_t *queue) static ngx_inline void -inc_ptr(ngx_wasm_shm_queue_t *queue, ngx_uint_t *ptr, ngx_uint_t n) +inc_ptr(ngx_wa_shm_queue_t *queue, ngx_uint_t *ptr, ngx_uint_t n) { ngx_uint_t new_ptr = *ptr + n; ngx_uint_t cap = queue_capacity(queue); @@ -62,7 +62,7 @@ inc_ptr(ngx_wasm_shm_queue_t *queue, ngx_uint_t *ptr, ngx_uint_t n) static ngx_inline void -circular_write(ngx_log_t *log, ngx_wasm_shm_queue_t *queue, +circular_write(ngx_log_t *log, ngx_wa_shm_queue_t *queue, ngx_uint_t ptr, void *data, ngx_uint_t data_size) { ngx_uint_t cap = queue_capacity(queue); @@ -89,7 +89,7 @@ circular_write(ngx_log_t *log, ngx_wasm_shm_queue_t *queue, static ngx_inline void -circular_read(ngx_log_t *log, ngx_wasm_shm_queue_t *queue, +circular_read(ngx_log_t *log, ngx_wa_shm_queue_t *queue, ngx_uint_t ptr, void *data_out, ngx_uint_t data_size) { ngx_uint_t cap = queue_capacity(queue); @@ -114,7 +114,7 @@ circular_read(ngx_log_t *log, ngx_wasm_shm_queue_t *queue, static ngx_inline void -check_queue_invariance(ngx_wasm_shm_queue_t *queue) +check_queue_invariance(ngx_wa_shm_queue_t *queue) { #if (NGX_DEBUG) ngx_uint_t cap = queue_capacity(queue); @@ -126,13 +126,13 @@ check_queue_invariance(ngx_wasm_shm_queue_t *queue) ngx_int_t -ngx_wasm_shm_queue_init(ngx_wasm_shm_t *shm) +ngx_wa_shm_queue_init(ngx_wa_shm_t *shm) { - ngx_uint_t buffer_size; - ngx_uint_t reserved_size = ngx_pagesize; - ngx_wasm_shm_queue_t *queue; + ngx_uint_t buffer_size; + ngx_uint_t reserved_size = ngx_pagesize; + ngx_wa_shm_queue_t *queue; - queue = ngx_slab_calloc(shm->shpool, sizeof(ngx_wasm_shm_queue_t)); + queue = ngx_slab_calloc(shm->shpool, sizeof(ngx_wa_shm_queue_t)); if (queue == NULL) { dd("failed allocating queue structure"); return NGX_ERROR; @@ -162,11 +162,11 @@ ngx_wasm_shm_queue_init(ngx_wasm_shm_t *shm) ngx_int_t -ngx_wasm_shm_queue_push_locked(ngx_wasm_shm_t *shm, ngx_str_t *data) +ngx_wa_shm_queue_push_locked(ngx_wa_shm_t *shm, ngx_str_t *data) { - uint32_t len = (uint32_t) data->len; - ngx_uint_t entry_size = sizeof(uint32_t) + data->len; - ngx_wasm_shm_queue_t *queue = ngx_wasm_shm_get_queue(shm); + uint32_t len = (uint32_t) data->len; + ngx_uint_t entry_size = sizeof(uint32_t) + data->len; + ngx_wa_shm_queue_t *queue = ngx_wa_shm_get_queue(shm); /* queue full? */ @@ -191,12 +191,12 @@ ngx_wasm_shm_queue_push_locked(ngx_wasm_shm_t *shm, ngx_str_t *data) ngx_int_t -ngx_wasm_shm_queue_pop_locked(ngx_wasm_shm_t *shm, ngx_str_t *data_out, - ngx_wasm_shm_queue_alloc_pt alloc, void *alloc_ctx) +ngx_wa_shm_queue_pop_locked(ngx_wa_shm_t *shm, ngx_str_t *data_out, + ngx_wa_shm_queue_alloc_pt alloc, void *alloc_ctx) { - uint32_t len; - void *buf = NULL; - ngx_wasm_shm_queue_t *queue = ngx_wasm_shm_get_queue(shm); + uint32_t len; + void *buf = NULL; + ngx_wa_shm_queue_t *queue = ngx_wa_shm_get_queue(shm); /* queue empty? */ @@ -234,9 +234,9 @@ ngx_wasm_shm_queue_pop_locked(ngx_wasm_shm_t *shm, ngx_str_t *data_out, ngx_int_t -ngx_wasm_shm_queue_resolve(ngx_log_t *log, uint32_t token, ngx_shm_zone_t **out) +ngx_wa_shm_queue_resolve(ngx_log_t *log, uint32_t token, ngx_shm_zone_t **out) { - ngx_wasm_shm_t *shm; + ngx_wa_shm_t *shm; ngx_shm_zone_t *zone; ngx_array_t *zone_array; ngx_cycle_t *cycle = (ngx_cycle_t *) ngx_cycle; @@ -250,7 +250,7 @@ ngx_wasm_shm_queue_resolve(ngx_log_t *log, uint32_t token, ngx_shm_zone_t **out) return NGX_DECLINED; } - zone = ((ngx_wasm_shm_mapping_t *) + zone = ((ngx_wa_shm_mapping_t *) zone_array->elts)[token].zone; shm = zone->data; diff --git a/src/common/shm/ngx_wa_shm_queue.h b/src/common/shm/ngx_wa_shm_queue.h new file mode 100644 index 000000000..37b862eb9 --- /dev/null +++ b/src/common/shm/ngx_wa_shm_queue.h @@ -0,0 +1,19 @@ +#ifndef _NGX_WASM_SHM_QUEUE_H_INCLUDED_ +#define _NGX_WASM_SHM_QUEUE_H_INCLUDED_ + + +#include + + +typedef void *(*ngx_wa_shm_queue_alloc_pt)(size_t size, void *alloc_ctx); + + +ngx_int_t ngx_wa_shm_queue_init(ngx_wa_shm_t *shm); +ngx_int_t ngx_wa_shm_queue_push_locked(ngx_wa_shm_t *shm, ngx_str_t *data); +ngx_int_t ngx_wa_shm_queue_pop_locked(ngx_wa_shm_t *shm, + ngx_str_t *data_out, ngx_wa_shm_queue_alloc_pt alloc, void *alloc_ctx); +ngx_int_t ngx_wa_shm_queue_resolve(ngx_log_t *log, uint32_t token, + ngx_shm_zone_t **out); + + +#endif /* _NGX_WASM_SHM_QUEUE_H_INCLUDED_ */ diff --git a/src/common/shm/ngx_wasm_shm_queue.h b/src/common/shm/ngx_wasm_shm_queue.h deleted file mode 100644 index a1d3238d7..000000000 --- a/src/common/shm/ngx_wasm_shm_queue.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _NGX_WASM_SHM_QUEUE_H_INCLUDED_ -#define _NGX_WASM_SHM_QUEUE_H_INCLUDED_ - - -#include - - -typedef void *(*ngx_wasm_shm_queue_alloc_pt)(size_t size, void *alloc_ctx); - - -ngx_int_t ngx_wasm_shm_queue_init(ngx_wasm_shm_t *shm); -ngx_int_t ngx_wasm_shm_queue_push_locked(ngx_wasm_shm_t *shm, ngx_str_t *data); -ngx_int_t ngx_wasm_shm_queue_pop_locked(ngx_wasm_shm_t *shm, - ngx_str_t *data_out, ngx_wasm_shm_queue_alloc_pt alloc, void *alloc_ctx); -ngx_int_t ngx_wasm_shm_queue_resolve(ngx_log_t *log, uint32_t token, - ngx_shm_zone_t **out); - - -#endif /* _NGX_WASM_SHM_QUEUE_H_INCLUDED_ */ diff --git a/src/ngx_wasmx.c b/src/ngx_wasmx.c index 489a86afd..481608c90 100644 --- a/src/ngx_wasmx.c +++ b/src/ngx_wasmx.c @@ -114,7 +114,7 @@ ngx_wasmx_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf, #endif if (ngx_array_init(&wacf->shms, cf->pool, - 1, sizeof(ngx_wasm_shm_mapping_t)) + 1, sizeof(ngx_wa_shm_mapping_t)) != NGX_OK) { /* diff --git a/src/ngx_wasmx.h b/src/ngx_wasmx.h index 7472b17b9..2abe681b0 100644 --- a/src/ngx_wasmx.h +++ b/src/ngx_wasmx.h @@ -3,7 +3,7 @@ #include -#include +#include #include @@ -39,7 +39,7 @@ typedef struct { #ifdef NGX_WA_IPC void **ipc_confs; #endif - ngx_array_t shms; /* ngx_wasm_shm_mapping_t */ + ngx_array_t shms; /* ngx_wa_shm_mapping_t */ ngx_wa_metrics_t *metrics; } ngx_wa_conf_t; diff --git a/src/wasm/ngx_wasm_core_module.c b/src/wasm/ngx_wasm_core_module.c index bf8e2bbb8..8ebf37355 100644 --- a/src/wasm/ngx_wasm_core_module.c +++ b/src/wasm/ngx_wasm_core_module.c @@ -4,7 +4,7 @@ #include "ddebug.h" #include -#include +#include #include @@ -459,7 +459,7 @@ ngx_wasm_core_init(ngx_cycle_t *cycle) return NGX_ERROR; } - if (ngx_wasm_shm_init(cycle) != NGX_OK) { + if (ngx_wa_shm_init(cycle) != NGX_OK) { return NGX_ERROR; } @@ -488,7 +488,7 @@ ngx_wasm_core_init_process(ngx_cycle_t *cycle) return NGX_ERROR; } - if (ngx_wasm_shm_init_process(cycle) != NGX_OK) { + if (ngx_wa_shm_init_process(cycle) != NGX_OK) { return NGX_ERROR; } diff --git a/src/wasm/ngx_wasm_directives.c b/src/wasm/ngx_wasm_directives.c index 8c7a68866..afd8bb07b 100644 --- a/src/wasm/ngx_wasm_directives.c +++ b/src/wasm/ngx_wasm_directives.c @@ -163,15 +163,15 @@ validate_shm_size(ngx_conf_t *cf, ssize_t size, ngx_str_t *value) static char * ngx_wasm_core_shm_generic_directive(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf, ngx_wasm_shm_type_e type) + void *conf, ngx_wa_shm_type_e type) { - size_t i; - ssize_t size; - ngx_str_t *value, *name, *arg3; - ngx_array_t *shms = ngx_wasmx_shms(cf->cycle); - ngx_wasm_shm_mapping_t *mapping; - ngx_wasm_shm_t *shm; - ngx_wasm_shm_eviction_e eviction; + size_t i; + ssize_t size; + ngx_str_t *value, *name, *arg3; + ngx_array_t *shms = ngx_wasmx_shms(cf->cycle); + ngx_wa_shm_mapping_t *mapping; + ngx_wa_shm_t *shm; + ngx_wa_shm_eviction_e eviction; value = cf->args->elts; name = &value[1]; @@ -213,7 +213,7 @@ ngx_wasm_core_shm_generic_directive(ngx_conf_t *cf, ngx_command_t *cmd, } } - shm = ngx_pcalloc(cf->pool, sizeof(ngx_wasm_shm_t)); + shm = ngx_pcalloc(cf->pool, sizeof(ngx_wa_shm_t)); if (shm == NULL) { return NGX_CONF_ERROR; } @@ -246,7 +246,7 @@ ngx_wasm_core_shm_generic_directive(ngx_conf_t *cf, ngx_command_t *cmd, return NGX_CONF_ERROR; } - mapping->zone->init = ngx_wasm_shm_init_zone; + mapping->zone->init = ngx_wa_shm_init_zone; mapping->zone->data = shm; mapping->zone->noreuse = 1; /* TODO: enable shm reuse (fix SIGHUP) */ diff --git a/t/04-openresty/ffi/shm/001-get_zones.t b/t/04-openresty/ffi/shm/001-get_zones.t index bd363165a..349389ed7 100644 --- a/t/04-openresty/ffi/shm/001-get_zones.t +++ b/t/04-openresty/ffi/shm/001-get_zones.t @@ -80,9 +80,9 @@ A call with a bad pointer is simply ignored. local C = ffi.C ffi.cdef [[ - typedef struct ngx_wasm_shm_t ngx_wasm_shm_t; + typedef struct ngx_wa_shm_t ngx_wa_shm_t; - typedef void (*ngx_wa_ffi_shm_get_zones_handler_pt)(ngx_wasm_shm_t *shm); + typedef void (*ngx_wa_ffi_shm_get_zones_handler_pt)(ngx_wa_shm_t *shm); int ngx_wa_ffi_shm_get_zones(ngx_wa_ffi_shm_get_zones_handler_pt handler); ]] diff --git a/t/04-openresty/ffi/shm/002-get_keys.t b/t/04-openresty/ffi/shm/002-get_keys.t index 970171dd9..61bc96f62 100644 --- a/t/04-openresty/ffi/shm/002-get_keys.t +++ b/t/04-openresty/ffi/shm/002-get_keys.t @@ -146,9 +146,9 @@ A call with a bad pointer is simply ignored. ffi.cdef [[ typedef uintptr_t ngx_uint_t; - typedef struct ngx_wasm_shm_t ngx_wasm_shm_t; + typedef struct ngx_wa_shm_t ngx_wa_shm_t; - int ngx_wa_ffi_shm_get_keys(ngx_wasm_shm_t *shm, + int ngx_wa_ffi_shm_get_keys(ngx_wa_shm_t *shm, ngx_uint_t n, ngx_str_t **keys); ]] diff --git a/t/04-openresty/ffi/shm/003-kv_get.t b/t/04-openresty/ffi/shm/003-kv_get.t index 38045b59c..9d33fd6e9 100644 --- a/t/04-openresty/ffi/shm/003-kv_get.t +++ b/t/04-openresty/ffi/shm/003-kv_get.t @@ -67,9 +67,9 @@ A call with a bad pointer is simply ignored. local C = ffi.C ffi.cdef [[ - typedef struct ngx_wasm_shm_t ngx_wasm_shm_t; + typedef struct ngx_wa_shm_t ngx_wa_shm_t; - int ngx_wa_ffi_shm_get_kv_value(ngx_wasm_shm_t *shm, + int ngx_wa_ffi_shm_get_kv_value(ngx_wa_shm_t *shm, ngx_str_t *k, ngx_str_t **v, uint32_t *cas);