Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
    npro  
 Modern all-safe Rust Network Protocol library supporting h1, h2, h3, ws, wt sans-IO and with socket IO + tls
git clone https://npro.rs/repo/npro
 
root / src / power / p-ws-server.c
Author[]Andy Green <andy@warmcat.com> 2025-09-21 05:43 UTC
Committer[]Andy Green <andy@warmcat.com> 2025-09-21 05:51 UTC
Tree8a42f513b8c2f6203f45b420f28dd5abe9c66ce5   Raw Patch
 
clean log handling
clean log handling
diff --git a/src/builder/b-comms.c b/src/builder/b-comms.c index c17470a..e8f8229 100644 --- a/src/builder/b-comms.c +++ b/src/builder/b-comms.c @@ -50,6 +50,27 @@ saib_m_rx(void *userobj, const uint8_t *buf, size_t len, int flags) return 0; } +unsigned int +saib_get_spm_log_count(struct sai_plat_server *spm) +{ + unsigned int spm_logs = 0; + + lws_start_foreach_dll(struct lws_dll2 *, d, builder.sai_plat_owner.head) { + sai_plat_t *p = lws_container_of(d, sai_plat_t, sai_plat_list); + + lws_start_foreach_dll(struct lws_dll2 *, d1, p->nspawn_owner.head) { + struct sai_nspawn *ns = lws_container_of(d1, struct sai_nspawn, list); + + if (ns->spm == spm && ns->chunk_cache.count) + spm_logs += ns->chunk_cache.count; + + } lws_end_foreach_dll(d1); + } lws_end_foreach_dll(d); + + return spm_logs; +} + + /* * We cover requested tx for any instance of a platform that can takes tasks * from the same server... it means just by coming here, no particular @@ -75,8 +96,8 @@ saib_m_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, * Are there some logs to dump? */ - if (spm->logs_in_flight) - goto send_logs; /* nothing to send */ + if (saib_get_spm_log_count(spm)) + goto send_logs; /* * Any build metrics to process? @@ -214,12 +235,13 @@ saib_m_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, } switch (spm->phase) { - case PHASE_BUILDING: case PHASE_IDLE: break; default: + // lwsl_notice("%s: ++++++++++++++++ updating with platform status\n", __func__); + /* * Update server with platform status */ @@ -236,8 +258,10 @@ saib_m_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, js = lws_struct_json_serialize_create(lsm_schema_map_plat, LWS_ARRAY_SIZE(lsm_schema_map_plat), 0, &builder.sai_plat_owner); - if (!js) + if (!js) { + lwsl_err("%s: ++++++++++++++++++ FAILED to serialize plat\n", __func__); return -1; + } n = (int)lws_struct_json_serialize(js, start, lws_ptr_diff_size_t(end, start), &w); @@ -250,7 +274,7 @@ saib_m_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, spm->phase = PHASE_IDLE; *flags = LWSSS_FLAG_SOM | LWSSS_FLAG_EOM; - if (spm->logs_in_flight) + if (saib_get_spm_log_count(spm)) return lws_ss_request_tx(spm->ss); return LWSSSSRET_OK; @@ -320,12 +344,8 @@ send_logs: spm->last_logging_nspawn = walk; - if (walk == star) { - lwsl_notice("%s: did not find logs: %d expected\n", - __func__, spm->logs_in_flight); - spm->logs_in_flight = 0; + if (walk == star) return 1; /* nothing to do */ - } if (!star) /* take first usable one as the starting point */ star = walk; @@ -378,9 +398,10 @@ send_logs: ns->chunk_cache_size -= sizeof(*chunk) + chunk->len; free(chunk); - spm->logs_in_flight--; - lwsl_debug("%s: spm logs_in_flight %d\n", __func__, - spm->logs_in_flight); + /* + * Here we're just looking at the log situation specifically with THIS ns, + * not for any ns that drains to this server + */ if (ns->finished_when_logs_drained && !ns->chunk_cache.count) { /* @@ -406,7 +427,7 @@ sendify: *flags = LWSSS_FLAG_SOM | LWSSS_FLAG_EOM; *len = (unsigned int)n; - if (spm->phase != PHASE_IDLE || spm->logs_in_flight) { + if (spm->phase != PHASE_IDLE || saib_get_spm_log_count(spm)) { r = lws_ss_request_tx(spm->ss); if (r) return r; diff --git a/src/builder/b-nspawn.c b/src/builder/b-nspawn.c index 98036a8..4e84ebf 100644 --- a/src/builder/b-nspawn.c +++ b/src/builder/b-nspawn.c @@ -69,7 +69,6 @@ saib_log_chunk_create(struct sai_nspawn *ns, void *buf, size_t len, int channel) ns->chunk_cache_size += sizeof(*chunk) + len; lws_dll2_add_head(&chunk->list, &ns->chunk_cache); - ns->spm->logs_in_flight++; return chunk; } @@ -318,11 +317,11 @@ skip: op->spawn = NULL; } - if (ns->spm) { - ns->spm->phase = PHASE_START_ATTACH; - if (lws_ss_request_tx(ns->spm->ss)) - lwsl_warn("%s: lws_ss_request_tx failed\n", __func__); - } +// if (ns->spm) { +// ns->spm->phase = PHASE_START_ATTACH; +// if (lws_ss_request_tx(ns->spm->ss)) +// lwsl_warn("%s: lws_ss_request_tx failed\n", __func__); +// } /* * add a final zero-length log with the retcode to the list of pending @@ -331,9 +330,8 @@ skip: saib_log_chunk_create(ns, NULL, 0, 2); - lwsl_notice("%s: finished, waiting to drain logs (this ns %d, spm in flight %d)\n", - __func__, ns->chunk_cache.count, - ns->spm ? ns->spm->logs_in_flight : -99); + lwsl_notice("%s: ns finished, waiting to drain %d logs\n", + __func__, ns->chunk_cache.count); /* * saib_task_grace(ns) sets ns->finished_when_logs_drained diff --git a/src/builder/b-task.c b/src/builder/b-task.c index 4a4c5cf..150c2c4 100644 --- a/src/builder/b-task.c +++ b/src/builder/b-task.c @@ -954,7 +954,6 @@ saib_ws_json_rx_builder(struct sai_plat_server *spm, const void *in, size_t len) lwsl_notice("%s: git_repo_url %s\n", __func__, ns->git_repo_url); lwsl_notice("%s: mountpoint %s\n", __func__, ns->fsm.mp); - spm->phase = PHASE_BUILDING; n = lws_snprintf(ns->inp, sizeof(ns->inp), "%s%c", builder.home, csep); diff --git a/src/common/include/private.h b/src/common/include/private.h index 39d1264..ee63fe2 100644 --- a/src/common/include/private.h +++ b/src/common/include/private.h @@ -395,7 +395,6 @@ typedef struct sai_plat_server { lws_dll2_t *last_logging_nspawn; struct sai_plat *last_logging_platform; - int logs_in_flight; int phase; int refcount; @@ -431,7 +430,6 @@ typedef struct sai_plat { lws_dll2_t sai_plat_list; lws_dll2_owner_t servers; /* list of sai_plat_server_ref_t */ - lws_dll2_owner_t chunk_cache; char peer_ip[48];
Page fetched 0s ago, creation time: 3ms (vhost etag hits: 0%, cache hits: 0%)