Fix: report to client when snapshot will be empty
authorDavid Goulet <dgoulet@efficios.com>
Tue, 14 Jan 2014 20:44:55 +0000 (15:44 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 14 Jan 2014 20:48:06 +0000 (15:48 -0500)
This adds a new lttng error code being the "snapshot nodata".

Fixes #662

Signed-off-by: David Goulet <dgoulet@efficios.com>
include/lttng/lttng-error.h
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/ust-app.c
src/bin/lttng/commands/snapshot.c
src/common/error.c

index 5e0dd07b272027b9b50539d6a17c6d73f2f362cc..817cbe8f1bab8b30e2717e327d843ce45a2616b3 100644 (file)
@@ -101,7 +101,7 @@ enum lttng_error_code {
        LTTNG_ERR_UST_CONSUMER64_FAIL    = 68,  /* 64-bit UST consumer start failed */
        LTTNG_ERR_UST_CONSUMER32_FAIL    = 69,  /* 32-bit UST consumer start failed */
        LTTNG_ERR_UST_STREAM_FAIL        = 70,  /* UST create stream failed */
-       /* 71 */
+       LTTNG_ERR_SNAPSHOT_NODATA        = 71,  /* No data in snapshot. */
        /* 72 */
        /* 73 */
        LTTNG_ERR_UST_LIST_FAIL          = 74,  /* UST listing events failed */
index f997cc79b3c6f5a89865250327ccb0477da69900..cca25992313cd8c48f5f049d717cff73e6a41045 100644 (file)
@@ -2637,12 +2637,17 @@ static int record_ust_snapshot(struct ltt_ust_session *usess,
 
        ret = ust_app_snapshot_record(usess, output, wait, nb_streams);
        if (ret < 0) {
-               if (ret == -EINVAL) {
+               switch (-ret) {
+               case EINVAL:
                        ret = LTTNG_ERR_INVALID;
-                       goto error_snapshot;
+                       break;
+               case ENODATA:
+                       ret = LTTNG_ERR_SNAPSHOT_NODATA;
+                       break;
+               default:
+                       ret = LTTNG_ERR_SNAPSHOT_FAIL;
+                       break;
                }
-
-               ret = LTTNG_ERR_SNAPSHOT_FAIL;
                goto error_snapshot;
        }
 
index 315e503edec59673217e97cbf2ef911797f5dcaa..1451963ad41f14cb1809e37594a3960238112819 100644 (file)
@@ -4992,6 +4992,7 @@ int ust_app_snapshot_record(struct ltt_ust_session *usess,
                struct snapshot_output *output, int wait, unsigned int nb_streams)
 {
        int ret = 0;
+       unsigned int snapshot_done = 0;
        struct lttng_ht_iter iter;
        struct ust_app *app;
        char pathname[PATH_MAX];
@@ -5066,6 +5067,7 @@ int ust_app_snapshot_record(struct ltt_ust_session *usess,
                        if (ret < 0) {
                                goto error;
                        }
+                       snapshot_done = 1;
                }
                break;
        }
@@ -5133,6 +5135,7 @@ int ust_app_snapshot_record(struct ltt_ust_session *usess,
                        if (ret < 0) {
                                goto error;
                        }
+                       snapshot_done = 1;
                }
                break;
        }
@@ -5141,6 +5144,15 @@ int ust_app_snapshot_record(struct ltt_ust_session *usess,
                break;
        }
 
+       if (!snapshot_done) {
+               /*
+                * If no snapshot was made and we are not in the error path, this means
+                * that there are no buffers thus no (prior) application to snapshot
+                * data from so we have simply NO data.
+                */
+               ret = -ENODATA;
+       }
+
 error:
        rcu_read_unlock();
        return ret;
index a357730d008444d1d1b1db4ffc36dc40637bd19e..db5a62551b5e3ba7b7812cee630c3fa6db6b4353 100644 (file)
@@ -480,10 +480,17 @@ int cmd_snapshot(int argc, const char **argv)
 
        ret = handle_command(poptGetArgs(pc));
        if (ret < 0) {
-               if (ret == -LTTNG_ERR_EPERM) {
+               switch (-ret) {
+               case LTTNG_ERR_EPERM:
                        ERR("The session needs to be set in no output mode (--no-output)");
+                       break;
+               case LTTNG_ERR_SNAPSHOT_NODATA:
+                       WARN("%s", lttng_strerror(ret));
+                       break;
+               default:
+                       ERR("%s", lttng_strerror(ret));
+                       break;
                }
-               ERR("%s", lttng_strerror(ret));
                goto end;
        }
 
index 911baea3ed4b42f0671dc1e53d9c32dd78287b22..5020f316af8a94e6345149d0d82d3f1f608687bc 100644 (file)
@@ -113,6 +113,7 @@ static const char *error_string_array[] = {
        [ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_OUTPUT_EXIST) ] = "Snapshot output already exists",
        [ ERROR_INDEX(LTTNG_ERR_START_SESSION_ONCE) ] = "Session needs to be started once",
        [ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_FAIL) ] = "Snapshot record failed",
+       [ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_NODATA) ] = "No data available in snapshot",
 
        /* Last element */
        [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"
This page took 0.032071 seconds and 4 git commands to generate.