77255fa2c597f0440e72e8585be486c64e6ef369
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 * Initialize a snapshot output object using the given parameters. The name
38 * value and url can be NULL.
40 * Return 0 on success or else a negative value.
42 int snapshot_output_init(uint64_t max_size
, const char *name
,
43 const char *ctrl_url
, const char *data_url
,
44 struct consumer_output
*consumer
, struct snapshot_output
*output
,
45 struct snapshot
*snapshot
)
47 int ret
= 0, nb_uri
, i
;
48 struct lttng_uri
*uris
= NULL
;
52 output
->max_size
= max_size
;
54 output
->id
= get_next_output_id(snapshot
);
56 lttng_ht_node_init_ulong(&output
->node
, (unsigned long) output
->id
);
59 strncpy(output
->name
, name
, sizeof(output
->name
));
61 /* Set default name. */
62 ret
= snprintf(output
->name
, sizeof(output
->name
), "%s-%" PRIu32
,
63 DEFAULT_SNAPSHOT_NAME
, output
->id
);
74 /* Create an array of URIs from URLs. */
75 nb_uri
= uri_parse_str_urls(ctrl_url
, data_url
, &uris
);
81 output
->consumer
= consumer_copy_output(consumer
);
82 if (!output
->consumer
) {
93 if (uris
[0].dtype
== LTTNG_DST_PATH
) {
94 memset(output
->consumer
->dst
.trace_path
, 0,
95 sizeof(output
->consumer
->dst
.trace_path
));
96 strncpy(output
->consumer
->dst
.trace_path
, uris
[0].dst
.path
,
97 sizeof(output
->consumer
->dst
.trace_path
));
98 output
->consumer
->type
= CONSUMER_DST_LOCAL
;
104 /* Absolutely needs two URIs for network. */
105 ret
= -LTTNG_ERR_INVALID
;
109 for (i
= 0; i
< nb_uri
; i
++) {
111 ret
= consumer_set_network_uri(output
->consumer
, &uris
[i
]);
123 struct snapshot_output
*snapshot_output_alloc(void)
125 return zmalloc(sizeof(struct snapshot_output
));
129 * Delete output from the snapshot object.
131 void snapshot_delete_output(struct snapshot
*snapshot
,
132 struct snapshot_output
*output
)
135 struct lttng_ht_iter iter
;
138 assert(snapshot
->output_ht
);
141 iter
.iter
.node
= &output
->node
.node
;
143 ret
= lttng_ht_del(snapshot
->output_ht
, &iter
);
147 * This is safe because the ownership of a snapshot object is in a session
148 * for which the session lock need to be acquired to read and modify it.
150 snapshot
->nb_output
--;
154 * Add output object to the snapshot.
156 void snapshot_add_output(struct snapshot
*snapshot
,
157 struct snapshot_output
*output
)
160 assert(snapshot
->output_ht
);
164 lttng_ht_add_unique_ulong(snapshot
->output_ht
, &output
->node
);
167 * This is safe because the ownership of a snapshot object is in a session
168 * for which the session lock need to be acquired to read and modify it.
170 snapshot
->nb_output
++;
174 * Destroy and free a snapshot output object.
176 void snapshot_output_destroy(struct snapshot_output
*obj
)
181 consumer_output_send_destroy_relayd(obj
->consumer
);
182 consumer_destroy_output(obj
->consumer
);
188 * RCU read side lock MUST be acquired before calling this since the returned
189 * pointer is in a RCU hash table.
191 * Return the reference on success or else NULL.
193 struct snapshot_output
*snapshot_find_output_by_id(uint32_t id
,
194 struct snapshot
*snapshot
)
196 struct lttng_ht_node_ulong
*node
;
197 struct lttng_ht_iter iter
;
198 struct snapshot_output
*output
= NULL
;
202 lttng_ht_lookup(snapshot
->output_ht
, (void *)((unsigned long) id
), &iter
);
203 node
= lttng_ht_iter_get_node_ulong(&iter
);
205 DBG3("Snapshot output not found with id %" PRId32
, id
);
208 output
= caa_container_of(node
, struct snapshot_output
, node
);
214 struct snapshot
*snapshot_alloc(void)
216 return zmalloc(sizeof(struct snapshot
));
220 * Initialized a snapshot object that was already allocated.
222 * Return 0 on success or else a negative errno value.
224 int snapshot_init(struct snapshot
*obj
)
230 memset(obj
, 0, sizeof(struct snapshot
));
232 obj
->output_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
233 if (!obj
->output_ht
) {
245 * Destroy snapshot object but the pointer is not freed so it's safe to pass a
248 void snapshot_destroy(struct snapshot
*obj
)
250 struct lttng_ht_iter iter
;
251 struct snapshot_output
*output
;
256 cds_lfht_for_each_entry(obj
->output_ht
->ht
, &iter
.iter
, output
,
258 snapshot_delete_output(obj
, output
);
259 snapshot_output_destroy(output
);
This page took 0.064334 seconds and 4 git commands to generate.