sessiond: tsdl: remove useless std::move
[lttng-tools.git] / src / bin / lttng-sessiond / buffer-registry.cpp
CommitLineData
7972aab2 1/*
ab5be9fa 2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
7972aab2 3 *
ab5be9fa 4 * SPDX-License-Identifier: GPL-2.0-only
7972aab2 5 *
7972aab2
DG
6 */
7
6c1c0768 8#define _LGPL_SOURCE
7972aab2
DG
9#include <inttypes.h>
10
c9e313bc
SM
11#include <common/common.hpp>
12#include <common/hashtable/utils.hpp>
7972aab2 13
c9e313bc
SM
14#include "buffer-registry.hpp"
15#include "fd-limit.hpp"
16#include "ust-consumer.hpp"
17#include "lttng-ust-ctl.hpp"
18#include "lttng-ust-error.hpp"
19#include "utils.hpp"
7972aab2
DG
20
21/*
22 * Set in main.c during initialization process of the daemon. This contains
23 * buffer_reg_uid object which are global registry for per UID buffer. Object
24 * are indexed by session id and matched by the triplet
25 * <session_id/bits_per_long/uid>.
26 */
27static struct lttng_ht *buffer_registry_uid;
28
29/*
30 * Initialized at the daemon start. This contains buffer_reg_pid object and
31 * indexed by session id.
32 */
33static struct lttng_ht *buffer_registry_pid;
34
35/*
36 * Match function for the per UID registry hash table. It matches a registry
37 * uid object with the triplet <session_id/abi/uid>.
38 */
39static int ht_match_reg_uid(struct cds_lfht_node *node, const void *_key)
40{
41 struct buffer_reg_uid *reg;
42 const struct buffer_reg_uid *key;
43
a0377dfe
FD
44 LTTNG_ASSERT(node);
45 LTTNG_ASSERT(_key);
7972aab2
DG
46
47 reg = caa_container_of(node, struct buffer_reg_uid, node.node);
a0377dfe 48 LTTNG_ASSERT(reg);
7966af57 49 key = (buffer_reg_uid *) _key;
7972aab2
DG
50
51 if (key->session_id != reg->session_id ||
52 key->bits_per_long != reg->bits_per_long ||
53 key->uid != reg->uid) {
54 goto no_match;
55 }
56
57 /* Match */
58 return 1;
59no_match:
60 return 0;
61}
62
63/*
64 * Hash function for the per UID registry hash table. This XOR the triplet
65 * together.
66 */
bcd52dd9 67static unsigned long ht_hash_reg_uid(const void *_key, unsigned long seed)
7972aab2
DG
68{
69 uint64_t xored_key;
7966af57 70 const struct buffer_reg_uid *key = (buffer_reg_uid *) _key;
7972aab2 71
a0377dfe 72 LTTNG_ASSERT(key);
7972aab2
DG
73
74 xored_key = (uint64_t)(key->session_id ^ key->bits_per_long ^ key->uid);
75 return hash_key_u64(&xored_key, seed);
76}
77
78/*
79 * Initialize global buffer per UID registry. Should only be called ONCE!.
80 */
81void buffer_reg_init_uid_registry(void)
82{
83 /* Should be called once. */
a0377dfe 84 LTTNG_ASSERT(!buffer_registry_uid);
7972aab2 85 buffer_registry_uid = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
a0377dfe 86 LTTNG_ASSERT(buffer_registry_uid);
7972aab2
DG
87 buffer_registry_uid->match_fct = ht_match_reg_uid;
88 buffer_registry_uid->hash_fct = ht_hash_reg_uid;
89
90 DBG3("Global buffer per UID registry initialized");
91}
92
93/*
94 * Allocate and initialize object. Set regp with the object pointer.
95 *
96 * Return 0 on success else a negative value and regp is untouched.
97 */
d9bf3ca4 98int buffer_reg_uid_create(uint64_t session_id, uint32_t bits_per_long, uid_t uid,
d7ba1388 99 enum lttng_domain_type domain, struct buffer_reg_uid **regp,
3d071855 100 const char *root_shm_path, const char *shm_path)
7972aab2
DG
101{
102 int ret = 0;
103 struct buffer_reg_uid *reg = NULL;
104
a0377dfe 105 LTTNG_ASSERT(regp);
7972aab2 106
64803277 107 reg = zmalloc<buffer_reg_uid>();
7972aab2
DG
108 if (!reg) {
109 PERROR("zmalloc buffer registry uid");
110 ret = -ENOMEM;
111 goto error;
112 }
113
64803277 114 reg->registry = zmalloc<buffer_reg_session>();
63c861bd 115 if (!reg->registry) {
7972aab2
DG
116 PERROR("zmalloc buffer registry uid session");
117 ret = -ENOMEM;
118 goto error;
119 }
120
121 reg->session_id = session_id;
122 reg->bits_per_long = bits_per_long;
123 reg->uid = uid;
124 reg->domain = domain;
d7ba1388 125 if (shm_path[0]) {
3d071855
MD
126 strncpy(reg->root_shm_path, root_shm_path, sizeof(reg->root_shm_path));
127 reg->root_shm_path[sizeof(reg->root_shm_path) - 1] = '\0';
d7ba1388
MD
128 strncpy(reg->shm_path, shm_path, sizeof(reg->shm_path));
129 reg->shm_path[sizeof(reg->shm_path) - 1] = '\0';
130 DBG3("shm path '%s' is assigned to uid buffer registry for session id %" PRIu64,
131 reg->shm_path, session_id);
132 }
7972aab2
DG
133 reg->registry->channels = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
134 if (!reg->registry->channels) {
135 ret = -ENOMEM;
136 goto error_session;
137 }
138
139 cds_lfht_node_init(&reg->node.node);
140 *regp = reg;
141
d9bf3ca4 142 DBG3("Buffer registry per UID created id: %" PRIu64 ", ABI: %u, uid: %d, domain: %d",
7972aab2
DG
143 session_id, bits_per_long, uid, domain);
144
145 return 0;
146
147error_session:
148 free(reg->registry);
149error:
150 free(reg);
151 return ret;
152}
153
154/*
155 * Add a buffer registry per UID object to the global registry.
156 */
157void buffer_reg_uid_add(struct buffer_reg_uid *reg)
158{
159 struct cds_lfht_node *nodep;
160 struct lttng_ht *ht = buffer_registry_uid;
161
a0377dfe 162 LTTNG_ASSERT(reg);
7972aab2 163
d9bf3ca4 164 DBG3("Buffer registry per UID adding to global registry with id: %" PRIu64 ,
7972aab2
DG
165 reg->session_id);
166
167 rcu_read_lock();
168 nodep = cds_lfht_add_unique(ht->ht, ht->hash_fct(reg, lttng_ht_seed),
169 ht->match_fct, reg, &reg->node.node);
a0377dfe 170 LTTNG_ASSERT(nodep == &reg->node.node);
7972aab2
DG
171 rcu_read_unlock();
172}
173
174/*
175 * Find a buffer registry per UID object with given params. RCU read side lock
176 * MUST be acquired before calling this and hold on to protect the object.
177 *
178 * Return the object pointer or NULL on error.
179 */
d9bf3ca4 180struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id,
7972aab2
DG
181 uint32_t bits_per_long, uid_t uid)
182{
183 struct lttng_ht_node_u64 *node;
184 struct lttng_ht_iter iter;
185 struct buffer_reg_uid *reg = NULL, key;
186 struct lttng_ht *ht = buffer_registry_uid;
187
48b7cdc2
FD
188 ASSERT_RCU_READ_LOCKED();
189
7972aab2
DG
190 /* Setup key we are looking for. */
191 key.session_id = session_id;
192 key.bits_per_long = bits_per_long;
193 key.uid = uid;
194
d9bf3ca4 195 DBG3("Buffer registry per UID find id: %" PRIu64 ", ABI: %u, uid: %d",
7972aab2
DG
196 session_id, bits_per_long, uid);
197
198 /* Custom lookup function since it's a different key. */
199 cds_lfht_lookup(ht->ht, ht->hash_fct(&key, lttng_ht_seed), ht->match_fct,
200 &key, &iter.iter);
201 node = lttng_ht_iter_get_node_u64(&iter);
202 if (!node) {
203 goto end;
204 }
0114db0e 205 reg = lttng::utils::container_of(node, &buffer_reg_uid::node);
7972aab2
DG
206
207end:
208 return reg;
209}
210
211/*
212 * Initialize global buffer per PID registry. Should only be called ONCE!.
213 */
214void buffer_reg_init_pid_registry(void)
215{
216 /* Should be called once. */
a0377dfe 217 LTTNG_ASSERT(!buffer_registry_pid);
d9bf3ca4 218 buffer_registry_pid = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
a0377dfe 219 LTTNG_ASSERT(buffer_registry_pid);
7972aab2
DG
220
221 DBG3("Global buffer per PID registry initialized");
222}
223
224/*
225 * Allocate and initialize object. Set regp with the object pointer.
226 *
227 * Return 0 on success else a negative value and regp is untouched.
228 */
d7ba1388 229int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp,
3d071855 230 const char *root_shm_path, const char *shm_path)
7972aab2
DG
231{
232 int ret = 0;
233 struct buffer_reg_pid *reg = NULL;
234
a0377dfe 235 LTTNG_ASSERT(regp);
7972aab2 236
64803277 237 reg = zmalloc<buffer_reg_pid>();
7972aab2
DG
238 if (!reg) {
239 PERROR("zmalloc buffer registry pid");
240 ret = -ENOMEM;
241 goto error;
242 }
243
64803277 244 reg->registry = zmalloc<buffer_reg_session>();
63c861bd 245 if (!reg->registry) {
7972aab2
DG
246 PERROR("zmalloc buffer registry pid session");
247 ret = -ENOMEM;
248 goto error;
249 }
250
251 /* A cast is done here so we can use the session ID as a u64 ht node. */
252 reg->session_id = session_id;
d7ba1388 253 if (shm_path[0]) {
3d071855
MD
254 strncpy(reg->root_shm_path, root_shm_path, sizeof(reg->root_shm_path));
255 reg->root_shm_path[sizeof(reg->root_shm_path) - 1] = '\0';
d7ba1388
MD
256 strncpy(reg->shm_path, shm_path, sizeof(reg->shm_path));
257 reg->shm_path[sizeof(reg->shm_path) - 1] = '\0';
258 DBG3("shm path '%s' is assigned to pid buffer registry for session id %" PRIu64,
259 reg->shm_path, session_id);
260 }
7972aab2
DG
261 reg->registry->channels = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
262 if (!reg->registry->channels) {
263 ret = -ENOMEM;
264 goto error_session;
265 }
266
d9bf3ca4 267 lttng_ht_node_init_u64(&reg->node, reg->session_id);
7972aab2
DG
268 *regp = reg;
269
d9bf3ca4
MD
270 DBG3("Buffer registry per PID created with session id: %" PRIu64,
271 session_id);
7972aab2
DG
272
273 return 0;
274
275error_session:
276 free(reg->registry);
277error:
278 free(reg);
279 return ret;
280}
281
282/*
283 * Add a buffer registry per PID object to the global registry.
284 */
285void buffer_reg_pid_add(struct buffer_reg_pid *reg)
286{
a0377dfe 287 LTTNG_ASSERT(reg);
7972aab2 288
d9bf3ca4 289 DBG3("Buffer registry per PID adding to global registry with id: %" PRIu64,
7972aab2
DG
290 reg->session_id);
291
292 rcu_read_lock();
d9bf3ca4 293 lttng_ht_add_unique_u64(buffer_registry_pid, &reg->node);
7972aab2
DG
294 rcu_read_unlock();
295}
296
297/*
298 * Find a buffer registry per PID object with given params. RCU read side lock
299 * MUST be acquired before calling this and hold on to protect the object.
300 *
301 * Return the object pointer or NULL on error.
302 */
d9bf3ca4 303struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id)
7972aab2 304{
d9bf3ca4 305 struct lttng_ht_node_u64 *node;
7972aab2
DG
306 struct lttng_ht_iter iter;
307 struct buffer_reg_pid *reg = NULL;
308 struct lttng_ht *ht = buffer_registry_pid;
309
d9bf3ca4 310 DBG3("Buffer registry per PID find id: %" PRIu64, session_id);
7972aab2 311
d9bf3ca4
MD
312 lttng_ht_lookup(ht, &session_id, &iter);
313 node = lttng_ht_iter_get_node_u64(&iter);
7972aab2
DG
314 if (!node) {
315 goto end;
316 }
0114db0e 317 reg = lttng::utils::container_of(node, &buffer_reg_pid::node);
7972aab2
DG
318
319end:
320 return reg;
321}
322
fb83fe64
JD
323/*
324 * Find the consumer channel key from a UST session per-uid channel key.
325 *
326 * Return the matching key or -1 if not found.
327 */
328int buffer_reg_uid_consumer_channel_key(
329 struct cds_list_head *buffer_reg_uid_list,
76604852 330 uint64_t chan_key, uint64_t *consumer_chan_key)
fb83fe64
JD
331{
332 struct lttng_ht_iter iter;
333 struct buffer_reg_uid *uid_reg = NULL;
334 struct buffer_reg_session *session_reg = NULL;
335 struct buffer_reg_channel *reg_chan;
336 int ret = -1;
337
338 rcu_read_lock();
339 /*
340 * For the per-uid registry, we have to iterate since we don't have the
341 * uid and bitness key.
342 */
343 cds_list_for_each_entry(uid_reg, buffer_reg_uid_list, lnode) {
344 session_reg = uid_reg->registry;
345 cds_lfht_for_each_entry(session_reg->channels->ht,
346 &iter.iter, reg_chan, node.node) {
347 if (reg_chan->key == chan_key) {
348 *consumer_chan_key = reg_chan->consumer_key;
349 ret = 0;
350 goto end;
351 }
352 }
353 }
354
355end:
356 rcu_read_unlock();
357 return ret;
358}
359
7972aab2
DG
360/*
361 * Allocate and initialize a buffer registry channel with the given key. Set
362 * regp with the object pointer.
363 *
364 * Return 0 on success or else a negative value keeping regp untouched.
365 */
366int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp)
367{
368 struct buffer_reg_channel *reg;
369
a0377dfe 370 LTTNG_ASSERT(regp);
7972aab2
DG
371
372 DBG3("Buffer registry channel create with key: %" PRIu64, key);
373
64803277 374 reg = zmalloc<buffer_reg_channel>();
7972aab2
DG
375 if (!reg) {
376 PERROR("zmalloc buffer registry channel");
377 return -ENOMEM;
378 }
379
380 reg->key = key;
381 CDS_INIT_LIST_HEAD(&reg->streams);
382 pthread_mutex_init(&reg->stream_list_lock, NULL);
383
384 lttng_ht_node_init_u64(&reg->node, key);
385 *regp = reg;
386
387 return 0;
388}
389
390/*
391 * Allocate and initialize a buffer registry stream. Set regp with the object
392 * pointer.
393 *
394 * Return 0 on success or else a negative value keeping regp untouched.
395 */
396int buffer_reg_stream_create(struct buffer_reg_stream **regp)
397{
398 struct buffer_reg_stream *reg;
399
a0377dfe 400 LTTNG_ASSERT(regp);
7972aab2
DG
401
402 DBG3("Buffer registry creating stream");
403
64803277 404 reg = zmalloc<buffer_reg_stream>();
7972aab2
DG
405 if (!reg) {
406 PERROR("zmalloc buffer registry stream");
407 return -ENOMEM;
408 }
409
410 *regp = reg;
411
412 return 0;
413}
414
415/*
416 * Add stream to the list in the channel.
417 */
418void buffer_reg_stream_add(struct buffer_reg_stream *stream,
419 struct buffer_reg_channel *channel)
420{
a0377dfe
FD
421 LTTNG_ASSERT(stream);
422 LTTNG_ASSERT(channel);
7972aab2
DG
423
424 pthread_mutex_lock(&channel->stream_list_lock);
425 cds_list_add_tail(&stream->lnode, &channel->streams);
5c786ded 426 channel->stream_count++;
7972aab2
DG
427 pthread_mutex_unlock(&channel->stream_list_lock);
428}
429
430/*
431 * Add a buffer registry channel object to the given session.
432 */
433void buffer_reg_channel_add(struct buffer_reg_session *session,
434 struct buffer_reg_channel *channel)
435{
a0377dfe
FD
436 LTTNG_ASSERT(session);
437 LTTNG_ASSERT(channel);
7972aab2
DG
438
439 rcu_read_lock();
440 lttng_ht_add_unique_u64(session->channels, &channel->node);
441 rcu_read_unlock();
442}
443
444/*
445 * Find a buffer registry channel object with the given key. RCU read side lock
446 * MUST be acquired and hold on until the object reference is not needed
447 * anymore.
448 *
449 * Return the object pointer or NULL on error.
450 */
451struct buffer_reg_channel *buffer_reg_channel_find(uint64_t key,
452 struct buffer_reg_uid *reg)
453{
454 struct lttng_ht_node_u64 *node;
455 struct lttng_ht_iter iter;
456 struct buffer_reg_channel *chan = NULL;
457 struct lttng_ht *ht;
458
a0377dfe 459 LTTNG_ASSERT(reg);
7972aab2
DG
460
461 switch (reg->domain) {
462 case LTTNG_DOMAIN_UST:
463 ht = reg->registry->channels;
464 break;
465 default:
a0377dfe 466 abort();
7972aab2
DG
467 goto end;
468 }
469
470 lttng_ht_lookup(ht, &key, &iter);
471 node = lttng_ht_iter_get_node_u64(&iter);
472 if (!node) {
473 goto end;
474 }
0114db0e 475 chan = lttng::utils::container_of(node, &buffer_reg_channel::node);
7972aab2
DG
476
477end:
478 return chan;
479}
480
481/*
482 * Destroy a buffer registry stream with the given domain.
483 */
484void buffer_reg_stream_destroy(struct buffer_reg_stream *regp,
485 enum lttng_domain_type domain)
486{
487 if (!regp) {
488 return;
489 }
490
491 DBG3("Buffer registry stream destroy with handle %d",
492 regp->obj.ust->handle);
493
494 switch (domain) {
495 case LTTNG_DOMAIN_UST:
496 {
497 int ret;
498
fb45065e 499 ret = ust_app_release_object(NULL, regp->obj.ust);
7972aab2
DG
500 if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) {
501 ERR("Buffer reg stream release obj handle %d failed with ret %d",
502 regp->obj.ust->handle, ret);
503 }
504 free(regp->obj.ust);
505 lttng_fd_put(LTTNG_FD_APPS, 2);
506 break;
507 }
508 default:
a0377dfe 509 abort();
7972aab2
DG
510 }
511
512 free(regp);
513 return;
514}
515
516/*
517 * Remove buffer registry channel object from the session hash table. RCU read
518 * side lock MUST be acquired before calling this.
519 */
520void buffer_reg_channel_remove(struct buffer_reg_session *session,
521 struct buffer_reg_channel *regp)
522{
523 int ret;
524 struct lttng_ht_iter iter;
525
a0377dfe
FD
526 LTTNG_ASSERT(session);
527 LTTNG_ASSERT(regp);
7972aab2
DG
528
529 iter.iter.node = &regp->node.node;
530 ret = lttng_ht_del(session->channels, &iter);
a0377dfe 531 LTTNG_ASSERT(!ret);
7972aab2
DG
532}
533
534/*
535 * Destroy a buffer registry channel with the given domain.
536 */
537void buffer_reg_channel_destroy(struct buffer_reg_channel *regp,
538 enum lttng_domain_type domain)
539{
540 if (!regp) {
541 return;
542 }
543
07d2ae95 544 DBG3("Buffer registry channel destroy with key %" PRIu32, regp->key);
7972aab2
DG
545
546 switch (domain) {
547 case LTTNG_DOMAIN_UST:
548 {
549 int ret;
550 struct buffer_reg_stream *sreg, *stmp;
551 /* Wipe stream */
552 cds_list_for_each_entry_safe(sreg, stmp, &regp->streams, lnode) {
553 cds_list_del(&sreg->lnode);
5c786ded 554 regp->stream_count--;
7972aab2
DG
555 buffer_reg_stream_destroy(sreg, domain);
556 }
557
55d7e860 558 if (regp->obj.ust) {
fb45065e 559 ret = ust_app_release_object(NULL, regp->obj.ust);
55d7e860
MD
560 if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) {
561 ERR("Buffer reg channel release obj handle %d failed with ret %d",
562 regp->obj.ust->handle, ret);
563 }
564 free(regp->obj.ust);
7972aab2 565 }
7972aab2
DG
566 lttng_fd_put(LTTNG_FD_APPS, 1);
567 break;
568 }
569 default:
a0377dfe 570 abort();
7972aab2
DG
571 }
572
573 free(regp);
574 return;
575}
576
577/*
578 * Destroy a buffer registry session with the given domain.
579 */
36b588ed 580static void buffer_reg_session_destroy(struct buffer_reg_session *regp,
7972aab2
DG
581 enum lttng_domain_type domain)
582{
583 int ret;
584 struct lttng_ht_iter iter;
585 struct buffer_reg_channel *reg_chan;
586
587 DBG3("Buffer registry session destroy");
588
589 /* Destroy all channels. */
590 rcu_read_lock();
591 cds_lfht_for_each_entry(regp->channels->ht, &iter.iter, reg_chan,
592 node.node) {
593 ret = lttng_ht_del(regp->channels, &iter);
a0377dfe 594 LTTNG_ASSERT(!ret);
7972aab2
DG
595 buffer_reg_channel_destroy(reg_chan, domain);
596 }
7972aab2
DG
597 rcu_read_unlock();
598
3c339053 599 lttng_ht_destroy(regp->channels);
36b588ed 600
7972aab2
DG
601 switch (domain) {
602 case LTTNG_DOMAIN_UST:
603 ust_registry_session_destroy(regp->reg.ust);
7972aab2
DG
604 break;
605 default:
a0377dfe 606 abort();
7972aab2
DG
607 }
608
609 free(regp);
610 return;
611}
612
613/*
36b588ed 614 * Remove buffer registry UID object from the global hash table.
7972aab2
DG
615 */
616void buffer_reg_uid_remove(struct buffer_reg_uid *regp)
617{
618 int ret;
619 struct lttng_ht_iter iter;
620
a0377dfe 621 LTTNG_ASSERT(regp);
7972aab2 622
36b588ed 623 rcu_read_lock();
7972aab2
DG
624 iter.iter.node = &regp->node.node;
625 ret = lttng_ht_del(buffer_registry_uid, &iter);
a0377dfe 626 LTTNG_ASSERT(!ret);
36b588ed 627 rcu_read_unlock();
7972aab2
DG
628}
629
630static void rcu_free_buffer_reg_uid(struct rcu_head *head)
631{
632 struct lttng_ht_node_u64 *node =
0114db0e 633 lttng::utils::container_of(head, &lttng_ht_node_u64::head);
7972aab2 634 struct buffer_reg_uid *reg =
0114db0e 635 lttng::utils::container_of(node, &buffer_reg_uid::node);
7972aab2
DG
636
637 buffer_reg_session_destroy(reg->registry, reg->domain);
638 free(reg);
639}
640
641static void rcu_free_buffer_reg_pid(struct rcu_head *head)
642{
d9bf3ca4 643 struct lttng_ht_node_u64 *node =
0114db0e 644 lttng::utils::container_of(head, &lttng_ht_node_u64::head);
7972aab2 645 struct buffer_reg_pid *reg =
0114db0e 646 lttng::utils::container_of(node, &buffer_reg_pid::node);
7972aab2
DG
647
648 buffer_reg_session_destroy(reg->registry, LTTNG_DOMAIN_UST);
649 free(reg);
650}
651
652/*
653 * Destroy buffer registry per UID. The given pointer is NOT removed from any
654 * list or hash table. Use buffer_reg_pid_remove() before calling this function
655 * for the case that the object is in the global hash table.
656 */
657void buffer_reg_uid_destroy(struct buffer_reg_uid *regp,
658 struct consumer_output *consumer)
659{
660 struct consumer_socket *socket;
661
662 if (!regp) {
663 return;
664 }
665
d9bf3ca4 666 DBG3("Buffer registry per UID destroy with id: %" PRIu64 ", ABI: %u, uid: %d",
7972aab2
DG
667 regp->session_id, regp->bits_per_long, regp->uid);
668
669 if (!consumer) {
670 goto destroy;
671 }
672
36b588ed 673 rcu_read_lock();
7972aab2
DG
674 /* Get the right socket from the consumer object. */
675 socket = consumer_find_socket_by_bitness(regp->bits_per_long,
676 consumer);
677 if (!socket) {
36b588ed 678 goto unlock;
7972aab2
DG
679 }
680
681 switch (regp->domain) {
682 case LTTNG_DOMAIN_UST:
aeeb48c6 683 if (regp->registry->reg.ust->_metadata_key) {
7972aab2
DG
684 /* Return value does not matter. This call will print errors. */
685 (void) consumer_close_metadata(socket,
aeeb48c6 686 regp->registry->reg.ust->_metadata_key);
7972aab2
DG
687 }
688 break;
689 default:
a0377dfe 690 abort();
36b588ed 691 rcu_read_unlock();
7972aab2
DG
692 return;
693 }
694
36b588ed
MD
695unlock:
696 rcu_read_unlock();
7972aab2
DG
697destroy:
698 call_rcu(&regp->node.head, rcu_free_buffer_reg_uid);
699}
700
701/*
702 * Remove buffer registry UID object from the global hash table. RCU read side
703 * lock MUST be acquired before calling this.
704 */
705void buffer_reg_pid_remove(struct buffer_reg_pid *regp)
706{
707 int ret;
708 struct lttng_ht_iter iter;
709
a0377dfe 710 LTTNG_ASSERT(regp);
7972aab2
DG
711
712 iter.iter.node = &regp->node.node;
713 ret = lttng_ht_del(buffer_registry_pid, &iter);
a0377dfe 714 LTTNG_ASSERT(!ret);
7972aab2
DG
715}
716
717/*
718 * Destroy buffer registry per PID. The pointer is NOT removed from the global
719 * hash table. Call buffer_reg_pid_remove() before that if the object was
720 * previously added to the global hash table.
721 */
722void buffer_reg_pid_destroy(struct buffer_reg_pid *regp)
723{
724 if (!regp) {
725 return;
726 }
727
d9bf3ca4
MD
728 DBG3("Buffer registry per PID destroy with id: %" PRIu64,
729 regp->session_id);
7972aab2
DG
730
731 /* This registry is only used by UST. */
732 call_rcu(&regp->node.head, rcu_free_buffer_reg_pid);
733}
734
735/*
736 * Destroy per PID and UID registry hash table.
737 */
738void buffer_reg_destroy_registries(void)
739{
740 DBG3("Buffer registry destroy all registry");
3c339053
FD
741 lttng_ht_destroy(buffer_registry_uid);
742 lttng_ht_destroy(buffer_registry_pid);
7972aab2 743}
This page took 0.101396 seconds and 4 git commands to generate.