Fix disable/enable channel when app registers
authorDavid Goulet <david.goulet@polymtl.ca>
Tue, 29 Nov 2011 23:15:25 +0000 (18:15 -0500)
committerDavid Goulet <david.goulet@polymtl.ca>
Tue, 29 Nov 2011 23:15:25 +0000 (18:15 -0500)
Upon registration, a disable channel in the global domain was created
but not disabled afterwords being enabled by default on the tracer. This
commit fix that for channels and events as well.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
lttng-sessiond/main.c
lttng-sessiond/ust-app.c

index 7e4000a0fd1183365a9ccc7746e47297f0cb9d66..7d898a94e19938ebbe697ef686d3b3bef95d9091 100644 (file)
@@ -2191,6 +2191,12 @@ static int cmd_disable_channel(struct ltt_session *session,
                        goto error;
                }
 
                        goto error;
                }
 
+               /* Already disabled */
+               if (!uchan->enabled) {
+                       DBG2("UST channel %s already disabled", channel_name);
+                       break;
+               }
+
                ret = ust_app_disable_channel_glb(usess, uchan);
                if (ret < 0) {
                        ret = LTTCOMM_UST_DISABLE_FAIL;
                ret = ust_app_disable_channel_glb(usess, uchan);
                if (ret < 0) {
                        ret = LTTCOMM_UST_DISABLE_FAIL;
@@ -2299,28 +2305,32 @@ static int cmd_enable_channel(struct ltt_session *session,
                                goto error;
                        }
 
                                goto error;
                        }
 
-                       rcu_read_lock();
-                       hashtable_add_unique(usess->domain_global.channels, &uchan->node);
-                       rcu_read_unlock();
-                       DBG2("UST channel %s added to global domain HT", attr->name);
-
                        /* Add channel to all registered applications */
                        ret = ust_app_create_channel_glb(usess, uchan);
                        if (ret != 0) {
                                ret = LTTCOMM_UST_CHAN_FAIL;
                                goto error;
                        }
                        /* Add channel to all registered applications */
                        ret = ust_app_create_channel_glb(usess, uchan);
                        if (ret != 0) {
                                ret = LTTCOMM_UST_CHAN_FAIL;
                                goto error;
                        }
+
+                       rcu_read_lock();
+                       hashtable_add_unique(usess->domain_global.channels, &uchan->node);
+                       rcu_read_unlock();
+
+                       DBG2("UST channel %s added to global domain HT", attr->name);
                } else {
                        /* If already enabled, everything is OK */
                        if (uchan->enabled) {
                } else {
                        /* If already enabled, everything is OK */
                        if (uchan->enabled) {
-                               ret = LTTCOMM_OK;
-                               goto error;
+                               break;
                        }
 
                        ret = ust_app_enable_channel_glb(usess, uchan);
                        if (ret < 0) {
                        }
 
                        ret = ust_app_enable_channel_glb(usess, uchan);
                        if (ret < 0) {
-                               ret = LTTCOMM_UST_ENABLE_FAIL;
-                               goto error;
+                               if (ret != -EEXIST) {
+                                       ret = LTTCOMM_UST_CHAN_ENABLE_FAIL;
+                                       goto error;
+                               } else {
+                                       ret = LTTCOMM_OK;
+                               }
                        }
                }
 
                        }
                }
 
index 3f4c4c661fb4aa10d8bb6680c1687d9f6b23ad0b..b6dd76ae9c0fec891f8ce2f3c3f5af6b6bb5b8d9 100644 (file)
@@ -288,8 +288,6 @@ static int disable_ust_channel(struct ust_app *app,
                goto error;
        }
 
                goto error;
        }
 
-       ua_chan->enabled = 0;
-
        DBG2("UST app channel %s disabled successfully for app (pid: %d)",
                        ua_chan->name, app->key.pid);
 
        DBG2("UST app channel %s disabled successfully for app (pid: %d)",
                        ua_chan->name, app->key.pid);
 
@@ -422,6 +420,14 @@ static int create_ust_channel(struct ust_app *app,
        DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
                        ua_chan->name, app->key.pid, app->key.sock);
 
        DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
                        ua_chan->name, app->key.pid, app->key.sock);
 
+       /* If channel is not enabled, disable it on the tracer */
+       if (!ua_chan->enabled) {
+               ret = disable_ust_channel(app, ua_sess, ua_chan);
+               if (ret < 0) {
+                       goto error;
+               }
+       }
+
 error:
        return ret;
 }
 error:
        return ret;
 }
@@ -445,11 +451,18 @@ int create_ust_event(struct ust_app *app, struct ust_app_session *ua_sess,
        }
 
        ua_event->handle = ua_event->obj->handle;
        }
 
        ua_event->handle = ua_event->obj->handle;
-       ua_event->enabled = 1;
 
        DBG2("UST app event %s created successfully for pid:%d",
                        ua_event->attr.name, app->key.pid);
 
 
        DBG2("UST app event %s created successfully for pid:%d",
                        ua_event->attr.name, app->key.pid);
 
+       /* If event not enabled, disable it on the tracer */
+       if (!ua_event->enabled) {
+               ret = disable_ust_event(app, ua_sess, ua_event);
+               if (ret < 0) {
+                       goto error;
+               }
+       }
+
 error:
        return ret;
 }
 error:
        return ret;
 }
