2 * Copyright (C) 2020 Simon Marchi <simon.marchi@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #include <common/buffer-view.h>
9 #include <common/dynamic-buffer.h>
10 #include <common/snapshot.h>
11 #include <lttng/snapshot-internal.h>
12 #include <lttng/snapshot.h>
18 bool lttng_snapshot_output_validate(const struct lttng_snapshot_output
*output
)
24 * It is mandatory to have a ctrl_url. If there is only one output
25 * URL (in the net://, net6:// or file:// form), it will be in this
28 len
= lttng_strnlen(output
->ctrl_url
, sizeof(output
->ctrl_url
));
29 if (len
== 0 || len
>= sizeof(output
->ctrl_url
)) {
33 len
= lttng_strnlen(output
->data_url
, sizeof(output
->data_url
));
34 if (len
>= sizeof(output
->data_url
)) {
38 len
= lttng_strnlen(output
->name
, sizeof(output
->name
));
39 if (len
>= sizeof(output
->name
)) {
50 bool lttng_snapshot_output_is_equal(
51 const struct lttng_snapshot_output
*a
,
52 const struct lttng_snapshot_output
*b
)
59 if (a
->max_size
!= b
->max_size
) {
63 if (strcmp(a
->name
, b
->name
) != 0) {
67 if (strcmp(a
->ctrl_url
, b
->ctrl_url
) != 0) {
71 if (strcmp(a
->data_url
, b
->data_url
) != 0) {
82 * This is essentially the same as `struct lttng_snapshot_output`, but packed.
84 struct lttng_snapshot_output_comm
{
87 char name
[LTTNG_NAME_MAX
];
88 char ctrl_url
[PATH_MAX
];
89 char data_url
[PATH_MAX
];
93 int lttng_snapshot_output_serialize(
94 const struct lttng_snapshot_output
*output
,
95 struct lttng_dynamic_buffer
*buf
)
97 struct lttng_snapshot_output_comm comm
;
100 comm
.id
= output
->id
;
101 comm
.max_size
= output
->max_size
;
103 ret
= lttng_strncpy(comm
.name
, output
->name
, sizeof(comm
.name
));
108 ret
= lttng_strncpy(comm
.ctrl_url
, output
->ctrl_url
, sizeof(comm
.ctrl_url
));
113 ret
= lttng_strncpy(comm
.data_url
, output
->data_url
, sizeof(comm
.data_url
));
118 ret
= lttng_dynamic_buffer_append(buf
, &comm
, sizeof(comm
));
128 ssize_t
lttng_snapshot_output_create_from_buffer(
129 const struct lttng_buffer_view
*view
,
130 struct lttng_snapshot_output
**output_p
)
132 const struct lttng_snapshot_output_comm
*comm
;
133 struct lttng_snapshot_output
*output
= NULL
;
136 if (view
->size
!= sizeof(*comm
)) {
141 output
= lttng_snapshot_output_create();
147 comm
= (const struct lttng_snapshot_output_comm
*) view
->data
;
149 output
->id
= comm
->id
;
150 output
->max_size
= comm
->max_size
;
152 ret
= lttng_strncpy(output
->name
, comm
->name
, sizeof(output
->name
));
157 ret
= lttng_strncpy(output
->ctrl_url
, comm
->ctrl_url
, sizeof(output
->ctrl_url
));
162 ret
= lttng_strncpy(output
->data_url
, comm
->data_url
, sizeof(output
->data_url
));
172 lttng_snapshot_output_destroy(output
);