ctf: assert that msg iter and medium seek offset is valid
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 5 Nov 2019 20:22:39 +0000 (15:22 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 15 Nov 2019 21:10:12 +0000 (16:10 -0500)
I don't think there is ever a valid situation for `offset` to have an
invalid value in ctf_msg_iter_seek or medop_seek.  If the user of the
iterator (e.g.  fs.c) thinks it's cool enough to seek, it should know
about the underlying medium it used to create the msg iter and make sure
not to seek at an invalid position.

This allows removing the INVAL values in enum ctf_msg_iter_medium_status
and enum ctf_msg_iter_status.

Change-Id: I19d48fe751aebf21e60c5cbc16127919a5fa72f3
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
src/plugins/ctf/common/msg-iter/msg-iter.c
src/plugins/ctf/common/msg-iter/msg-iter.h
src/plugins/ctf/fs-src/data-stream-file.c
src/plugins/ctf/lttng-live/lttng-live.c

index a074aafe1814ec0ba948976d04bdf8d50894371b..0a16eed412fcfe3b2269a3d1248ddd3041446cdc 100644 (file)
@@ -3160,17 +3160,10 @@ enum ctf_msg_iter_status ctf_msg_iter_seek(struct ctf_msg_iter *msg_it,
                off_t offset)
 {
        enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
-       bt_self_component *self_comp = msg_it->self_comp;
        enum ctf_msg_iter_medium_status medium_status;
 
        BT_ASSERT(msg_it);
-       if (offset < 0) {
-               BT_COMP_LOGE_APPEND_CAUSE(self_comp,
-                       "Cannot seek to negative offset: offset=%jd",
-                       (intmax_t) offset);
-               status = CTF_MSG_ITER_STATUS_INVAL;
-               goto end;
-       }
+       BT_ASSERT(offset >= 0);
 
        if (!msg_it->medium.medops.seek) {
                status = CTF_MSG_ITER_STATUS_UNSUPPORTED;
index 9fecf72889e9e7ce795dee236b9a56459c625a8b..dd3b01d3d5597aabcbeb599fd05efcee47f8865c 100644 (file)
@@ -64,9 +64,6 @@ enum ctf_msg_iter_medium_status {
        /** Unsupported operation. */
        CTF_MSG_ITER_MEDIUM_STATUS_UNSUPPORTED = -3,
 
-       /** Invalid argument. */
-       CTF_MSG_ITER_MEDIUM_STATUS_INVAL = -2,
-
        /** General error. */
        CTF_MSG_ITER_MEDIUM_STATUS_ERROR = -1,
 
@@ -97,9 +94,6 @@ enum ctf_msg_iter_status {
         */
        CTF_MSG_ITER_STATUS_AGAIN = CTF_MSG_ITER_MEDIUM_STATUS_AGAIN,
 
-       /** Invalid argument. */
-       CTF_MSG_ITER_STATUS_INVAL = CTF_MSG_ITER_MEDIUM_STATUS_INVAL,
-
        /** Unsupported operation. */
        CTF_MSG_ITER_STATUS_UNSUPPORTED = CTF_MSG_ITER_MEDIUM_STATUS_UNSUPPORTED,
 
@@ -350,8 +344,6 @@ const char *ctf_msg_iter_medium_status_string(
                return "EOF";
        case CTF_MSG_ITER_MEDIUM_STATUS_AGAIN:
                return "AGAIN";
-       case CTF_MSG_ITER_MEDIUM_STATUS_INVAL:
-               return "INVAL";
        case CTF_MSG_ITER_MEDIUM_STATUS_ERROR:
                return "ERROR";
        case CTF_MSG_ITER_MEDIUM_STATUS_OK:
@@ -370,8 +362,6 @@ const char *ctf_msg_iter_status_string(
                return "EOF";
        case CTF_MSG_ITER_STATUS_AGAIN:
                return "AGAIN";
-       case CTF_MSG_ITER_STATUS_INVAL:
-               return "INVAL";
        case CTF_MSG_ITER_STATUS_ERROR:
                return "ERROR";
        case CTF_MSG_ITER_STATUS_OK:
index 9d9726fdc62840f7c5bd091c18d461b34e9f0bff..30da41a140fca4ee278dc5cfdd63f7d6f1c8b675 100644 (file)
@@ -221,12 +221,8 @@ enum ctf_msg_iter_medium_status medop_seek(off_t offset, void *data)
        bt_self_component *self_comp = ds_file->self_comp;
        bt_logging_level log_level = ds_file->log_level;
 
-       if (offset < 0 || offset > file_size) {
-               BT_COMP_LOGE("Invalid medium seek request: offset=%jd, file-size=%jd",
-                       (intmax_t) offset, (intmax_t) file_size);
-               status = CTF_MSG_ITER_MEDIUM_STATUS_INVAL;
-               goto end;
-       }
+       BT_ASSERT(offset >= 0);
+       BT_ASSERT(offset < file_size);
 
        /* If there is no current mapping, map the right file directly. */
        if (!ds_file->mmap_addr) {
index b8f3c8c278c36c31cd232351147e40ee243e6816..2376d440bb4c3be91bc7f8efb8353087a2549811 100644 (file)
@@ -835,8 +835,6 @@ enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_active_data_
                 */
                ret = LTTNG_LIVE_ITERATOR_STATUS_CONTINUE;
                break;
-       case CTF_MSG_ITER_STATUS_INVAL:
-               /* No argument provided by the user, so don't return INVAL. */
        case CTF_MSG_ITER_STATUS_ERROR:
        default:
                ret = LTTNG_LIVE_ITERATOR_STATUS_ERROR;
This page took 0.029065 seconds and 4 git commands to generate.