28364bbc75575508dc823c0ca6f819981bf66d0f
2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <urcu/uatomic.h>
24 #include <common/defaults.h>
29 * Return the atomically incremented value of next_output_id.
31 static inline unsigned long get_next_output_id(struct snapshot
*snapshot
)
33 return uatomic_add_return(&snapshot
->next_output_id
, 1);
37 * Initialized snapshot output with the given values.
39 * Return 0 on success or else a negative value.
41 static int output_init(uint64_t max_size
, const char *name
,
42 struct lttng_uri
*uris
, size_t nb_uri
,
43 struct consumer_output
*consumer
, struct snapshot_output
*output
,
44 struct snapshot
*snapshot
)
50 output
->max_size
= max_size
;
52 output
->id
= get_next_output_id(snapshot
);
54 lttng_ht_node_init_ulong(&output
->node
, (unsigned long) output
->id
);
56 if (name
&& name
[0] != '\0') {
57 strncpy(output
->name
, name
, sizeof(output
->name
));
59 /* Set default name. */
60 ret
= snprintf(output
->name
, sizeof(output
->name
), "%s-%" PRIu32
,
61 DEFAULT_SNAPSHOT_NAME
, output
->id
);
72 output
->consumer
= consumer_copy_output(consumer
);
73 if (!output
->consumer
) {
84 if (uris
[0].dtype
== LTTNG_DST_PATH
) {
85 memset(output
->consumer
->dst
.trace_path
, 0,
86 sizeof(output
->consumer
->dst
.trace_path
));
87 strncpy(output
->consumer
->dst
.trace_path
, uris
[0].dst
.path
,
88 sizeof(output
->consumer
->dst
.trace_path
));
89 output
->consumer
->type
= CONSUMER_DST_LOCAL
;
95 /* Absolutely needs two URIs for network. */
96 ret
= -LTTNG_ERR_INVALID
;
100 for (i
= 0; i
< nb_uri
; i
++) {
102 ret
= consumer_set_network_uri(output
->consumer
, &uris
[i
]);
114 * Initialize a snapshot output object using the given parameters and URI(s).
115 * The name value and uris can be NULL.
117 * Return 0 on success or else a negative value.
119 int snapshot_output_init_with_uri(uint64_t max_size
, const char *name
,
120 struct lttng_uri
*uris
, size_t nb_uri
,
121 struct consumer_output
*consumer
, struct snapshot_output
*output
,
122 struct snapshot
*snapshot
)
124 return output_init(max_size
, name
, uris
, nb_uri
, consumer
, output
,
129 * Initialize a snapshot output object using the given parameters. The name
130 * value and url can be NULL.
132 * Return 0 on success or else a negative value.
134 int snapshot_output_init(uint64_t max_size
, const char *name
,
135 const char *ctrl_url
, const char *data_url
,
136 struct consumer_output
*consumer
, struct snapshot_output
*output
,
137 struct snapshot
*snapshot
)
140 struct lttng_uri
*uris
= NULL
;
142 /* Create an array of URIs from URLs. */
143 nb_uri
= uri_parse_str_urls(ctrl_url
, data_url
, &uris
);
149 ret
= output_init(max_size
, name
, uris
, nb_uri
, consumer
, output
,
157 struct snapshot_output
*snapshot_output_alloc(void)
159 return zmalloc(sizeof(struct snapshot_output
));
163 * Delete output from the snapshot object.
165 void snapshot_delete_output(struct snapshot
*snapshot
,
166 struct snapshot_output
*output
)
169 struct lttng_ht_iter iter
;
172 assert(snapshot
->output_ht
);
175 iter
.iter
.node
= &output
->node
.node
;
177 ret
= lttng_ht_del(snapshot
->output_ht
, &iter
);
181 * This is safe because the ownership of a snapshot object is in a session
182 * for which the session lock need to be acquired to read and modify it.
184 snapshot
->nb_output
--;
188 * Add output object to the snapshot.
190 void snapshot_add_output(struct snapshot
*snapshot
,
191 struct snapshot_output
*output
)
194 assert(snapshot
->output_ht
);
198 lttng_ht_add_unique_ulong(snapshot
->output_ht
, &output
->node
);
201 * This is safe because the ownership of a snapshot object is in a session
202 * for which the session lock need to be acquired to read and modify it.
204 snapshot
->nb_output
++;
208 * Destroy and free a snapshot output object.
210 void snapshot_output_destroy(struct snapshot_output
*obj
)
215 consumer_output_send_destroy_relayd(obj
->consumer
);
216 consumer_destroy_output(obj
->consumer
);
222 * RCU read side lock MUST be acquired before calling this since the returned
223 * pointer is in a RCU hash table.
225 * Return the reference on success or else NULL.
227 struct snapshot_output
*snapshot_find_output_by_id(uint32_t id
,
228 struct snapshot
*snapshot
)
230 struct lttng_ht_node_ulong
*node
;
231 struct lttng_ht_iter iter
;
232 struct snapshot_output
*output
= NULL
;
236 lttng_ht_lookup(snapshot
->output_ht
, (void *)((unsigned long) id
), &iter
);
237 node
= lttng_ht_iter_get_node_ulong(&iter
);
239 DBG3("Snapshot output not found with id %" PRId32
, id
);
242 output
= caa_container_of(node
, struct snapshot_output
, node
);
249 * Initialized a snapshot object that was already allocated.
251 * Return 0 on success or else a negative errno value.
253 int snapshot_init(struct snapshot
*obj
)
259 memset(obj
, 0, sizeof(struct snapshot
));
261 obj
->output_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
262 if (!obj
->output_ht
) {
274 * Destroy snapshot object but the pointer is not freed so it's safe to pass a
277 void snapshot_destroy(struct snapshot
*obj
)
279 struct lttng_ht_iter iter
;
280 struct snapshot_output
*output
;
285 cds_lfht_for_each_entry(obj
->output_ht
->ht
, &iter
.iter
, output
,
287 snapshot_delete_output(obj
, output
);
288 snapshot_output_destroy(output
);
This page took 0.059788 seconds and 4 git commands to generate.