start to handle async rotation on the relay + basics for remote rotate_pending
[deliverable/lttng-tools.git] / src / bin / lttng-sessiond / ust-app.c
index 7f252d53fbedd1adb83a4d046570055d84fac14d..2283f980ae079c53c483f5c9f11e58aa4600b099 100644 (file)
@@ -6279,73 +6279,6 @@ int ust_app_regenerate_statedump_all(struct ltt_ust_session *usess)
        return 0;
 }
 
-static
-int regenerate_per_pid_metadata(struct ltt_ust_session *usess,
-               struct ust_app *app,
-               struct ust_registry_session *registry)
-{
-       int ret;
-       struct ust_registry_channel *chan;
-       struct lttng_ht_iter iter_chan;
-
-       pthread_mutex_lock(&registry->lock);
-       registry->metadata_len_sent = 0;
-       memset(registry->metadata, 0, registry->metadata_alloc_len);
-       registry->metadata_len = 0;
-       registry->metadata_version++;
-
-       fprintf(stderr, "PER_PID REGEN %d\n", registry->metadata_fd);
-#if 0
-       if (registry->metadata_fd > 0) {
-               /* Clear the metadata file's content. */
-               ret = clear_metadata_file(registry->metadata_fd);
-               if (ret) {
-                       pthread_mutex_unlock(&registry->lock);
-                       goto end;
-               }
-       }
-#endif
-
-       ret = ust_metadata_session_statedump(registry, app,
-                       registry->major, registry->minor);
-       if (ret) {
-               pthread_mutex_unlock(&registry->lock);
-               ERR("Failed to generate session metadata (err = %d)",
-                               ret);
-               goto end;
-       }
-       cds_lfht_for_each_entry(registry->channels->ht, &iter_chan.iter,
-                       chan, node.node) {
-               struct ust_registry_event *event;
-               struct lttng_ht_iter iter_event;
-
-               ret = ust_metadata_channel_statedump(registry, chan);
-               if (ret) {
-                       pthread_mutex_unlock(&registry->lock);
-                       ERR("Failed to generate channel metadata "
-                                       "(err = %d)", ret);
-                       goto end;
-               }
-               cds_lfht_for_each_entry(chan->ht->ht, &iter_event.iter,
-                               event, node.node) {
-                       ret = ust_metadata_event_statedump(registry,
-                                       chan, event);
-                       if (ret) {
-                               pthread_mutex_unlock(&registry->lock);
-                               ERR("Failed to generate event metadata "
-                                               "(err = %d)", ret);
-                               goto end;
-                       }
-               }
-       }
-       pthread_mutex_unlock(&registry->lock);
-
-       ret = 0;
-
-end:
-       return ret;
-}
-
 /*
  * Rotate all the channels of a session.
  *
@@ -6353,7 +6286,7 @@ end:
  */
 int ust_app_rotate_session(struct ltt_session *session)
 {
-       int ret = 0;
+       int ret = 0, nr_channels = 0, nr_app = 0;
        struct lttng_ht_iter iter;
        struct ust_app *app;
        struct ltt_ust_session *usess = session->ust_session;
@@ -6379,6 +6312,7 @@ int ust_app_rotate_session(struct ltt_session *session)
                        struct buffer_reg_channel *reg_chan;
                        struct consumer_socket *socket;
 
+                       nr_channels++;
                        /* Get consumer socket to use to push the metadata.*/
                        socket = consumer_find_socket_by_bitness(reg->bits_per_long,
                                        usess->consumer);
@@ -6425,7 +6359,8 @@ int ust_app_rotate_session(struct ltt_session *session)
                                ret = consumer_rotate_channel(socket,
                                                reg_chan->consumer_key,
                                                usess->uid, usess->gid,
-                                               usess->consumer, pathname, 0);
+                                               usess->consumer, pathname, 0,
+                                               session->rotate_count);
                                if (ret < 0) {
                                        goto error;
                                }
@@ -6436,12 +6371,11 @@ int ust_app_rotate_session(struct ltt_session *session)
                        ret = consumer_rotate_channel(socket,
                                        reg->registry->reg.ust->metadata_key,
                                        usess->uid, usess->gid,
-                                       usess->consumer, pathname, 1);
+                                       usess->consumer, pathname, 1,
+                                       session->rotate_count);
                        if (ret < 0) {
                                goto error;
                        }
-
-                       /* TODO: regenerate metadata here instead of at the end ? */
                }
                break;
        }
@@ -6459,6 +6393,7 @@ int ust_app_rotate_session(struct ltt_session *session)
                                /* Session not associated with this app. */
                                continue;
                        }
+                       nr_app++;
                        ret = snprintf(pathname, PATH_MAX, DEFAULT_UST_TRACE_DIR "/%s",
                                        ua_sess->path);
                        if (ret < 0) {
@@ -6508,7 +6443,8 @@ int ust_app_rotate_session(struct ltt_session *session)
                                }
                                ret = consumer_rotate_channel(socket, ua_chan->key,
                                                ua_sess->euid, ua_sess->egid,
-                                               ua_sess->consumer, pathname, 0);
+                                               ua_sess->consumer, pathname, 0,
+                                               session->rotate_count);
                                if (ret < 0) {
                                        goto error;
                                }
@@ -6518,17 +6454,11 @@ int ust_app_rotate_session(struct ltt_session *session)
                        (void) push_metadata(registry, usess->consumer);
                        ret = consumer_rotate_channel(socket, registry->metadata_key,
                                        ua_sess->euid, ua_sess->egid,
-                                       ua_sess->consumer, pathname, 1);
+                                       ua_sess->consumer, pathname, 1,
+                                       session->rotate_count);
                        if (ret < 0) {
                                goto error;
                        }
-
-                       /*
-                       ret = regenerate_per_pid_metadata(usess, app, registry);
-                       if (ret < 0) {
-                               goto error;
-                       }
-                       */
                }
                break;
        }
@@ -6537,6 +6467,11 @@ int ust_app_rotate_session(struct ltt_session *session)
                break;
        }
 
+       if (nr_app == 0 && nr_channels == 0) {
+               session->rotate_pending = 0;
+               session->rotate_status = LTTNG_ROTATE_EMPTY;
+       }
+
        ret = LTTNG_OK;
 
 error:
This page took 0.026723 seconds and 5 git commands to generate.