[lttng-dev] [PATCH lttng-tools 1/4] Fix: validate number of subbuffers after tweaking properties

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Wed Apr 20 15:19:57 UTC 2016


There are properties that are tweaked by each of ust and kernel channel
create functions after a validation on the number of subbuffers for
overwrite channels. Move validation after those properties
modifications.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
---
 src/bin/lttng-sessiond/channel.c | 25 +++++++++++++++++++++++++
 src/bin/lttng-sessiond/cmd.c     | 10 ----------
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/src/bin/lttng-sessiond/channel.c b/src/bin/lttng-sessiond/channel.c
index 8ceb4e8..0119abf 100644
--- a/src/bin/lttng-sessiond/channel.c
+++ b/src/bin/lttng-sessiond/channel.c
@@ -179,6 +179,19 @@ error:
 	return ret;
 }
 
+static int channel_validate(struct lttng_channel *attr)
+{
+	/*
+	 * The ringbuffer (both in user space and kernel) behave badly
+	 * in overwrite mode and with less than 2 subbuf so block it
+	 * right away and send back an invalid attribute error.
+	 */
+	if (attr->attr.overwrite && attr->attr.num_subbuf < 2) {
+		return -1;
+	}
+	return 0;
+}
+
 /*
  * Create kernel channel of the kernel session and notify kernel thread.
  */
@@ -207,6 +220,12 @@ int channel_kernel_create(struct ltt_kernel_session *ksession,
 		attr->attr.output = LTTNG_EVENT_MMAP;
 	}
 
+	/* Validate common channel properties. */
+	if (channel_validate(attr) < 0) {
+		ret = LTTNG_ERR_INVALID;
+		goto error;
+	}
+
 	/* Channel not found, creating it */
 	ret = kernel_create_channel(ksession, attr);
 	if (ret < 0) {
@@ -305,6 +324,12 @@ int channel_ust_create(struct ltt_ust_session *usess,
 		attr->attr.output = LTTNG_EVENT_MMAP;
 	}
 
+	/* Validate common channel properties. */
+	if (channel_validate(attr) < 0) {
+		ret = LTTNG_ERR_INVALID;
+		goto error;
+	}
+
 	/*
 	 * Validate UST buffer size and number of buffers: must both be power of 2
 	 * and nonzero. We validate right here for UST, because applications will
diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c
index ba963ff..73942a6 100644
--- a/src/bin/lttng-sessiond/cmd.c
+++ b/src/bin/lttng-sessiond/cmd.c
@@ -1322,16 +1322,6 @@ int cmd_enable_channel(struct ltt_session *session,
 		attr->attr.switch_timer_interval = 0;
 	}
 
-	/*
-	 * The ringbuffer (both in user space and kernel) behave badly in overwrite
-	 * mode and with less than 2 subbuf so block it right away and send back an
-	 * invalid attribute error.
-	 */
-	if (attr->attr.overwrite && attr->attr.num_subbuf < 2) {
-		ret = LTTNG_ERR_INVALID;
-		goto error;
-	}
-
 	switch (domain->type) {
 	case LTTNG_DOMAIN_KERNEL:
 	{
-- 
2.1.4



More information about the lttng-dev mailing list