+/*
+ * Create UST app event and create it on the tracer side.
+ */
+static struct ust_app_event *create_ust_app_event(
+ struct ust_app_session *ua_sess, struct ust_app_channel *ua_chan,
+ struct ltt_ust_event *uevent, struct ust_app *app)
+{
+ int ret;
+ struct cds_lfht_iter iter;
+ struct cds_lfht_node *ua_event_node;
+ struct ust_app_event *ua_event;
+
+ /* Get event node */
+ ua_event_node = hashtable_lookup(ua_chan->events,
+ (void *)uevent->attr.name, strlen(uevent->attr.name), &iter);
+ if (ua_event_node == NULL) {
+ DBG2("UST app event %s not found, creating it", uevent->attr.name);
+ /* Does not exist so create one */
+ ua_event = alloc_ust_app_event(uevent->attr.name, &uevent->attr);
+ if (ua_event == NULL) {
+ /* Only malloc can failed so something is really wrong */
+ goto error;
+ }
+ shadow_copy_event(ua_event, uevent);
+
+ hashtable_add_unique(ua_chan->events, &ua_event->node);
+ } else {
+ ua_event = caa_container_of(ua_event_node, struct ust_app_event, node);
+ }
+
+ ret = create_ust_event(app, ua_sess, ua_chan, ua_event);
+ if (ret < 0) {
+ goto error;
+ }
+
+ return ua_event;
+
+error:
+ return NULL;
+}
+
+/*
+ * Create UST metadata and open it on the tracer side.
+ */
+static int create_ust_app_metadata(struct ust_app_session *ua_sess,
+ char *pathname, struct ust_app *app)
+{
+ int ret = 0;
+
+ if (ua_sess->metadata == NULL) {
+ /* Allocate UST metadata */
+ ua_sess->metadata = trace_ust_create_metadata(pathname);
+ if (ua_sess->metadata == NULL) {
+ ERR("UST app session %d creating metadata failed",
+ ua_sess->handle);
+ goto error;
+ }
+
+ ret = open_ust_metadata(app, ua_sess);