From: David Goulet Date: Tue, 14 Jan 2014 20:44:55 +0000 (-0500) Subject: Fix: report to client when snapshot will be empty X-Git-Tag: v2.3.2~16 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=e9accd4fad532b481ff23af1ef2202c1b5a43c70 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 --- diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index 5e0dd07b2..817cbe8f1 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 f997cc79b..cca259923 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -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; } diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 315e503ed..1451963ad 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -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; diff --git a/src/bin/lttng/commands/snapshot.c b/src/bin/lttng/commands/snapshot.c index a357730d0..db5a62551 100644 --- a/src/bin/lttng/commands/snapshot.c +++ b/src/bin/lttng/commands/snapshot.c @@ -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; } diff --git a/src/common/error.c b/src/common/error.c index 911baea3e..5020f316a 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -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"