Willy, > I merged your 6 first ones. I slightly adjusted the last one because > it spewed a build warning: > > src/http_ana.c: In function 'http_process_request': > src/http_ana.c:806:15: warning: unused variable 'n' [-Wunused-variable] > > And it made me figure that all this simplified to a single line now. > This is great!
The single line merge would have happened in the missing 7th patch. I've rebased it, resolved the merge conflict you created and added back the `unlikely` that you dropped. The other change I made was using `b_putist` instead of my manual loop as suggested. It compiles and passes reg-tests, I did not verify that tracing works. Best regards Tim Düsterhus Apply with `git am --scissors` to automatically cut the commit message. -- >8 -- The `unique_id` member of `struct stream` now is a `struct ist`. --- include/proto/stream.h | 2 +- include/types/stream.h | 2 +- src/http_ana.c | 10 +++++----- src/http_fetch.c | 10 +++++----- src/log.c | 8 +++++--- src/stream.c | 35 ++++++++++++++++++++--------------- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/include/proto/stream.h b/include/proto/stream.h index e54ac60cc..69153df5d 100644 --- a/include/proto/stream.h +++ b/include/proto/stream.h @@ -66,7 +66,7 @@ void stream_shutdown(struct stream *stream, int why); void stream_dump(struct buffer *buf, const struct stream *s, const char *pfx, char eol); void stream_dump_and_crash(enum obj_type *obj, int rate); -int stream_generate_unique_id(struct stream *strm, struct list *format); +struct ist stream_generate_unique_id(struct stream *strm, struct list *format); void stream_process_counters(struct stream *s); void sess_change_server(struct stream *sess, struct server *newsrv); diff --git a/include/types/stream.h b/include/types/stream.h index 90819e66d..39a68557e 100644 --- a/include/types/stream.h +++ b/include/types/stream.h @@ -177,7 +177,7 @@ struct stream { int pcli_next_pid; /* next target PID to use for the CLI proxy */ int pcli_flags; /* flags for CLI proxy */ - char *unique_id; /* custom unique ID */ + struct ist unique_id; /* custom unique ID */ /* These two pointers are used to resume the execution of the rule lists. */ struct list *current_rule_list; /* this is used to store the current executed rule list. */ diff --git a/src/http_ana.c b/src/http_ana.c index 010b170a3..b9067dd0c 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -793,9 +793,9 @@ int http_process_request(struct stream *s, struct channel *req, int an_bit) * fetches only available in the HTTP request processing stage. */ if (!LIST_ISEMPTY(&sess->fe->format_unique_id)) { - int length; + struct ist unique_id = stream_generate_unique_id(s, &sess->fe->format_unique_id); - if ((length = stream_generate_unique_id(s, &sess->fe->format_unique_id)) < 0) { + if (!isttest(unique_id)) { if (!(s->flags & SF_ERR_MASK)) s->flags |= SF_ERR_RESOURCE; goto return_int_err; @@ -803,7 +803,7 @@ int http_process_request(struct stream *s, struct channel *req, int an_bit) /* send unique ID if a "unique-id-header" is defined */ if (isttest(sess->fe->header_unique_id) && - !http_add_header(htx, sess->fe->header_unique_id, ist2(s->unique_id, length))) + unlikely(!http_add_header(htx, sess->fe->header_unique_id, s->unique_id))) goto return_int_err; } @@ -5078,9 +5078,9 @@ void http_end_txn(struct stream *s) pool_free(pool_head_requri, txn->uri); pool_free(pool_head_capture, txn->cli_cookie); pool_free(pool_head_capture, txn->srv_cookie); - pool_free(pool_head_uniqueid, s->unique_id); + pool_free(pool_head_uniqueid, s->unique_id.ptr); - s->unique_id = NULL; + s->unique_id = IST_NULL; txn->uri = NULL; txn->srv_cookie = NULL; txn->cli_cookie = NULL; diff --git a/src/http_fetch.c b/src/http_fetch.c index 9113b5e49..9cfcee2ab 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -409,17 +409,17 @@ static int smp_fetch_stcode(const struct arg *args, struct sample *smp, const ch static int smp_fetch_uniqueid(const struct arg *args, struct sample *smp, const char *kw, void *private) { - int length; + struct ist unique_id; if (LIST_ISEMPTY(&smp->sess->fe->format_unique_id)) return 0; - length = stream_generate_unique_id(smp->strm, &smp->sess->fe->format_unique_id); - if (length < 0) + unique_id = stream_generate_unique_id(smp->strm, &smp->sess->fe->format_unique_id); + if (!isttest(unique_id)) return 0; - smp->data.u.str.area = smp->strm->unique_id; - smp->data.u.str.data = length; + smp->data.u.str.area = smp->strm->unique_id.ptr; + smp->data.u.str.data = smp->strm->unique_id.len; smp->data.type = SMP_T_STR; smp->flags = SMP_F_CONST; return 1; diff --git a/src/log.c b/src/log.c index b46605b8d..8f502ac7e 100644 --- a/src/log.c +++ b/src/log.c @@ -2927,8 +2927,10 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t case LOG_FMT_UNIQUEID: // %ID ret = NULL; - src = s ? s->unique_id : NULL; - ret = lf_text(tmplog, src, maxsize - (tmplog - dst), tmp); + if (s) + ret = lf_text_len(tmplog, s->unique_id.ptr, s->unique_id.len, maxsize - (tmplog - dst), tmp); + else + ret = lf_text_len(tmplog, NULL, 0, maxsize - (tmplog - dst), tmp); if (ret == NULL) goto out; tmplog = ret; @@ -2982,7 +2984,7 @@ void strm_log(struct stream *s) } /* if unique-id was not generated */ - if (!s->unique_id && !LIST_ISEMPTY(&sess->fe->format_unique_id)) { + if (!isttest(s->unique_id) && !LIST_ISEMPTY(&sess->fe->format_unique_id)) { stream_generate_unique_id(s, &sess->fe->format_unique_id); } diff --git a/src/stream.c b/src/stream.c index 331f24be7..7b63f1d31 100644 --- a/src/stream.c +++ b/src/stream.c @@ -170,8 +170,10 @@ static void strm_trace(enum trace_level level, uint64_t mask, const struct trace /* General info about the stream (htx/tcp, id...) */ chunk_appendf(&trace_buf, " : [%u,%s]", s->uniq_id, ((s->flags & SF_HTX) ? "HTX" : "TCP")); - if (s->unique_id) - chunk_appendf(&trace_buf, " id=%s", s->unique_id); + if (isttest(s->unique_id)) { + chunk_appendf(&trace_buf, " id="); + b_putist(&trace_buf, s->unique_id); + } /* Front and back stream-int state */ chunk_appendf(&trace_buf, " SI=(%s,%s)", @@ -399,7 +401,7 @@ struct stream *stream_new(struct session *sess, enum obj_type *origin) s->call_rate.curr_sec = s->call_rate.curr_ctr = s->call_rate.prev_ctr = 0; s->pcli_next_pid = 0; s->pcli_flags = 0; - s->unique_id = NULL; + s->unique_id = IST_NULL; if ((t = task_new(tid_bit)) == NULL) goto out_fail_alloc; @@ -605,8 +607,8 @@ static void stream_free(struct stream *s) offer_buffers(NULL, tasks_run_queue); } - pool_free(pool_head_uniqueid, s->unique_id); - s->unique_id = NULL; + pool_free(pool_head_uniqueid, s->unique_id.ptr); + s->unique_id = IST_NULL; hlua_ctx_destroy(s->hlua); s->hlua = NULL; @@ -2663,25 +2665,28 @@ void stream_dump_and_crash(enum obj_type *obj, int rate) } /* Generates a unique ID based on the given <format>, stores it in the given <strm> and - * returns the length of the ID. -1 is returned on memory allocation failure. + * returns the unique ID. + + * If this function fails to allocate memory IST_NULL is returned. * - * If an ID is already stored within the stream nothing happens and length of the stored - * ID is returned. + * If an ID is already stored within the stream nothing happens existing unique ID is + * returned. */ -int stream_generate_unique_id(struct stream *strm, struct list *format) +struct ist stream_generate_unique_id(struct stream *strm, struct list *format) { - if (strm->unique_id != NULL) { - return strlen(strm->unique_id); + if (isttest(strm->unique_id)) { + return strm->unique_id; } else { char *unique_id; + int length; if ((unique_id = pool_alloc(pool_head_uniqueid)) == NULL) - return -1; + return IST_NULL; - strm->unique_id = unique_id; - strm->unique_id[0] = 0; + length = build_logline(strm, unique_id, UNIQUEID_LEN, format); + strm->unique_id = ist2(unique_id, length); - return build_logline(strm, strm->unique_id, UNIQUEID_LEN, format); + return strm->unique_id; } } -- 2.25.1