From 7badf927c6cd5d2e2ef217b905e45d5c3229ae79 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 14 Jan 2014 15:44:55 -0500 Subject: [PATCH] Fix: report to client when snapshot will be empty This adds a new lttng error code being the "snapshot nodata". Fixes #662 Signed-off-by: David Goulet --- include/lttng/lttng-error.h | 2 +- src/bin/lttng-sessiond/cmd.c | 13 +++++++++---- src/bin/lttng-sessiond/ust-app.c | 12 ++++++++++++ src/bin/lttng/commands/snapshot.c | 11 +++++++++-- src/common/error.c | 1 + 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index f752fc4ad..93a8c2187 100644 --- a/include/lttng/lttng-error.h +++ b/include/lttng/lttng-error.h @@ -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 */ diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 4343fb114..dd9e6927e 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -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; } diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index d1fa0d09c..34d4c9b15 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -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; diff --git a/src/bin/lttng/commands/snapshot.c b/src/bin/lttng/commands/snapshot.c index e973456b9..c704eee5f 100644 --- a/src/bin/lttng/commands/snapshot.c +++ b/src/bin/lttng/commands/snapshot.c @@ -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; } diff --git a/src/common/error.c b/src/common/error.c index 2733d0d11..b5e3fcea1 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -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" -- 2.34.1