Re: [PATCH v11 21/28] tracing: Remove restriction on string position in hist trigger keys
From: Namhyung Kim
Date: Mon Nov 02 2015 - 09:41:13 EST
On Thu, Oct 22, 2015 at 01:14:25PM -0500, Tom Zanussi wrote:
> If we assume the maximum size for a string field, we don't have to
> worry about its position. Since we only allow two keys in a compound
> key and having more than one string key in a given compound key
> doesn't make much sense anyway, trading a bit of extra space instead
> of introducing an arbitrary restriction makes more sense.
>
> We also need to use the event field size for static strings when
> copying the contents, otherwise we get random garbage in the key.
>
> Also, cast string return values to avoid warnings on 32-bit compiles.
>
> Finally, rearrange the code without changing any functionality by
> moving the compound key updating code into a separate function.
>
> Signed-off-by: Tom Zanussi <tom.zanussi@xxxxxxxxxxxxxxx>
> Tested-by: Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx>
> ---
[SNIP]
> @@ -508,8 +508,8 @@ static int create_key_field(struct hist_trigger_data *hist_data,
> goto out;
> }
>
> - if (is_string_field(field)) /* should be last key field */
> - key_size = HIST_KEY_SIZE_MAX - key_offset;
> + if (is_string_field(field))
> + key_size = MAX_FILTER_STR_VAL;
> else
> key_size = field->size;
> }
> @@ -781,9 +781,36 @@ static void hist_trigger_elt_update(struct hist_trigger_data *hist_data,
> }
> }
>
> +static inline void add_to_key(char *compound_key, void *key,
> + struct hist_field *key_field, void *rec)
> +{
> + size_t size = key_field->size;
> +
> + if (key_field->flags & HIST_FIELD_STRING) {
> + struct ftrace_event_field *field;
> +
> + /* ensure NULL-termination */
> + size--;
No need to do it here since the size will be updated below.
> +
> + field = key_field->field;
> + if (field->filter_type == FILTER_DYN_STRING)
> + size = *(u32 *)(rec + field->offset) >> 16;
> + else if (field->filter_type == FILTER_PTR_STRING)
> + size = strlen(key);
> + else if (field->filter_type == FILTER_STATIC_STRING)
> + size = field->size;
> +
> + if (size > key_field->size - 1)
> + size = key_field->size - 1;
The comment above can be moved here though.
Thanks,
Namhyung
> + }
> +
> + memcpy(compound_key + key_field->offset, key, size);
> +}
> +
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/