rotation-api: pass session name explicitly
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 1 Aug 2018 20:49:46 +0000 (16:49 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 1 Aug 2018 20:53:26 +0000 (16:53 -0400)
The session name is currently passed to the rotation API commands
through the attribute descriptors. However, the session name is
an attribute that is always required and passing it explicitly
allows users to perform immediate rotations without allocating
an immediate rotation attribute descriptor.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/rotate-internal.h
include/lttng/rotation.h
src/bin/lttng/commands/disable_rotation.c
src/bin/lttng/commands/enable_rotation.c
src/bin/lttng/commands/rotate.c
src/common/config/session-config.c
src/lib/lttng-ctl/rotate.c

index e359cd741050d7a860edacdf08a39d95c3df87a5..8d0823b7a8e42f05e5731fbc9dc58c54e344ce8a 100644 (file)
@@ -32,8 +32,6 @@
  * This is opaque to the public library.
  */
 struct lttng_rotation_immediate_attr {
  * This is opaque to the public library.
  */
 struct lttng_rotation_immediate_attr {
-       /* Session name to rotate. */
-       char session_name[LTTNG_NAME_MAX];
        /* For the rotate pending request. */
        uint64_t rotate_id;
 };
        /* For the rotate pending request. */
        uint64_t rotate_id;
 };
@@ -44,8 +42,6 @@ struct lttng_rotation_immediate_attr {
  * This is opaque to the public library.
  */
 struct lttng_rotation_schedule_attr {
  * This is opaque to the public library.
  */
 struct lttng_rotation_schedule_attr {
-       /* Session name to rotate. */
-       char session_name[LTTNG_NAME_MAX];
        /* > 0 if a timer is set. */
        uint64_t timer_us;
        /* > 0 if the session should rotate when it has written that many bytes. */
        /* > 0 if a timer is set. */
        uint64_t timer_us;
        /* > 0 if the session should rotate when it has written that many bytes. */
index dbc0183da7e856a26df927c454df439b2e5f3a37..6091a7b988078039f73d641a6329cd6045f21701 100644 (file)
@@ -88,25 +88,14 @@ struct lttng_rotation_schedule_attr;
 struct lttng_rotation_handle;
 
 /*
 struct lttng_rotation_handle;
 
 /*
- * Return a newly allocated immediate session rotation descriptor object or NULL
- * on error.
- */
-extern struct lttng_rotation_immediate_attr *
-lttng_rotation_immediate_attr_create(void);
-
-/*
- * Return a newly allocated scheduled rotate session descriptor object or NULL
+ * Return a newly allocated session rotation schedule descriptor object or NULL
  * on error.
  * on error.
+ *
+ * The rotation schedule may be expressed as a size or as a time period.
  */
 extern struct lttng_rotation_schedule_attr *
 lttng_rotation_schedule_attr_create(void);
 
  */
 extern struct lttng_rotation_schedule_attr *
 lttng_rotation_schedule_attr_create(void);
 
-/*
- * Destroy a given immediate session rotation descriptor object.
- */
-extern void lttng_rotation_immediate_attr_destroy(
-               struct lttng_rotation_immediate_attr *attr);
-
 /*
  * Destroy a given scheduled rotate session descriptor object.
  */
 /*
  * Destroy a given scheduled rotate session descriptor object.
  */
@@ -114,33 +103,13 @@ extern void lttng_rotation_schedule_attr_destroy(
                struct lttng_rotation_schedule_attr *attr);
 
 /*
                struct lttng_rotation_schedule_attr *attr);
 
 /*
- * Set the name of the session to rotate immediately.
- *
- * The session_name parameter is copied to the immediate session rotation
- * attributes.
- */
-extern enum lttng_rotation_status lttng_rotation_immediate_attr_set_session_name(
-               struct lttng_rotation_immediate_attr *attr,
-               const char *session_name);
-
-/*
- * Set the name of the session to rotate automatically.
- *
- * The session_name parameter is copied to the immediate session rotation
- * attributes.
- */
-extern enum lttng_rotation_status lttng_rotation_schedule_attr_set_session_name(
-               struct lttng_rotation_schedule_attr *attr,
-               const char *session_name);
-
-/*
- * Set the timer to periodically rotate the session (µs, -1ULL to disable).
+ * Set the timer to periodically rotate the session (in µs).
  */
 extern enum lttng_rotation_status lttng_rotation_schedule_attr_set_timer_period(
                struct lttng_rotation_schedule_attr *attr, uint64_t timer);
 
 /*
  */
 extern enum lttng_rotation_status lttng_rotation_schedule_attr_set_timer_period(
                struct lttng_rotation_schedule_attr *attr, uint64_t timer);
 
 /*
- * Set the size to rotate the session (bytes, -1ULL to disable).
+ * Set the size to rotate the session (in bytes).
  */
 void lttng_rotation_schedule_attr_set_size(
                struct lttng_rotation_schedule_attr *attr, uint64_t size);
  */
 void lttng_rotation_schedule_attr_set_size(
                struct lttng_rotation_schedule_attr *attr, uint64_t size);
@@ -179,22 +148,26 @@ extern void lttng_rotation_handle_destroy(
                struct lttng_rotation_handle *rotation_handle);
 
 /*
                struct lttng_rotation_handle *rotation_handle);
 
 /*
- * Rotate the output folder of the session
+ * Rotate the output folder of the session.
  *
  * On success, handle is allocated and can be used to monitor the progress
  * of the rotation with lttng_rotation_get_state(). The handle must be freed
  * by the caller with lttng_rotation_handle_destroy().
  *
  *
  * On success, handle is allocated and can be used to monitor the progress
  * of the rotation with lttng_rotation_get_state(). The handle must be freed
  * by the caller with lttng_rotation_handle_destroy().
  *
+ * Passing NULL as the immediate rotation attribute results in the default
+ * options being used.
+ *
  * Return 0 if the rotate action was successfully launched or a negative
  * LTTng error code on error.
  */
  * Return 0 if the rotate action was successfully launched or a negative
  * LTTng error code on error.
  */
-extern int lttng_rotate_session(struct lttng_rotation_immediate_attr *attr,
+extern int lttng_rotate_session(const char *session_name,
+               struct lttng_rotation_immediate_attr *attr,
                struct lttng_rotation_handle **rotation_handle);
 
 /*
                struct lttng_rotation_handle **rotation_handle);
 
 /*
- * Configure a session to rotate periodically or based on the size written.
+ * Configure a session to rotate according to a given schedule.
  */
  */
-extern int lttng_rotation_set_schedule(
+extern int lttng_rotation_set_schedule(const char *session_name,
                struct lttng_rotation_schedule_attr *attr);
 
 /*
                struct lttng_rotation_schedule_attr *attr);
 
 /*
index a4a97903017764f461c6da3f66c4d256c6c84064..b179e91ce33e8f91e94a3d741d9ef7a0a34e03ab 100644 (file)
@@ -77,11 +77,6 @@ static int setup_rotate(char *session_name, uint64_t timer, uint64_t size)
                }
        }
 
                }
        }
 
-       ret = lttng_rotation_schedule_attr_set_session_name(attr, session_name);
-       if (ret < 0) {
-               goto error;
-       }
-
        if (lttng_opt_mi) {
                ret = mi_lttng_writer_write_element_string(writer,
                                mi_lttng_element_session_name, session_name);
        if (lttng_opt_mi) {
                ret = mi_lttng_writer_write_element_string(writer,
                                mi_lttng_element_session_name, session_name);
@@ -99,7 +94,7 @@ static int setup_rotate(char *session_name, uint64_t timer, uint64_t size)
                MSG("Disabling rotation based on size on session %s", session_name);
        }
 
                MSG("Disabling rotation based on size on session %s", session_name);
        }
 
-       ret = lttng_rotation_set_schedule(attr);
+       ret = lttng_rotation_set_schedule(session_name, attr);
        if (ret) {
                ERR("%s", lttng_strerror(ret));
                if (lttng_opt_mi) {
        if (ret) {
                ERR("%s", lttng_strerror(ret));
                if (lttng_opt_mi) {
index 42aa45017d9b29b0eda022ccb5ace06b72399abf..81a55b24c8aaec4810cec9ce54bcbc1621d1a6ea 100644 (file)
@@ -69,11 +69,6 @@ static int setup_rotate(char *session_name, uint64_t timer, uint64_t size)
                goto error;
        }
 
                goto error;
        }
 
-       ret = lttng_rotation_schedule_attr_set_session_name(attr, session_name);
-       if (ret < 0) {
-               goto error;
-       }
-
        if (lttng_opt_mi) {
                /* Open rotation_schedule element */
                ret = mi_lttng_writer_open_element(writer,
        if (lttng_opt_mi) {
                /* Open rotation_schedule element */
                ret = mi_lttng_writer_open_element(writer,
@@ -114,7 +109,7 @@ static int setup_rotate(char *session_name, uint64_t timer, uint64_t size)
                }
        }
 
                }
        }
 
-       ret = lttng_rotation_set_schedule(attr);
+       ret = lttng_rotation_set_schedule(session_name, attr);
        if (ret) {
                ERR("%s", lttng_strerror(ret));
                if (lttng_opt_mi) {
        if (ret) {
                ERR("%s", lttng_strerror(ret));
                if (lttng_opt_mi) {
index 05e55bf3cc39d1eb8a138641061b33d69f886fc1..68bc59a33bf59037cd827a694637a530f5724c06 100644 (file)
@@ -209,25 +209,13 @@ end:
 static int rotate_tracing(char *session_name)
 {
        int ret;
 static int rotate_tracing(char *session_name)
 {
        int ret;
-       struct lttng_rotation_immediate_attr *attr = NULL;
        struct lttng_rotation_handle *handle = NULL;
        enum lttng_rotation_status rotation_status;
        enum lttng_rotation_state rotation_state = LTTNG_ROTATION_STATE_ONGOING;
 
        DBG("Rotating the output files of session %s", session_name);
 
        struct lttng_rotation_handle *handle = NULL;
        enum lttng_rotation_status rotation_status;
        enum lttng_rotation_state rotation_state = LTTNG_ROTATION_STATE_ONGOING;
 
        DBG("Rotating the output files of session %s", session_name);
 
-       attr = lttng_rotation_immediate_attr_create();
-       if (!attr) {
-               goto error;
-       }
-
-       ret = lttng_rotation_immediate_attr_set_session_name(attr, session_name);
-       if (ret < 0) {
-               ERR("Session name exceeds the maximal allowed length");
-               goto error;
-       }
-
-       ret = lttng_rotate_session(attr, &handle);
+       ret = lttng_rotate_session(session_name, NULL, &handle);
        if (ret < 0) {
                switch (-ret) {
                case LTTNG_ERR_SESSION_NOT_STARTED:
        if (ret < 0) {
                switch (-ret) {
                case LTTNG_ERR_SESSION_NOT_STARTED:
@@ -314,7 +302,6 @@ error:
        ret = CMD_ERROR;
 end:
        lttng_rotation_handle_destroy(handle);
        ret = CMD_ERROR;
 end:
        lttng_rotation_handle_destroy(handle);
-       lttng_rotation_immediate_attr_destroy(attr);
        return ret;
 }
 
        return ret;
 }
 
index 1b0db12cc8d448ea175192c28861a3a170edaed8..244fbd5cc5c05f85e0bcaef9a00c345e634f02dc 100644 (file)
@@ -2831,20 +2831,18 @@ domain_init_error:
        }
 
        if (rotation_timer_interval || rotation_size) {
        }
 
        if (rotation_timer_interval || rotation_size) {
-               struct lttng_rotation_schedule_attr *rotation_attr = lttng_rotation_schedule_attr_create();
+               struct lttng_rotation_schedule_attr *rotation_attr =
+                               lttng_rotation_schedule_attr_create();
 
                if (!rotation_attr) {
                        goto error;
                }
 
                if (!rotation_attr) {
                        goto error;
                }
-               ret = lttng_rotation_schedule_attr_set_session_name(rotation_attr, (const char *) name);
-               if (ret) {
-                       lttng_rotation_schedule_attr_destroy(rotation_attr);
-                       goto error;
-               }
                lttng_rotation_schedule_attr_set_timer_period(rotation_attr,
                                rotation_timer_interval);
                lttng_rotation_schedule_attr_set_timer_period(rotation_attr,
                                rotation_timer_interval);
-               lttng_rotation_schedule_attr_set_size(rotation_attr, rotation_size);
-               ret = lttng_rotation_set_schedule(rotation_attr);
+               lttng_rotation_schedule_attr_set_size(rotation_attr,
+                               rotation_size);
+               ret = lttng_rotation_set_schedule((const char *) name,
+                               rotation_attr);
                lttng_rotation_schedule_attr_destroy(rotation_attr);
                if (ret) {
                        goto error;
                lttng_rotation_schedule_attr_destroy(rotation_attr);
                if (ret) {
                        goto error;
index 26cc5f94f8fb10361d43a20c968da7a9a6db9500..f32c69be18d10bc07c0c8294ff808aee23f50333 100644 (file)
 
 #include "lttng-ctl-helper.h"
 
 
 #include "lttng-ctl-helper.h"
 
-struct lttng_rotation_immediate_attr *lttng_rotation_immediate_attr_create(void)
-{
-       return zmalloc(sizeof(struct lttng_rotation_immediate_attr));
-}
-
 struct lttng_rotation_schedule_attr *lttng_rotation_schedule_attr_create(void)
 {
        return zmalloc(sizeof(struct lttng_rotation_schedule_attr));
 }
 
 struct lttng_rotation_schedule_attr *lttng_rotation_schedule_attr_create(void)
 {
        return zmalloc(sizeof(struct lttng_rotation_schedule_attr));
 }
 
-void lttng_rotation_immediate_attr_destroy(
-               struct lttng_rotation_immediate_attr *attr)
-{
-       free(attr);
-}
-
 void lttng_rotation_schedule_attr_destroy(struct lttng_rotation_schedule_attr *attr)
 {
        if (attr) {
 void lttng_rotation_schedule_attr_destroy(struct lttng_rotation_schedule_attr *attr)
 {
        if (attr) {
@@ -52,29 +41,6 @@ void lttng_rotation_schedule_attr_destroy(struct lttng_rotation_schedule_attr *a
        }
 }
 
        }
 }
 
-enum lttng_rotation_status lttng_rotation_immediate_attr_set_session_name(
-               struct lttng_rotation_immediate_attr *attr,
-               const char *session_name)
-{
-       enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK;
-       int ret;
-
-       if (!attr || !session_name) {
-               status = LTTNG_ROTATION_STATUS_INVALID;
-               goto error;
-       }
-
-       ret = lttng_strncpy(attr->session_name, session_name,
-                       sizeof(attr->session_name));
-       if (ret) {
-               status = LTTNG_ROTATION_STATUS_INVALID;
-               goto error;
-       }
-
-error:
-       return status;
-}
-
 static
 enum lttng_rotation_status ask_rotation_info(
                struct lttng_rotation_handle *rotation_handle,
 static
 enum lttng_rotation_status ask_rotation_info(
                struct lttng_rotation_handle *rotation_handle,
@@ -111,29 +77,6 @@ end:
 
 }
 
 
 }
 
-enum lttng_rotation_status lttng_rotation_schedule_attr_set_session_name(
-               struct lttng_rotation_schedule_attr *attr,
-               const char *session_name)
-{
-       enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK;
-       int ret;
-
-       if (!attr || !session_name) {
-               status = LTTNG_ROTATION_STATUS_INVALID;
-               goto error;
-       }
-
-       ret = lttng_strncpy(attr->session_name, session_name,
-                       sizeof(attr->session_name));
-       if (ret) {
-               status = LTTNG_ROTATION_STATUS_INVALID;
-               goto error;
-       }
-
-error:
-       return status;
-}
-
 enum lttng_rotation_status lttng_rotation_schedule_attr_set_timer_period(
                struct lttng_rotation_schedule_attr *attr,
                uint64_t timer)
 enum lttng_rotation_status lttng_rotation_schedule_attr_set_timer_period(
                struct lttng_rotation_schedule_attr *attr,
                uint64_t timer)
@@ -277,12 +220,13 @@ void lttng_rotation_handle_destroy(
 
 static
 int init_rotation_handle(struct lttng_rotation_handle *rotation_handle,
 
 static
 int init_rotation_handle(struct lttng_rotation_handle *rotation_handle,
+               const char *session_name,
                struct lttng_rotate_session_return *rotate_return,
                struct lttng_rotation_immediate_attr *attr)
 {
        int ret;
 
                struct lttng_rotate_session_return *rotate_return,
                struct lttng_rotation_immediate_attr *attr)
 {
        int ret;
 
-       ret = lttng_strncpy(rotation_handle->session_name, attr->session_name,
+       ret = lttng_strncpy(rotation_handle->session_name, session_name,
                        sizeof(rotation_handle->session_name));
        if (ret) {
                goto end;
                        sizeof(rotation_handle->session_name));
        if (ret) {
                goto end;
@@ -298,21 +242,30 @@ end:
  *
  * Return 0 on success else a negative LTTng error code.
  */
  *
  * Return 0 on success else a negative LTTng error code.
  */
-int lttng_rotate_session(struct lttng_rotation_immediate_attr *attr,
+int lttng_rotate_session(const char *session_name,
+               struct lttng_rotation_immediate_attr *attr,
                struct lttng_rotation_handle **rotation_handle)
 {
        struct lttcomm_session_msg lsm;
        struct lttng_rotate_session_return *rotate_return = NULL;
        int ret;
                struct lttng_rotation_handle **rotation_handle)
 {
        struct lttcomm_session_msg lsm;
        struct lttng_rotate_session_return *rotate_return = NULL;
        int ret;
+       size_t session_name_len;
 
 
-       if (!attr) {
+       if (!session_name) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       session_name_len = strlen(session_name);
+       if (session_name_len >= sizeof(lsm.session.name) ||
+           session_name_len >= member_sizeof(struct lttng_rotation_handle, session_name)) {
                ret = -LTTNG_ERR_INVALID;
                goto end;
        }
 
        memset(&lsm, 0, sizeof(lsm));
        lsm.cmd_type = LTTNG_ROTATE_SESSION;
                ret = -LTTNG_ERR_INVALID;
                goto end;
        }
 
        memset(&lsm, 0, sizeof(lsm));
        lsm.cmd_type = LTTNG_ROTATE_SESSION;
-       lttng_ctl_copy_string(lsm.session.name, attr->session_name,
+       lttng_ctl_copy_string(lsm.session.name, session_name,
                        sizeof(lsm.session.name));
 
        ret = lttng_ctl_ask_sessiond(&lsm, (void **) &rotate_return);
                        sizeof(lsm.session.name));
 
        ret = lttng_ctl_ask_sessiond(&lsm, (void **) &rotate_return);
@@ -327,7 +280,8 @@ int lttng_rotate_session(struct lttng_rotation_immediate_attr *attr,
                goto end;
        }
 
                goto end;
        }
 
-       init_rotation_handle(*rotation_handle, rotate_return, attr);
+       init_rotation_handle(*rotation_handle, session_name, rotate_return,
+                       attr);
 
        ret = 0;
 
 
        ret = 0;
 
@@ -339,20 +293,25 @@ end:
 /*
  * Configure the automatic rotate parameters.
  */
 /*
  * Configure the automatic rotate parameters.
  */
-int lttng_rotation_set_schedule(
+int lttng_rotation_set_schedule(const char *session_name,
                struct lttng_rotation_schedule_attr *attr)
 {
        struct lttcomm_session_msg lsm;
        int ret;
 
                struct lttng_rotation_schedule_attr *attr)
 {
        struct lttcomm_session_msg lsm;
        int ret;
 
-       if (!attr) {
+       if (!attr || !session_name) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       if (strlen(session_name) >= sizeof(lsm.session.name)) {
                ret = -LTTNG_ERR_INVALID;
                goto end;
        }
 
        memset(&lsm, 0, sizeof(lsm));
        lsm.cmd_type = LTTNG_ROTATION_SET_SCHEDULE;
                ret = -LTTNG_ERR_INVALID;
                goto end;
        }
 
        memset(&lsm, 0, sizeof(lsm));
        lsm.cmd_type = LTTNG_ROTATION_SET_SCHEDULE;
-       lttng_ctl_copy_string(lsm.session.name, attr->session_name,
+       lttng_ctl_copy_string(lsm.session.name, session_name,
                        sizeof(lsm.session.name));
        lsm.u.rotate_setup.timer_us = attr->timer_us;
        lsm.u.rotate_setup.size = attr->size;
                        sizeof(lsm.session.name));
        lsm.u.rotate_setup.timer_us = attr->timer_us;
        lsm.u.rotate_setup.size = attr->size;
This page took 0.031037 seconds and 4 git commands to generate.