From: Mathieu Desnoyers Date: Wed, 14 Nov 2018 21:28:24 +0000 (-0500) Subject: Fix: sessiond: consumer.c: rotation error handling X-Git-Tag: v2.12.0-rc1~759 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=20f37cb4bb8799d9493eff17b11055bc81bd7dd3 Fix: sessiond: consumer.c: rotation error handling Return more specific error codes in the various error paths of the session rotation commands. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index c53b6ceac..0ea77aadb 100644 --- a/include/lttng/lttng-error.h +++ b/include/lttng/lttng-error.h @@ -161,6 +161,13 @@ enum lttng_error_code { LTTNG_ERR_PROBE_LOCATION_INVAL = 138, /* Invalid userspace probe location. */ LTTNG_ERR_ELF_PARSING = 139, /* ELF parsing error. */ LTTNG_ERR_SDT_PROBE_SEMAPHORE = 140, /* SDT probe guarded by a semaphore. */ + LTTNG_ERR_ROTATION_FAIL_CONSUMER = 141, /* Rotation failure on consumer */ + LTTNG_ERR_ROTATE_RENAME_FAIL_CONSUMER = 142, /* Rotation rename failure on consumer */ + LTTNG_ERR_ROTATION_PENDING_LOCAL_FAIL_CONSUMER = 143, /* Rotation pending check (local) failure on consumer */ + LTTNG_ERR_ROTATION_PENDING_RELAY_FAIL_CONSUMER = 144, /* Rotation pending check (relay) failure on consumer */ + LTTNG_ERR_MKDIR_FAIL_CONSUMER = 145, /* mkdir failure on consumer */ + LTTNG_ERR_CHAN_NOT_FOUND = 146, /* Channel not found */ + /* MUST be last element */ LTTNG_ERR_NR, /* Last element */ diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 06fa5eeb4..b6c9d3055 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -1663,7 +1663,7 @@ int consumer_rotate_channel(struct consumer_socket *socket, uint64_t key, output->chunk_path, domain_path); if (ret < 0 || ret == sizeof(msg.u.rotate_channel.pathname)) { ERR("Failed to format channel path name when asking consumer to rotate channel"); - ret = -1; + ret = -LTTNG_ERR_INVALID; goto error; } } else { @@ -1674,7 +1674,7 @@ int consumer_rotate_channel(struct consumer_socket *socket, uint64_t key, output->chunk_path, domain_path); if (ret < 0 || ret == sizeof(msg.u.rotate_channel.pathname)) { ERR("Failed to format channel path name when asking consumer to rotate channel"); - ret = -1; + ret = -LTTNG_ERR_INVALID; goto error; } } @@ -1682,9 +1682,16 @@ int consumer_rotate_channel(struct consumer_socket *socket, uint64_t key, health_code_update(); ret = consumer_send_msg(socket, &msg); if (ret < 0) { + switch (-ret) { + case LTTCOMM_CONSUMERD_CHAN_NOT_FOUND: + ret = -LTTNG_ERR_CHAN_NOT_FOUND; + break; + default: + ret = -LTTNG_ERR_ROTATION_FAIL_CONSUMER; + break; + } goto error; } - error: pthread_mutex_unlock(socket->lock); health_code_update(); @@ -1710,7 +1717,7 @@ int consumer_rotate_rename(struct consumer_socket *socket, uint64_t session_id, if (old_path_length >= sizeof(msg.u.rotate_rename.old_path)) { ERR("consumer_rotate_rename: old path length (%zu bytes) exceeds the maximal length allowed by the consumer protocol (%zu bytes)", old_path_length + 1, sizeof(msg.u.rotate_rename.old_path)); - ret = -1; + ret = -LTTNG_ERR_INVALID; goto error; } @@ -1718,7 +1725,7 @@ int consumer_rotate_rename(struct consumer_socket *socket, uint64_t session_id, if (new_path_length >= sizeof(msg.u.rotate_rename.new_path)) { ERR("consumer_rotate_rename: new path length (%zu bytes) exceeds the maximal length allowed by the consumer protocol (%zu bytes)", new_path_length + 1, sizeof(msg.u.rotate_rename.new_path)); - ret = -1; + ret = -LTTNG_ERR_INVALID; goto error; } @@ -1739,6 +1746,7 @@ int consumer_rotate_rename(struct consumer_socket *socket, uint64_t session_id, health_code_update(); ret = consumer_send_msg(socket, &msg); if (ret < 0) { + ret = -LTTNG_ERR_ROTATE_RENAME_FAIL_CONSUMER; goto error; } @@ -1774,6 +1782,7 @@ int consumer_check_rotation_pending_local(struct consumer_socket *socket, health_code_update(); ret = consumer_send_msg(socket, &msg); if (ret < 0) { + ret = -LTTNG_ERR_ROTATION_PENDING_LOCAL_FAIL_CONSUMER; goto error; } @@ -1819,6 +1828,7 @@ int consumer_check_rotation_pending_relay(struct consumer_socket *socket, health_code_update(); ret = consumer_send_msg(socket, &msg); if (ret < 0) { + ret = -LTTNG_ERR_ROTATION_PENDING_RELAY_FAIL_CONSUMER; goto error; } @@ -1858,7 +1868,7 @@ int consumer_mkdir(struct consumer_socket *socket, uint64_t session_id, ret = snprintf(msg.u.mkdir.path, sizeof(msg.u.mkdir.path), "%s", path); if (ret < 0 || ret >= sizeof(msg.u.mkdir.path)) { ERR("Format path"); - ret = -1; + ret = -LTTNG_ERR_INVALID; goto error; } @@ -1871,6 +1881,7 @@ int consumer_mkdir(struct consumer_socket *socket, uint64_t session_id, health_code_update(); ret = consumer_send_msg(socket, &msg); if (ret < 0) { + ret = -LTTNG_ERR_MKDIR_FAIL_CONSUMER; goto error; } diff --git a/src/common/error.c b/src/common/error.c index 076321437..dd1735dd4 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -202,6 +202,12 @@ static const char *error_string_array[] = { [ ERROR_INDEX(LTTNG_ERR_PROBE_LOCATION_INVAL) ] = "Invalid userspace probe location", [ ERROR_INDEX(LTTNG_ERR_ELF_PARSING) ] = "ELF parsing error", [ ERROR_INDEX(LTTNG_ERR_SDT_PROBE_SEMAPHORE) ] = "SDT probe guarded by a semaphore", + [ ERROR_INDEX(LTTNG_ERR_ROTATION_FAIL_CONSUMER) ] = "Rotation failure on consumer", + [ ERROR_INDEX(LTTNG_ERR_ROTATE_RENAME_FAIL_CONSUMER) ] = "Rotation rename failure on consumer", + [ ERROR_INDEX(LTTNG_ERR_ROTATION_PENDING_LOCAL_FAIL_CONSUMER) ] = "Rotation pending check (local) failure on consumer", + [ ERROR_INDEX(LTTNG_ERR_ROTATION_PENDING_RELAY_FAIL_CONSUMER) ] = "Rotation pending check (relay) failure on consumer", + [ ERROR_INDEX(LTTNG_ERR_MKDIR_FAIL_CONSUMER) ] = "mkdir failure on consumer", + [ ERROR_INDEX(LTTNG_ERR_CHAN_NOT_FOUND) ] = "Channel not found", /* Last element */ [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"