@@ -496,6 +509,7 @@ static struct ust_app_channel *alloc_ust_app_channel(char *name,
        strncpy(ua_chan->name, name, sizeof(ua_chan->name));
        ua_chan->name[sizeof(ua_chan->name) - 1] = '\0';
 
        strncpy(ua_chan->name, name, sizeof(ua_chan->name));
        ua_chan->name[sizeof(ua_chan->name) - 1] = '\0';
 
+       ua_chan->enabled = 1;
        ua_chan->handle = -1;
        ua_chan->ctx = hashtable_new(0);
        ua_chan->events = hashtable_new_str(0);
        ua_chan->handle = -1;
        ua_chan->ctx = hashtable_new(0);
        ua_chan->events = hashtable_new_str(0);
@@ -532,6 +546,7 @@ static struct ust_app_event *alloc_ust_app_event(char *name,
                goto error;
        }
 
                goto error;
        }
 
+       ua_event->enabled = 1;
        strncpy(ua_event->name, name, sizeof(ua_event->name));
        ua_event->name[sizeof(ua_event->name) - 1] = '\0';
        ua_event->ctx = hashtable_new(0);
        strncpy(ua_event->name, name, sizeof(ua_event->name));
        ua_event->name[sizeof(ua_event->name) - 1] = '\0';
        ua_event->ctx = hashtable_new(0);
@@ -798,29 +813,19 @@ error:
 /*
  * Lookup ust app channel for session and disable it on the tracer side.
  */
 /*
  * Lookup ust app channel for session and disable it on the tracer side.
  */
-static int disable_ust_app_channel(struct ust_app_session *ua_sess,
-               struct ltt_ust_channel *uchan, struct ust_app *app)
+static
+int disable_ust_app_channel(struct ust_app_session *ua_sess,
+               struct ust_app_channel *ua_chan, struct ust_app *app)
 {
 {
-       int ret = 0;
-       struct cds_lfht_iter iter;
-       struct cds_lfht_node *ua_chan_node;
-       struct ust_app_channel *ua_chan;
-
-       ua_chan_node = hashtable_lookup(ua_sess->channels,
-                       (void *)uchan->name, strlen(uchan->name), &iter);
-       if (ua_chan_node == NULL) {
-               DBG2("Unable to find channel %s in ust session uid %u",
-                               uchan->name, ua_sess->uid);
-               goto error;
-       }
-
-       ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+       int ret;
 
        ret = disable_ust_channel(app, ua_sess, ua_chan);
        if (ret < 0) {
                goto error;
        }
 
 
        ret = disable_ust_channel(app, ua_sess, ua_chan);
        if (ret < 0) {
                goto error;
        }
 
+       ua_chan->enabled = 0;
+
 error:
        return ret;
 }
 error:
        return ret;
 }
@@ -933,6 +938,8 @@ int create_ust_app_event(struct ust_app_session *ua_sess,
                goto error;
        }
 
                goto error;
        }
 
+       ua_event->enabled = 1;
+
        hashtable_add_unique(ua_chan->events, &ua_event->node);
 
 end:
        hashtable_add_unique(ua_chan->events, &ua_event->node);
 
 end:
@@ -1242,8 +1249,10 @@ int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
 {
        int ret = 0;
        struct cds_lfht_iter iter;
 {
        int ret = 0;
        struct cds_lfht_iter iter;
+       struct cds_lfht_node *ua_chan_node;
        struct ust_app *app;
        struct ust_app_session *ua_sess;
        struct ust_app *app;
        struct ust_app_session *ua_sess;
+       struct ust_app_channel *ua_chan;
 
        if (usess == NULL || uchan == NULL) {
                ERR("Disabling UST global channel with NULL values");
 
        if (usess == NULL || uchan == NULL) {
                ERR("Disabling UST global channel with NULL values");
@@ -1251,7 +1260,7 @@ int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
                goto error;
        }
 
                goto error;
        }
 
-       DBG2("UST app disablling channel %s from global domain for session uid %d",
+       DBG2("UST app disabling channel %s from global domain for session uid %d",
                        uchan->name, usess->uid);
 
        rcu_read_lock();
                        uchan->name, usess->uid);
 
        rcu_read_lock();
@@ -1263,8 +1272,18 @@ int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
                        continue;
                }
 
                        continue;
                }
 
-               /* Create channel onto application */
-               ret = disable_ust_app_channel(ua_sess, uchan, app);
+               /* Get channel */
+               ua_chan_node = hashtable_lookup(ua_sess->channels,
+                               (void *)uchan->name, strlen(uchan->name), &iter);
+               /* If the session if found for the app, the channel must be there */
+               assert(ua_chan_node);
+
+               ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+               /* The channel must not be already disabled */
+               assert(ua_chan->enabled == 1);
+
+               /* Disable channel onto application */
+               ret = disable_ust_app_channel(ua_sess, ua_chan, app);
                if (ret < 0) {
                        /* XXX: We might want to report this error at some point... */
                        continue;
                if (ret < 0) {
                        /* XXX: We might want to report this error at some point... */
                        continue;
This page took 0.030349 seconds and 4 git commands to generate.