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:50:22 +0000 (15:50 -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 f752fc4ad240da2d4e0652ffa0546d5a8c502c67..93a8c2187ee28d825822f3db803583e9dd75f423 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 4343fb114191352dbdaf13ee7a928fc283119c08..dd9e6927e32d1f9ff1c831d55aee7e774f9b667c 100644 (file)
@@ -2846,12 +2846,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 d1fa0d09cb2b04d75b3419cd6fa969a602253eb0..34d4c9b1558de816bd1935ba02eef50b1c90e511 100644 (file)
@@ -4932,6 +4932,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];
@@ -5006,6 +5007,7 @@ int ust_app_snapshot_record(struct ltt_ust_session *usess,
                        if (ret < 0) {
                                goto error;
                        }
+                       snapshot_done = 1;
                }
                break;
        }
@@ -5073,6 +5075,7 @@ int ust_app_snapshot_record(struct ltt_ust_session *usess,
                        if (ret < 0) {
                                goto error;
                        }
+                       snapshot_done = 1;
                }
                break;
        }
@@ -5081,6 +5084,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 e973456b9c7786ff6abde3e9db7252759290f50d..c704eee5f8582c791c8ba9831e7c7b9186975c26 100644 (file)
@@ -492,10 +492,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 2733d0d11881cabaada536ac1d4a0d9401754f54..b5e3fcea1c83f89329b72c780125a0d9473e891c 100644 (file)
@@ -114,6 +114,7 @@ static const char *error_string_array[] = {
        [ 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_CHAN_EXIST) ] = "Channel already exists",
+       [ 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.042343 seconds and 4 git commands to generate.