Fix: support temporary snapshot max size and name
authorDavid Goulet <dgoulet@efficios.com>
Thu, 11 Jul 2013 18:51:35 +0000 (14:51 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 12 Jul 2013 15:18:28 +0000 (11:18 -0400)
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/snapshot.c
src/bin/lttng-sessiond/ust-app.c
src/bin/lttng/commands/snapshot.c
src/lib/lttng-ctl/snapshot.c

index c522d51c2dc27e46efa08ccb7f85085e16e4e4d3..6000d198ca2c153b5791e57f7fd4e63f75a47e02 100644 (file)
@@ -2576,7 +2576,8 @@ int cmd_snapshot_record(struct ltt_session *session,
                struct lttng_snapshot_output *output, int wait)
 {
        int ret = LTTNG_OK;
-       struct snapshot_output *tmp_sout = NULL;
+       unsigned int use_tmp_output = 0;
+       struct snapshot_output tmp_output;
        unsigned int nb_streams;
 
        assert(session);
@@ -2600,15 +2601,9 @@ int cmd_snapshot_record(struct ltt_session *session,
 
        /* Use temporary output for the session. */
        if (output && *output->ctrl_url != '\0') {
-               tmp_sout = snapshot_output_alloc();
-               if (!tmp_sout) {
-                       ret = LTTNG_ERR_NOMEM;
-                       goto error;
-               }
-
                ret = snapshot_output_init(output->max_size, output->name,
                                output->ctrl_url, output->data_url, session->consumer,
-                               tmp_sout, NULL);
+                               &tmp_output, NULL);
                if (ret < 0) {
                        if (ret == -ENOMEM) {
                                ret = LTTNG_ERR_NOMEM;
@@ -2617,6 +2612,7 @@ int cmd_snapshot_record(struct ltt_session *session,
                        }
                        goto error;
                }
+               use_tmp_output = 1;
        }
 
        /*
@@ -2628,8 +2624,8 @@ int cmd_snapshot_record(struct ltt_session *session,
        if (session->kernel_session) {
                struct ltt_kernel_session *ksess = session->kernel_session;
 
-               if (tmp_sout) {
-                       ret = record_kernel_snapshot(ksess, tmp_sout, session,
+               if (use_tmp_output) {
+                       ret = record_kernel_snapshot(ksess, &tmp_output, session,
                                        wait, nb_streams);
                        if (ret < 0) {
                                goto error;
@@ -2641,7 +2637,25 @@ int cmd_snapshot_record(struct ltt_session *session,
                        rcu_read_lock();
                        cds_lfht_for_each_entry(session->snapshot.output_ht->ht,
                                        &iter.iter, sout, node.node) {
-                               ret = record_kernel_snapshot(ksess, sout,
+                               /*
+                                * Make a local copy of the output and assign the possible
+                                * temporary value given by the caller.
+                                */
+                               memset(&tmp_output, 0, sizeof(tmp_output));
+                               memcpy(&tmp_output, sout, sizeof(tmp_output));
+
+                               /* Use temporary max size. */
+                               if (output->max_size != (uint64_t) -1ULL) {
+                                       tmp_output.max_size = output->max_size;
+                               }
+
+                               /* Use temporary name. */
+                               if (*output->name != '\0') {
+                                       strncpy(tmp_output.name, output->name,
+                                                       sizeof(tmp_output.name));
+                               }
+
+                               ret = record_kernel_snapshot(ksess, &tmp_output,
                                                session, wait, nb_streams);
                                if (ret < 0) {
                                        rcu_read_unlock();
@@ -2655,8 +2669,8 @@ int cmd_snapshot_record(struct ltt_session *session,
        if (session->ust_session) {
                struct ltt_ust_session *usess = session->ust_session;
 
-               if (tmp_sout) {
-                       ret = record_ust_snapshot(usess, tmp_sout, session,
+               if (use_tmp_output) {
+                       ret = record_ust_snapshot(usess, &tmp_output, session,
                                        wait, nb_streams);
                        if (ret < 0) {
                                goto error;
@@ -2668,7 +2682,27 @@ int cmd_snapshot_record(struct ltt_session *session,
                        rcu_read_lock();
                        cds_lfht_for_each_entry(session->snapshot.output_ht->ht,
                                        &iter.iter, sout, node.node) {
-                               ret = record_ust_snapshot(usess, sout, session,
+                               /*
+                                * Make a local copy of the output and assign the possible
+                                * temporary value given by the caller.
+                                */
+                               memset(&tmp_output, 0, sizeof(tmp_output));
+                               memcpy(&tmp_output, sout, sizeof(tmp_output));
+
+                               fprintf(stderr, "Name: %s\n", output->name);
+
+                               /* Use temporary max size. */
+                               if (output->max_size != (uint64_t) -1ULL) {
+                                       tmp_output.max_size = output->max_size;
+                               }
+
+                               /* Use temporary name. */
+                               if (*output->name != '\0') {
+                                       strncpy(tmp_output.name, output->name,
+                                                       sizeof(tmp_output.name));
+                               }
+
+                               ret = record_ust_snapshot(usess, &tmp_output, session,
                                                wait, nb_streams);
                                if (ret < 0) {
                                        rcu_read_unlock();
@@ -2680,9 +2714,6 @@ int cmd_snapshot_record(struct ltt_session *session,
        }
 
 error:
-       if (tmp_sout) {
-               snapshot_output_destroy(tmp_sout);
-       }
        return ret;
 }
 
index 28364bbc75575508dc823c0ca6f819981bf66d0f..d2fc8ca691a15de1455dbb5cb3019f41cd756b09 100644 (file)
@@ -47,7 +47,11 @@ static int output_init(uint64_t max_size, const char *name,
 
        assert(output);
 
+       if (max_size == (uint64_t) -1ULL) {
+               max_size = 0;
+       }
        output->max_size = max_size;
+
        if (snapshot) {
                output->id = get_next_output_id(snapshot);
        }
index 223fb77c0c936e0b81d678e4787a2c5f46e80bdc..9863bf75d2ae610d5dbfcf317c5944ad7c314634 100644 (file)
@@ -4929,7 +4929,8 @@ int ust_app_snapshot_record(struct ltt_ust_session *usess,
                         * subbuffer size or else it's an error since we won't be able to
                         * snapshot anything.
                         */
-                       if (ua_chan->attr.subbuf_size > max_stream_size) {
+                       if (max_stream_size &&
+                                       ua_chan->attr.subbuf_size > max_stream_size) {
                                ret = -EINVAL;
                                DBG3("UST app snapshot record maximum stream size %" PRIu64
                                                " is smaller than subbuffer size of %" PRIu64,
index 0c15dbb70fa5f6b8f2adb8f314d9db4b4b773432..be28511b33f65c5a5cc39710b7c755432aacb6a7 100644 (file)
@@ -323,12 +323,10 @@ static int record(const char *url)
        int ret;
        struct lttng_snapshot_output *output = NULL;
 
-       if (url || (opt_ctrl_url && opt_data_url)) {
-               output = create_output_from_args(url);
-               if (!output) {
-                       ret = CMD_FATAL;
-                       goto error;
-               }
+       output = create_output_from_args(url);
+       if (!output) {
+               ret = CMD_FATAL;
+               goto error;
        }
 
        ret = lttng_snapshot_record(current_session_name, output, 0);
@@ -422,6 +420,8 @@ int cmd_snapshot(int argc, const char **argv)
                        char *endptr;
                        const char *opt = poptGetOptArg(pc);
 
+                       /* Documented by the man page of strtoll(3). */
+                       errno = 0;
                        val = strtoll(opt, &endptr, 10);
                        if ((errno == ERANGE && (val == LLONG_MAX || val == LONG_MIN))
                                        || (errno != 0 && val == 0)) {
index 9dc2c679b885da9de502e71d8fba9268c0d0a6de..6b7b8a9fc237e44487c0a3c1692bc1f5ad39a5ec 100644 (file)
@@ -221,7 +221,17 @@ int lttng_snapshot_record(const char *session_name,
  */
 struct lttng_snapshot_output *lttng_snapshot_output_create(void)
 {
-       return zmalloc(sizeof(struct lttng_snapshot_output));
+       struct lttng_snapshot_output *output;
+
+       output = zmalloc(sizeof(struct lttng_snapshot_output));
+       if (!output) {
+               goto error;
+       }
+
+       output->max_size = (uint64_t) -1ULL;
+
+error:
+       return output;
 }
 
 /*
This page took 0.031751 seconds and 5 git commands to generate.