2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; only version 2 of the License.
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., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <lttng-share.h>
27 #include <lttng-sessiond-comm.h>
28 #include <lttng/lttng-consumer.h>
30 #include "hashtable.h"
31 #include "ust-consumer.h"
34 * Send all stream fds of UST channel to the consumer.
36 static int send_channel_streams(int sock
,
37 struct ust_app_channel
*uchan
)
40 struct lttcomm_consumer_msg lum
;
41 struct ltt_ust_stream
*stream
;
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 to make sure this key stays unique within
52 lum
.u
.channel
.channel_key
= uchan
->obj
->shm_fd
;
53 lum
.u
.channel
.max_sb_size
= uchan
->attr
.subbuf_size
;
54 lum
.u
.channel
.mmap_len
= uchan
->obj
->memory_map_size
;
55 DBG("Sending channel %d to consumer", lum
.u
.channel
.channel_key
);
56 ret
= lttcomm_send_unix_sock(sock
, &lum
, sizeof(lum
));
58 perror("send consumer channel");
61 fd
= uchan
->obj
->shm_fd
;
62 ret
= lttcomm_send_fds_unix_sock(sock
, &fd
, 1);
64 perror("send consumer channel ancillary data");
68 cds_list_for_each_entry(stream
, &uchan
->streams
.head
, list
) {
71 if (!stream
->obj
->shm_fd
) {
74 lum
.cmd_type
= LTTNG_CONSUMER_ADD_STREAM
;
75 lum
.u
.stream
.channel_key
= uchan
->obj
->shm_fd
;
76 lum
.u
.stream
.stream_key
= stream
->obj
->shm_fd
;
77 lum
.u
.stream
.state
= LTTNG_CONSUMER_ACTIVE_STREAM
;
78 lum
.u
.stream
.output
= uchan
->attr
.output
;
79 lum
.u
.stream
.mmap_len
= stream
->obj
->memory_map_size
;
80 strncpy(lum
.u
.stream
.path_name
, stream
->pathname
, PATH_MAX
- 1);
81 lum
.u
.stream
.path_name
[PATH_MAX
- 1] = '\0';
82 DBG("Sending stream %d to consumer", lum
.u
.stream
.stream_key
);
83 ret
= lttcomm_send_unix_sock(sock
, &lum
, sizeof(lum
));
85 perror("send consumer stream");
89 fds
[0] = stream
->obj
->shm_fd
;
90 fds
[1] = stream
->obj
->wait_fd
;
91 ret
= lttcomm_send_fds_unix_sock(sock
, fds
, 2);
93 perror("send consumer stream ancillary data");
98 DBG("consumer channel streams sent");
107 * Send all stream fds of the UST session to the consumer.
109 int ust_consumer_send_session(int consumer_fd
, struct ust_app_session
*usess
)
112 int sock
= consumer_fd
;
113 struct cds_lfht_iter iter
;
114 struct cds_lfht_node
*node
;
115 struct lttcomm_consumer_msg lum
;
116 struct ust_app_channel
*uchan
;
118 DBG("Sending metadata stream fd");
120 if (usess
->metadata
->obj
->shm_fd
!= 0) {
124 /* Send metadata channel fd */
125 lum
.cmd_type
= LTTNG_CONSUMER_ADD_CHANNEL
;
126 lum
.u
.channel
.channel_key
= usess
->metadata
->obj
->shm_fd
;
127 lum
.u
.channel
.max_sb_size
= usess
->metadata
->attr
.subbuf_size
;
128 lum
.u
.channel
.mmap_len
= usess
->metadata
->obj
->memory_map_size
;
129 DBG("Sending metadata channel %d to consumer", lum
.u
.channel
.channel_key
);
130 ret
= lttcomm_send_unix_sock(sock
, &lum
, sizeof(lum
));
132 perror("send consumer channel");
135 fd
= usess
->metadata
->obj
->shm_fd
;
136 ret
= lttcomm_send_fds_unix_sock(sock
, &fd
, 1);
138 perror("send consumer metadata channel");
142 /* Send metadata stream fd */
143 lum
.cmd_type
= LTTNG_CONSUMER_ADD_STREAM
;
144 lum
.u
.stream
.channel_key
= usess
->metadata
->obj
->shm_fd
;
145 lum
.u
.stream
.stream_key
= usess
->metadata
->stream_obj
->shm_fd
;
146 lum
.u
.stream
.state
= LTTNG_CONSUMER_ACTIVE_STREAM
;
147 lum
.u
.stream
.output
= DEFAULT_UST_CHANNEL_OUTPUT
;
148 lum
.u
.stream
.mmap_len
= usess
->metadata
->stream_obj
->memory_map_size
;
149 strncpy(lum
.u
.stream
.path_name
, usess
->metadata
->pathname
, PATH_MAX
- 1);
150 lum
.u
.stream
.path_name
[PATH_MAX
- 1] = '\0';
151 DBG("Sending metadata stream %d to consumer", lum
.u
.stream
.stream_key
);
152 ret
= lttcomm_send_unix_sock(sock
, &lum
, sizeof(lum
));
154 perror("send consumer metadata stream");
157 fds
[0] = usess
->metadata
->stream_obj
->shm_fd
;
158 fds
[1] = usess
->metadata
->stream_obj
->wait_fd
;
159 ret
= lttcomm_send_fds_unix_sock(sock
, fds
, 2);
161 perror("send consumer stream");
166 /* Send each channel fd streams of session */
168 hashtable_get_first(usess
->channels
, &iter
);
169 while ((node
= hashtable_iter_get_node(&iter
)) != NULL
) {
170 uchan
= caa_container_of(node
, struct ust_app_channel
, node
);
172 ret
= send_channel_streams(sock
, uchan
);
176 hashtable_get_next(usess
->channels
, &iter
);
180 DBG("consumer fds (metadata and channel streams) sent");