linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libtraceeval: Add traceeval_init_data_size()
@ 2023-09-27 13:09 Steven Rostedt
  2023-10-02 20:25 ` Ross Zwisler
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt @ 2023-09-27 13:09 UTC (permalink / raw)
  To: Linux Trace Devel; +Cc: Ross Zwisler, Stevie Alvarez

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

In the future, the traceeval_type and traceeval_data may need to include
more information and be expanded. If that happens, it will break backward
compatibility for older applications using the newer library.

To be able to handle backward compatibility in this situation, have the
traceeval_init() turn into traceeval_init_data_size() which takes the
sizeof struct traceeval_type and struct traceeval_data. Make
traceeval_init() into a macro that calls this function passing in the
sizeof(struct traceeval_type) and sizeof(struct traceeval_data). This way
if the sizes change for either one, the new code will know if the
application is using the new interface or the older one, and can
can keep the older one still functioning properly.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 include/traceeval-hist.h |  9 +++++++--
 src/eval-local.h         |  2 ++
 src/histograms.c         | 16 +++++++++++++---
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/include/traceeval-hist.h b/include/traceeval-hist.h
index 396054e14a6f..eefa48d5d772 100644
--- a/include/traceeval-hist.h
+++ b/include/traceeval-hist.h
@@ -171,8 +171,13 @@ struct traceeval;
 
 /* Histogram interfaces */
 
-struct traceeval *traceeval_init(struct traceeval_type *keys,
-				 struct traceeval_type *vals);
+#define traceeval_init(keys, vals) \
+	traceeval_init_data_size(keys, vals, sizeof(struct traceeval_type), \
+				 sizeof(struct traceeval_data))
+
+struct traceeval *traceeval_init_data_size(struct traceeval_type *keys,
+					   struct traceeval_type *vals,
+					   size_t sizeof_type, size_t sizeof_data);
 
 void traceeval_release(struct traceeval *teval);
 
diff --git a/src/eval-local.h b/src/eval-local.h
index 26b3c9b29929..f0917b6a45e9 100644
--- a/src/eval-local.h
+++ b/src/eval-local.h
@@ -69,6 +69,8 @@ struct traceeval {
 	size_t				nr_key_types;
 	size_t				nr_val_types;
 	size_t				update_counter;
+	size_t				sizeof_type;
+	size_t				sizeof_data;
 };
 
 struct traceeval_iterator {
diff --git a/src/histograms.c b/src/histograms.c
index 1d7002b66dac..24563423ab99 100644
--- a/src/histograms.c
+++ b/src/histograms.c
@@ -233,9 +233,11 @@ static int check_vals(struct traceeval_type *vals)
 }
 
 /*
- * traceeval_init - create a traceeval descriptor
+ * traceeval_init_data_size - create a traceeval descriptor
  * @keys: Defines the keys to differentiate traceeval entries
  * @vals: Defines values attached to entries differentiated by @keys.
+ * @sizeof_type: The size of struct traceeval_type
+ * @sizeof_data: The size of struct traceeval_data
  *
  * The @keys and @vals define how the traceeval instance will be populated.
  * The @keys will be used by traceeval_query() to find an instance within
@@ -259,10 +261,15 @@ static int check_vals(struct traceeval_type *vals)
  * @keys must be populated with at least one element that is not of type
  * TRACEEVAL_TYPE_NONE.
  *
+ * The @sizeof_type and @sizeof_data are used to handle backward compatibility
+ * in the event that items are added to them. All the existing functions
+ * will still need to work with the older sizes.
+ *
  * Returns the descriptor on success, or NULL on error.
  */
-struct traceeval *traceeval_init(struct traceeval_type *keys,
-				 struct traceeval_type *vals)
+struct traceeval *traceeval_init_data_size(struct traceeval_type *keys,
+					   struct traceeval_type *vals,
+					   size_t sizeof_type, size_t sizeof_data)
 {
 	struct traceeval *teval;
 	char *err_msg;
@@ -314,6 +321,9 @@ struct traceeval *traceeval_init(struct traceeval_type *keys,
 		goto fail_release;
 	}
 
+	teval->sizeof_type = sizeof_type;
+	teval->sizeof_data = sizeof_data;
+
 	return teval;
 
 fail_release:
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] libtraceeval: Add traceeval_init_data_size()
  2023-09-27 13:09 [PATCH] libtraceeval: Add traceeval_init_data_size() Steven Rostedt
@ 2023-10-02 20:25 ` Ross Zwisler
  0 siblings, 0 replies; 2+ messages in thread
From: Ross Zwisler @ 2023-10-02 20:25 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Linux Trace Devel, Stevie Alvarez

On Wed, Sep 27, 2023 at 09:09:04AM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> In the future, the traceeval_type and traceeval_data may need to include
> more information and be expanded. If that happens, it will break backward
> compatibility for older applications using the newer library.
> 
> To be able to handle backward compatibility in this situation, have the
> traceeval_init() turn into traceeval_init_data_size() which takes the
> sizeof struct traceeval_type and struct traceeval_data. Make
> traceeval_init() into a macro that calls this function passing in the
> sizeof(struct traceeval_type) and sizeof(struct traceeval_data). This way
> if the sizes change for either one, the new code will know if the
> application is using the new interface or the older one, and can
> can keep the older one still functioning properly.
> 
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Reviewed-by: Ross Zwisler <zwisler@google.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-02 20:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-27 13:09 [PATCH] libtraceeval: Add traceeval_init_data_size() Steven Rostedt
2023-10-02 20:25 ` Ross Zwisler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).