X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fsnapshot.c;h=960240b2c4a1144830109a97fe5389473c19fe43;hb=3afa94aeca5a0daae40fd7b6cc96b7e4c150c7d8;hp=9d1627fcb142f6858c2516ca54df3eb6c642fffe;hpb=b30fa1919a1e0274b8d4734acb8cb54753808609;p=lttng-tools.git diff --git a/src/common/snapshot.c b/src/common/snapshot.c index 9d1627fcb..960240b2c 100644 --- a/src/common/snapshot.c +++ b/src/common/snapshot.c @@ -5,16 +5,16 @@ * */ -#include -#include +#include +#include +#include +#include #include #include #include -#include #include -LTTNG_HIDDEN bool lttng_snapshot_output_validate(const struct lttng_snapshot_output *output) { bool valid = false; @@ -46,15 +46,14 @@ end: return valid; } -LTTNG_HIDDEN bool lttng_snapshot_output_is_equal( const struct lttng_snapshot_output *a, const struct lttng_snapshot_output *b) { bool equal = false; - assert(a); - assert(b); + LTTNG_ASSERT(a); + LTTNG_ASSERT(b); if (a->max_size != b->max_size) { goto end; @@ -89,10 +88,9 @@ struct lttng_snapshot_output_comm { char data_url[PATH_MAX]; } LTTNG_PACKED; -LTTNG_HIDDEN int lttng_snapshot_output_serialize( const struct lttng_snapshot_output *output, - struct lttng_dynamic_buffer *buf) + struct lttng_payload *payload) { struct lttng_snapshot_output_comm comm; int ret; @@ -105,17 +103,20 @@ int lttng_snapshot_output_serialize( goto end; } - ret = lttng_strncpy(comm.ctrl_url, output->ctrl_url, sizeof(comm.ctrl_url)); + ret = lttng_strncpy( + comm.ctrl_url, output->ctrl_url, sizeof(comm.ctrl_url)); if (ret) { goto end; } - ret = lttng_strncpy(comm.data_url, output->data_url, sizeof(comm.data_url)); + ret = lttng_strncpy( + comm.data_url, output->data_url, sizeof(comm.data_url)); if (ret) { goto end; } - ret = lttng_dynamic_buffer_append(buf, &comm, sizeof(comm)); + ret = lttng_dynamic_buffer_append( + &payload->buffer, &comm, sizeof(comm)); if (ret) { goto end; } @@ -124,16 +125,15 @@ end: return ret; } -LTTNG_HIDDEN -ssize_t lttng_snapshot_output_create_from_buffer( - const struct lttng_buffer_view *view, +ssize_t lttng_snapshot_output_create_from_payload( + struct lttng_payload_view *view, struct lttng_snapshot_output **output_p) { const struct lttng_snapshot_output_comm *comm; struct lttng_snapshot_output *output = NULL; int ret; - if (view->size != sizeof(*comm)) { + if (view->buffer.size != sizeof(*comm)) { ret = -1; goto end; } @@ -144,7 +144,7 @@ ssize_t lttng_snapshot_output_create_from_buffer( goto end; } - comm = (const struct lttng_snapshot_output_comm *) view->data; + comm = (typeof(comm)) view->buffer.data; output->id = comm->id; output->max_size = comm->max_size; @@ -154,12 +154,14 @@ ssize_t lttng_snapshot_output_create_from_buffer( goto end; } - ret = lttng_strncpy(output->ctrl_url, comm->ctrl_url, sizeof(output->ctrl_url)); + ret = lttng_strncpy(output->ctrl_url, comm->ctrl_url, + sizeof(output->ctrl_url)); if (ret) { goto end; } - ret = lttng_strncpy(output->data_url, comm->data_url, sizeof(output->data_url)); + ret = lttng_strncpy(output->data_url, comm->data_url, + sizeof(output->data_url)); if (ret) { goto end; } @@ -172,3 +174,79 @@ end: lttng_snapshot_output_destroy(output); return ret; } + +enum lttng_error_code lttng_snapshot_output_mi_serialize( + const struct lttng_snapshot_output *output, + struct mi_writer *writer) +{ + int ret; + enum lttng_error_code ret_code; + + LTTNG_ASSERT(output); + LTTNG_ASSERT(writer); + + /* Open output element. */ + ret = mi_lttng_writer_open_element(writer, + mi_lttng_element_action_snapshot_session_output); + if (ret) { + goto mi_error; + } + + /* Name. */ + if (strnlen(output->name, LTTNG_NAME_MAX) != 0) { + ret = mi_lttng_writer_write_element_string( + writer, config_element_name, output->name); + if (ret) { + goto mi_error; + } + } + + /* Control url (always present). */ + ret = mi_lttng_writer_write_element_string(writer, + mi_lttng_element_snapshot_ctrl_url, output->ctrl_url); + if (ret) { + goto mi_error; + } + + /* Data url (optional). */ + if (strnlen(output->data_url, PATH_MAX) != 0) { + ret = mi_lttng_writer_write_element_string(writer, + mi_lttng_element_snapshot_data_url, + output->data_url); + if (ret) { + goto mi_error; + } + } + + /* + * Maximum size in bytes of the snapshot meaning the total size of all + * streams combined. A value of 0 means unlimited. The default value is + * UINT64_MAX which also means unlimited in practice. + * + * The value is not serialized when it is set to either of those values + * to normalize them to '0'. + */ + if (output->max_size > 0 && output->max_size != UINT64_MAX) { + /* Total size of all stream combined. */ + ret = mi_lttng_writer_write_element_unsigned_int(writer, + mi_lttng_element_snapshot_max_size, + output->max_size); + if (ret) { + goto mi_error; + } + } + + /* Close output element. */ + ret = mi_lttng_writer_close_element(writer); + if (ret) { + goto mi_error; + } + + ret_code = LTTNG_OK; + goto end; + +mi_error: + ret_code = LTTNG_ERR_MI_IO_FAIL; +end: + return ret_code; +}