Fix: sessiond: consumer.c: rotation error handling
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 14 Nov 2018 21:28:24 +0000 (16:28 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 16 Nov 2018 20:48:07 +0000 (15:48 -0500)
Return more specific error codes in the various error paths
of the session rotation commands.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/lttng-error.h
src/bin/lttng-sessiond/consumer.c
src/common/error.c

index c53b6ceac48a5ddbb6a4ca197f78fa2597da7ff6..0ea77aadbcf9b5475497df2bd8c7a5fbe8cc7dbf 100644 (file)
@@ -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 */
index 06fa5eeb4b4e54112a95c5998b1b870b46575a37..b6c9d3055705b04bea1e848750f76cf1a1d86912 100644 (file)
@@ -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;
        }
 
index 076321437fc5df3db545f3df3e9968e3d0389551..dd1735dd4779094f35dd85c028ce156e488f6754 100644 (file)
@@ -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"
This page took 0.029868 seconds and 4 git commands to generate.