2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <common/common.h>
26 #include <common/consumer.h>
27 #include <common/defaults.h>
28 #include <common/sessiond-comm/sessiond-comm.h>
30 #include "ust-consumer.h"
33 * Send all stream fds of UST channel to the consumer.
35 static int send_channel_streams(int sock
,
36 struct ust_app_channel
*uchan
,
40 struct lttcomm_consumer_msg lum
;
41 struct ltt_ust_stream
*stream
, *tmp
;
43 DBG("Sending streams of channel %s to UST consumer", uchan
->name
);
46 lum
.cmd_type
= LTTNG_CONSUMER_ADD_CHANNEL
;
49 * We need to keep shm_fd open while we transfer the stream file
50 * descriptors to make sure this key stays unique within the
51 * session daemon. We can free the channel shm_fd without
52 * problem after we finished sending stream fds for that
55 lum
.u
.channel
.channel_key
= uchan
->obj
->shm_fd
;
56 lum
.u
.channel
.max_sb_size
= uchan
->attr
.subbuf_size
;
57 lum
.u
.channel
.mmap_len
= uchan
->obj
->memory_map_size
;
58 DBG("Sending channel %d to consumer", lum
.u
.channel
.channel_key
);
59 ret
= lttcomm_send_unix_sock(sock
, &lum
, sizeof(lum
));
61 PERROR("send consumer channel");
65 DBG("Sending channel shm path: %s\n", uchan
->obj
->shm_path
);
66 ret
= lttcomm_send_string(sock
,
68 strlen(uchan
->obj
->shm_path
));
70 PERROR("send consumer channel shm path");
74 cds_list_for_each_entry_safe(stream
, tmp
, &uchan
->streams
.head
, list
) {
76 if (!stream
->obj
->shm_fd
) {
79 lum
.cmd_type
= LTTNG_CONSUMER_ADD_STREAM
;
80 lum
.u
.stream
.channel_key
= uchan
->obj
->shm_fd
;
81 lum
.u
.stream
.stream_key
= stream
->obj
->shm_fd
;
82 lum
.u
.stream
.state
= LTTNG_CONSUMER_ACTIVE_STREAM
;
84 * FIXME Hack alert! we force MMAP for now. Mixup
85 * between EVENT and UST enums elsewhere.
87 lum
.u
.stream
.output
= DEFAULT_UST_CHANNEL_OUTPUT
;
88 lum
.u
.stream
.mmap_len
= stream
->obj
->memory_map_size
;
89 lum
.u
.stream
.uid
= uid
;
90 lum
.u
.stream
.gid
= gid
;
91 strncpy(lum
.u
.stream
.path_name
, stream
->pathname
, PATH_MAX
- 1);
92 lum
.u
.stream
.path_name
[PATH_MAX
- 1] = '\0';
93 DBG("Sending stream %d to consumer", lum
.u
.stream
.stream_key
);
94 ret
= lttcomm_send_unix_sock(sock
, &lum
, sizeof(lum
));
96 PERROR("send consumer stream");
100 DBG("Sending stream shm path: %s\n", stream
->obj
->shm_path
);
101 ret
= lttcomm_send_string(sock
,
102 stream
->obj
->shm_path
,
103 strlen(stream
->obj
->shm_path
));
105 PERROR("send consumer stream shm path");
109 DBG("Sending stream wait pipe path: %s\n", stream
->obj
->wait_pipe_path
);
110 ret
= lttcomm_send_string(sock
,
111 stream
->obj
->wait_pipe_path
,
112 strlen(stream
->obj
->wait_pipe_path
));
115 PERROR("send consumer stream wait pipe path");
120 DBG("consumer channel streams sent");
129 * Send all stream fds of the UST session to the consumer.
131 int ust_consumer_send_session(int consumer_fd
, struct ust_app_session
*usess
)
134 int sock
= consumer_fd
;
135 struct lttng_ht_iter iter
;
136 struct lttcomm_consumer_msg lum
;
137 struct ust_app_channel
*ua_chan
;
139 DBG("Sending metadata stream fd");
141 if (consumer_fd
< 0) {
142 ERR("Consumer has negative file descriptor");
146 if (usess
->metadata
->obj
->shm_fd
!= 0) {
147 /* Send metadata channel fd */
148 lum
.cmd_type
= LTTNG_CONSUMER_ADD_CHANNEL
;
149 lum
.u
.channel
.channel_key
= usess
->metadata
->obj
->shm_fd
;
150 lum
.u
.channel
.max_sb_size
= usess
->metadata
->attr
.subbuf_size
;
151 lum
.u
.channel
.mmap_len
= usess
->metadata
->obj
->memory_map_size
;
152 DBG("Sending metadata channel %d to consumer", lum
.u
.channel
.channel_key
);
153 ret
= lttcomm_send_unix_sock(sock
, &lum
, sizeof(lum
));
155 PERROR("send consumer channel");
159 DBG("Sending metadata channel shm path: %s\n", usess
->metadata
->obj
->shm_path
);
160 ret
= lttcomm_send_string(sock
,
161 usess
->metadata
->obj
->shm_path
,
162 strlen(usess
->metadata
->obj
->shm_path
));
164 PERROR("send consumer metadata channel");
168 /* Send metadata stream fd */
169 lum
.cmd_type
= LTTNG_CONSUMER_ADD_STREAM
;
170 lum
.u
.stream
.channel_key
= usess
->metadata
->obj
->shm_fd
;
171 lum
.u
.stream
.stream_key
= usess
->metadata
->stream_obj
->shm_fd
;
172 lum
.u
.stream
.state
= LTTNG_CONSUMER_ACTIVE_STREAM
;
173 lum
.u
.stream
.output
= DEFAULT_UST_CHANNEL_OUTPUT
;
174 lum
.u
.stream
.mmap_len
= usess
->metadata
->stream_obj
->memory_map_size
;
175 lum
.u
.stream
.uid
= usess
->uid
;
176 lum
.u
.stream
.gid
= usess
->gid
;
177 strncpy(lum
.u
.stream
.path_name
, usess
->metadata
->pathname
, PATH_MAX
- 1);
178 lum
.u
.stream
.path_name
[PATH_MAX
- 1] = '\0';
179 DBG("Sending metadata stream %d to consumer", lum
.u
.stream
.stream_key
);
180 ret
= lttcomm_send_unix_sock(sock
, &lum
, sizeof(lum
));
182 PERROR("send consumer metadata stream");
186 DBG("Sending metadata stream shm path: %s\n",
187 usess
->metadata
->stream_obj
->shm_path
);
188 ret
= lttcomm_send_string(sock
,
189 usess
->metadata
->stream_obj
->shm_path
,
190 strlen(usess
->metadata
->stream_obj
->shm_path
));
193 PERROR("send consumer shm stream");
197 DBG("Sending metadata stream wait pipe path: %s\n",
198 usess
->metadata
->stream_obj
->wait_pipe_path
);
199 ret
= lttcomm_send_string(sock
,
200 usess
->metadata
->stream_obj
->wait_pipe_path
,
201 strlen(usess
->metadata
->stream_obj
->wait_pipe_path
));
204 PERROR("send consumer shm stream");
210 /* Send each channel fd streams of session */
212 cds_lfht_for_each_entry(usess
->channels
->ht
, &iter
.iter
, ua_chan
,
215 * Indicate that the channel was not created on the tracer side so skip
216 * sending unexisting streams.
218 if (ua_chan
->obj
== NULL
) {
222 ret
= send_channel_streams(sock
, ua_chan
, usess
->uid
, usess
->gid
);
230 DBG("consumer fds (metadata and channel streams) sent");