X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Flttng-ctl%2Frotate.c;h=f32c69be18d10bc07c0c8294ff808aee23f50333;hb=dbd512ea8aa5349849aeeccda6130aa9e28cf23c;hp=9ad32f962c035a90429bef225edc75919aa73b41;hpb=329f344308786acb81d8939eb8e1ad37307696c2;p=lttng-tools.git diff --git a/src/lib/lttng-ctl/rotate.c b/src/lib/lttng-ctl/rotate.c index 9ad32f962..f32c69be1 100644 --- a/src/lib/lttng-ctl/rotate.c +++ b/src/lib/lttng-ctl/rotate.c @@ -21,28 +21,18 @@ #include #include +#include #include #include #include #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)); } -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) { @@ -51,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, @@ -110,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) @@ -149,13 +93,45 @@ end: return status; } +void lttng_rotation_schedule_attr_set_size( + struct lttng_rotation_schedule_attr *attr, uint64_t size) +{ + attr->size = size; +} + +static +struct lttng_trace_archive_location * +create_trace_archive_location_from_get_info( + const struct lttng_rotation_get_info_return *info) +{ + struct lttng_trace_archive_location *location; + + switch (info->location_type) { + case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL: + location = lttng_trace_archive_location_local_create( + info->location.local.absolute_path); + break; + case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY: + location = lttng_trace_archive_location_relay_create( + info->location.relay.host, + info->location.relay.protocol, + info->location.relay.ports.control, + info->location.relay.ports.data, + info->location.relay.relative_path); + break; + default: + location = NULL; + break; + } + return location; +} + enum lttng_rotation_status lttng_rotation_handle_get_state( struct lttng_rotation_handle *rotation_handle, enum lttng_rotation_state *state) { enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK; struct lttng_rotation_get_info_return *info = NULL; - int ret; if (!rotation_handle || !state) { status = LTTNG_ROTATION_STATUS_INVALID; @@ -168,7 +144,7 @@ enum lttng_rotation_status lttng_rotation_handle_get_state( } *state = (enum lttng_rotation_state) info->status; - if (rotation_handle->archive_location.is_set || + if (rotation_handle->archive_location || *state != LTTNG_ROTATION_STATE_COMPLETED) { /* * The path is only provided by the sessiond once @@ -181,35 +157,32 @@ enum lttng_rotation_status lttng_rotation_handle_get_state( * Cache the location since the rotation may expire before the user * has a chance to query it. */ - ret = lttng_strncpy(rotation_handle->archive_location.path, - info->path, - sizeof(rotation_handle->archive_location.path)); - if (ret) { + rotation_handle->archive_location = + create_trace_archive_location_from_get_info(info); + if (!rotation_handle->archive_location) { status = LTTNG_ROTATION_STATUS_ERROR; goto end; } - rotation_handle->archive_location.is_set = true; end: free(info); return status; } -enum lttng_rotation_status lttng_rotation_handle_get_completed_archive_location( +enum lttng_rotation_status lttng_rotation_handle_get_archive_location( struct lttng_rotation_handle *rotation_handle, - const char **path) + const struct lttng_trace_archive_location **location) { - int ret; enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK; struct lttng_rotation_get_info_return *info = NULL; - if (!rotation_handle || !path) { + if (!rotation_handle || !location) { status = LTTNG_ROTATION_STATUS_INVALID; goto end; } /* Use the cached location we got from a previous query. */ - if (rotation_handle->archive_location.is_set) { - *path = rotation_handle->archive_location.path; + if (rotation_handle->archive_location) { + *location = rotation_handle->archive_location; goto end; } @@ -224,14 +197,12 @@ enum lttng_rotation_status lttng_rotation_handle_get_completed_archive_location( goto end; } - ret = lttng_strncpy(rotation_handle->archive_location.path, - info->path, - sizeof(rotation_handle->archive_location.path)); - if (ret) { + rotation_handle->archive_location = + create_trace_archive_location_from_get_info(info); + if (!rotation_handle->archive_location) { status = LTTNG_ROTATION_STATUS_ERROR; goto end; } - rotation_handle->archive_location.is_set = true; end: free(info); return status; @@ -240,17 +211,22 @@ end: void lttng_rotation_handle_destroy( struct lttng_rotation_handle *rotation_handle) { + if (!rotation_handle) { + return; + } + lttng_trace_archive_location_destroy(rotation_handle->archive_location); free(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; - 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; @@ -266,21 +242,30 @@ end: * * 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; + 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; - 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); @@ -295,7 +280,8 @@ int lttng_rotate_session(struct lttng_rotation_immediate_attr *attr, goto end; } - init_rotation_handle(*rotation_handle, rotate_return, attr); + init_rotation_handle(*rotation_handle, session_name, rotate_return, + attr); ret = 0; @@ -307,25 +293,30 @@ end: /* * 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; - 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; - 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; ret = lttng_ctl_ask_sessiond(&lsm, NULL); - end: return ret; } @@ -349,9 +340,7 @@ int lttng_rotation_schedule_get_timer_period(const char *session_name, } *rotate_timer = get_timer->rotate_timer; - ret = 0; - end: free(get_timer); return ret;