Use the trace format type for ust metadata generation
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.cpp
CommitLineData
d0b96690 1/*
ab5be9fa 2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
d0b96690 3 *
ab5be9fa 4 * SPDX-License-Identifier: GPL-2.0-only
d0b96690 5 *
d0b96690 6 */
890d8fe4 7
6c1c0768 8#define _LGPL_SOURCE
7972aab2 9
c9e313bc 10#include "ust-registry.hpp"
c9e313bc
SM
11#include "lttng-sessiond.hpp"
12#include "notification-thread-commands.hpp"
d7bfb9b0 13#include "ust-app.hpp"
b0f2e8db
JG
14#include "ust-registry-session-pid.hpp"
15#include "ust-registry-session-uid.hpp"
d7bfb9b0 16#include "utils.hpp"
d0b96690 17
d7bfb9b0
JG
18#include <common/common.hpp>
19#include <common/exception.hpp>
20#include <common/format.hpp>
21#include <common/hashtable/utils.hpp>
22#include <common/make-unique-wrapper.hpp>
23#include <lttng/lttng.h>
c4d702e6 24#include <lttng/trace-format-descriptor-internal.hpp>
10b56aef 25
d7bfb9b0 26#include <inttypes.h>
3b016e58 27
d7bfb9b0
JG
28namespace ls = lttng::sessiond;
29namespace lst = lttng::sessiond::trace;
30namespace lsu = lttng::sessiond::ust;
10b56aef 31
d0b96690
DG
32/*
33 * Destroy event function call of the call RCU.
34 */
d7bfb9b0 35static void ust_registry_event_destroy_rcu(struct rcu_head *head)
d0b96690 36{
d7bfb9b0
JG
37 DIAGNOSTIC_PUSH
38 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
39 lttng::sessiond::ust::registry_event *event =
f139a4f9 40 lttng::utils::container_of(head, &lttng::sessiond::ust::registry_event::_head);
d7bfb9b0
JG
41 DIAGNOSTIC_POP
42
43 lttng::sessiond::ust::registry_event_destroy(event);
d0b96690
DG
44}
45
46/*
47 * For a given event in a registry, delete the entry and destroy the event.
48 * This MUST be called within a RCU read side lock section.
49 */
d7bfb9b0
JG
50void ust_registry_channel_destroy_event(lsu::registry_channel *chan,
51 lttng::sessiond::ust::registry_event *event)
d0b96690
DG
52{
53 int ret;
54 struct lttng_ht_iter iter;
55
a0377dfe
FD
56 LTTNG_ASSERT(chan);
57 LTTNG_ASSERT(event);
48b7cdc2 58 ASSERT_RCU_READ_LOCKED();
d0b96690
DG
59
60 /* Delete the node first. */
f139a4f9 61 iter.iter.node = &event->_node;
d7bfb9b0 62 ret = lttng_ht_del(chan->_events, &iter);
a0377dfe 63 LTTNG_ASSERT(!ret);
d0b96690 64
f139a4f9 65 call_rcu(&event->_head, ust_registry_event_destroy_rcu);
d0b96690
DG
66
67 return;
68}
69
b0f2e8db 70lsu::registry_session *ust_registry_session_per_uid_create(const lttng::sessiond::trace::abi& abi,
af6142cf 71 uint32_t major,
d7ba1388 72 uint32_t minor,
3d071855 73 const char *root_shm_path,
d7ba1388
MD
74 const char *shm_path,
75 uid_t euid,
8de88061
JR
76 gid_t egid,
77 uint64_t tracing_id,
c4d702e6
JR
78 uid_t tracing_uid,
79 const lttng::trace_format_descriptor& trace_format)
d0b96690 80{
aeeb48c6 81 try {
b0f2e8db 82 return new lsu::registry_session_per_uid(abi, major, minor, root_shm_path, shm_path,
c4d702e6 83 euid, egid, tracing_id, tracing_uid, trace_format);
d7bfb9b0 84 } catch (const std::exception& ex) {
aeeb48c6
JG
85 ERR("Failed to create per-uid registry session: %s", ex.what());
86 return nullptr;
d7ba1388 87 }
aeeb48c6 88}
8de88061 89
b0f2e8db 90lsu::registry_session *ust_registry_session_per_pid_create(struct ust_app *app,
d7bfb9b0 91 const lttng::sessiond::trace::abi& abi,
aeeb48c6
JG
92 uint32_t major,
93 uint32_t minor,
94 const char *root_shm_path,
95 const char *shm_path,
96 uid_t euid,
97 gid_t egid,
c4d702e6
JR
98 uint64_t tracing_id,
99 const lttng::trace_format_descriptor& trace_format)
aeeb48c6
JG
100{
101 try {
b0f2e8db 102 return new lsu::registry_session_per_pid(*app, abi, major, minor, root_shm_path,
c4d702e6 103 shm_path, euid, egid, tracing_id, trace_format);
d7bfb9b0 104 } catch (const std::exception& ex) {
aeeb48c6
JG
105 ERR("Failed to create per-pid registry session: %s", ex.what());
106 return nullptr;
d0b96690 107 }
d0b96690
DG
108}
109
110/*
111 * Destroy session registry. This does NOT free the given pointer since it
112 * might get passed as a reference. The registry lock should NOT be acquired.
113 */
b0f2e8db 114void ust_registry_session_destroy(lsu::registry_session *reg)
d0b96690 115{
aeeb48c6 116 delete reg;
d0b96690 117}
d7bfb9b0
JG
118
119lsu::registry_enum::registry_enum(
120 std::string in_name, enum lst::integer_type::signedness in_signedness) :
121 name{std::move(in_name)}, signedness{in_signedness}
122{
123 cds_lfht_node_init(&this->node.node);
124 this->rcu_head = {};
125}
126
127bool lsu::operator==(const lsu::registry_enum& lhs, const lsu::registry_enum& rhs) noexcept
128{
129 if (lhs.signedness != rhs.signedness) {
130 return false;
131 }
132
133 return lhs._is_equal(rhs);
134}
This page took 0.101058 seconds and 5 git commands to generate.