c8dd848b1dfafe49778ecdeba6c3dcd0b5c81ed5
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; only version 2
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include "hashtable.h"
31 #include "../hashtable/hash.h"
34 * Delete a traceable application structure from the global list.
36 static void delete_ust_app(struct ust_app
*lta
)
39 struct cds_lfht_node
*node
;
40 struct cds_lfht_iter iter
;
44 hashtable_get_first(lta
->channels
, &iter
);
45 while ((node
= hashtable_iter_get_node(&iter
)) != NULL
) {
46 ret
= hashtable_del(lta
->channels
, &iter
);
48 trace_ust_destroy_channel(
49 caa_container_of(node
, struct ltt_ust_channel
, node
));
51 hashtable_get_next(lta
->channels
, &iter
);
57 /* Remove from apps hash table */
58 node
= hashtable_lookup(ust_app_ht
,
59 (void *) ((unsigned long) lta
->key
.pid
), sizeof(void *), &iter
);
61 ERR("UST app pid %d not found in hash table", lta
->key
.pid
);
63 ret
= hashtable_del(ust_app_ht
, &iter
);
65 ERR("UST app unable to delete app %d from hash table",
68 DBG2("UST app pid %d deleted", lta
->key
.pid
);
72 /* Remove from key hash table */
73 node
= hashtable_lookup(ust_app_sock_key_map
,
74 (void *) ((unsigned long) lta
->key
.sock
), sizeof(void *), &iter
);
76 ERR("UST app key %d not found in key hash table", lta
->key
.sock
);
78 ret
= hashtable_del(ust_app_sock_key_map
, &iter
);
80 ERR("UST app unable to delete app sock %d from key hash table",
83 DBG2("UST app pair sock %d key %d deleted",
84 lta
->key
.sock
, lta
->key
.pid
);
94 * URCU intermediate call to delete an UST app.
96 static void delete_ust_app_rcu(struct rcu_head
*head
)
98 struct cds_lfht_node
*node
=
99 caa_container_of(head
, struct cds_lfht_node
, head
);
100 struct ust_app
*app
=
101 caa_container_of(node
, struct ust_app
, node
);
107 * Find an ust_app using the sock and return it.
109 static struct ust_app
*find_app_by_sock(int sock
)
111 struct cds_lfht_node
*node
;
112 struct ust_app_key
*key
;
113 struct cds_lfht_iter iter
;
114 //struct ust_app *app;
118 node
= hashtable_lookup(ust_app_sock_key_map
,
119 (void *)((unsigned long) sock
), sizeof(void *), &iter
);
121 DBG2("UST app find by sock %d key not found", sock
);
126 key
= caa_container_of(node
, struct ust_app_key
, node
);
128 node
= hashtable_lookup(ust_app_ht
,
129 (void *)((unsigned long) key
->pid
), sizeof(void *), &iter
);
131 DBG2("UST app find by sock %d not found", sock
);
137 return caa_container_of(node
, struct ust_app
, node
);
144 * Return pointer to traceable apps list.
146 struct cds_lfht
*ust_app_get_ht(void)
152 * Return ust app pointer or NULL if not found.
154 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
156 struct cds_lfht_node
*node
;
157 struct cds_lfht_iter iter
;
160 node
= hashtable_lookup(ust_app_ht
,
161 (void *)((unsigned long) pid
), sizeof(void *), &iter
);
164 DBG2("UST app no found with pid %d", pid
);
169 DBG2("Found UST app by pid %d", pid
);
171 return caa_container_of(node
, struct ust_app
, node
);
178 * Using pid and uid (of the app), allocate a new ust_app struct and
179 * add it to the global traceable app list.
181 * On success, return 0, else return malloc ENOMEM.
183 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
187 lta
= malloc(sizeof(struct ust_app
));
195 lta
->key
.pid
= msg
->pid
;
196 lta
->ppid
= msg
->ppid
;
197 lta
->v_major
= msg
->major
;
198 lta
->v_minor
= msg
->minor
;
199 lta
->key
.sock
= sock
;
200 strncpy(lta
->name
, msg
->name
, sizeof(lta
->name
));
201 lta
->name
[16] = '\0';
202 hashtable_node_init(<a
->node
, (void *)((unsigned long)lta
->key
.pid
),
204 lta
->channels
= hashtable_new_str(0);
206 /* Set sock key map */
207 hashtable_node_init(<a
->key
.node
, (void *)((unsigned long)lta
->key
.sock
),
211 hashtable_add_unique(ust_app_ht
, <a
->node
);
212 hashtable_add_unique(ust_app_sock_key_map
, <a
->key
.node
);
215 DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
216 " (version %d.%d)", lta
->key
.pid
, lta
->ppid
, lta
->uid
, lta
->gid
,
217 lta
->key
.sock
, lta
->name
, lta
->v_major
, lta
->v_minor
);
223 * Unregister app by removing it from the global traceable app list and freeing
226 * The socket is already closed at this point so no close to sock.
228 void ust_app_unregister(int sock
)
232 DBG2("UST app unregistering sock %d", sock
);
234 lta
= find_app_by_sock(sock
);
236 DBG("PID %d unregistering with sock %d", lta
->key
.pid
, sock
);
237 /* FIXME: Better use a call_rcu here ? */
243 * Return traceable_app_count
245 unsigned long ust_app_list_count(void)
250 count
= hashtable_get_count(ust_app_ht
);
257 * Free and clean all traceable apps of the global list.
259 void ust_app_clean_list(void)
262 struct cds_lfht_node
*node
;
263 struct cds_lfht_iter iter
;
265 DBG2("UST app clean hash table");
269 hashtable_get_first(ust_app_ht
, &iter
);
270 while ((node
= hashtable_iter_get_node(&iter
)) != NULL
) {
271 ret
= hashtable_del(ust_app_ht
, &iter
);
273 call_rcu(&node
->head
, delete_ust_app_rcu
);
275 hashtable_get_next(ust_app_ht
, &iter
);
282 * Init UST app hash table.
284 void ust_app_ht_alloc(void)
286 ust_app_ht
= hashtable_new(0);
287 ust_app_sock_key_map
= hashtable_new(0);
This page took 0.03493 seconds and 3 git commands to generate.