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 if (max_size
== (uint64_t) -1ULL) {
53 output
->max_size
= max_size
;
56 output
->id
= get_next_output_id(snapshot
);
58 lttng_ht_node_init_ulong(&output
->node
, (unsigned long) output
->id
);
60 if (name
&& name
[0] != '\0') {
61 strncpy(output
->name
, name
, sizeof(output
->name
));
63 /* Set default name. */
64 ret
= snprintf(output
->name
, sizeof(output
->name
), "%s-%" PRIu32
,
65 DEFAULT_SNAPSHOT_NAME
, output
->id
);
76 output
->consumer
= consumer_copy_output(consumer
);
77 if (!output
->consumer
) {
88 if (uris
[0].dtype
== LTTNG_DST_PATH
) {
89 memset(output
->consumer
->dst
.trace_path
, 0,
90 sizeof(output
->consumer
->dst
.trace_path
));
91 strncpy(output
->consumer
->dst
.trace_path
, uris
[0].dst
.path
,
92 sizeof(output
->consumer
->dst
.trace_path
));
93 output
->consumer
->type
= CONSUMER_DST_LOCAL
;
99 /* Absolutely needs two URIs for network. */
100 ret
= -LTTNG_ERR_INVALID
;
104 for (i
= 0; i
< nb_uri
; i
++) {
106 ret
= consumer_set_network_uri(output
->consumer
, &uris
[i
]);
118 * Initialize a snapshot output object using the given parameters and URI(s).
119 * The name value and uris can be NULL.
121 * Return 0 on success or else a negative value.
123 int snapshot_output_init_with_uri(uint64_t max_size
, const char *name
,
124 struct lttng_uri
*uris
, size_t nb_uri
,
125 struct consumer_output
*consumer
, struct snapshot_output
*output
,
126 struct snapshot
*snapshot
)
128 return output_init(max_size
, name
, uris
, nb_uri
, consumer
, output
,
133 * Initialize a snapshot output object using the given parameters. The name
134 * value and url can be NULL.
136 * Return 0 on success or else a negative value.
138 int snapshot_output_init(uint64_t max_size
, const char *name
,
139 const char *ctrl_url
, const char *data_url
,
140 struct consumer_output
*consumer
, struct snapshot_output
*output
,
141 struct snapshot
*snapshot
)
144 struct lttng_uri
*uris
= NULL
;
146 /* Create an array of URIs from URLs. */
147 nb_uri
= uri_parse_str_urls(ctrl_url
, data_url
, &uris
);
153 ret
= output_init(max_size
, name
, uris
, nb_uri
, consumer
, output
,
161 struct snapshot_output
*snapshot_output_alloc(void)
163 return zmalloc(sizeof(struct snapshot_output
));
167 * Delete output from the snapshot object.
169 void snapshot_delete_output(struct snapshot
*snapshot
,
170 struct snapshot_output
*output
)
173 struct lttng_ht_iter iter
;
176 assert(snapshot
->output_ht
);
179 iter
.iter
.node
= &output
->node
.node
;
181 ret
= lttng_ht_del(snapshot
->output_ht
, &iter
);
185 * This is safe because the ownership of a snapshot object is in a session
186 * for which the session lock need to be acquired to read and modify it.
188 snapshot
->nb_output
--;
192 * Add output object to the snapshot.
194 void snapshot_add_output(struct snapshot
*snapshot
,
195 struct snapshot_output
*output
)
198 assert(snapshot
->output_ht
);
202 lttng_ht_add_unique_ulong(snapshot
->output_ht
, &output
->node
);
205 * This is safe because the ownership of a snapshot object is in a session
206 * for which the session lock need to be acquired to read and modify it.
208 snapshot
->nb_output
++;
212 * Destroy and free a snapshot output object.
214 void snapshot_output_destroy(struct snapshot_output
*obj
)
219 consumer_output_send_destroy_relayd(obj
->consumer
);
220 consumer_destroy_output(obj
->consumer
);
226 * RCU read side lock MUST be acquired before calling this since the returned
227 * pointer is in a RCU hash table.
229 * Return the reference on success or else NULL.
231 struct snapshot_output
*snapshot_find_output_by_id(uint32_t id
,
232 struct snapshot
*snapshot
)
234 struct lttng_ht_node_ulong
*node
;
235 struct lttng_ht_iter iter
;
236 struct snapshot_output
*output
= NULL
;
240 lttng_ht_lookup(snapshot
->output_ht
, (void *)((unsigned long) id
), &iter
);
241 node
= lttng_ht_iter_get_node_ulong(&iter
);
243 DBG3("Snapshot output not found with id %" PRId32
, id
);
246 output
= caa_container_of(node
, struct snapshot_output
, node
);
253 * Initialized a snapshot object that was already allocated.
255 * Return 0 on success or else a negative errno value.
257 int snapshot_init(struct snapshot
*obj
)
263 memset(obj
, 0, sizeof(struct snapshot
));
265 obj
->output_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
266 if (!obj
->output_ht
) {
278 * Destroy snapshot object but the pointer is not freed so it's safe to pass a
281 void snapshot_destroy(struct snapshot
*obj
)
283 struct lttng_ht_iter iter
;
284 struct snapshot_output
*output
;
289 cds_lfht_for_each_entry(obj
->output_ht
->ht
, &iter
.iter
, output
,
291 snapshot_delete_output(obj
, output
);
292 snapshot_output_destroy(output
);
This page took 0.036834 seconds and 4 git commands to generate.