relayd: replace lttng_index_file with relay_index_file
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 1 Jul 2018 03:20:43 +0000 (23:20 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 3 Jul 2018 14:40:58 +0000 (10:40 -0400)
lttng_index_file is shared between the consumer and relay daemon.
However, the introduction of the fd-tracker in the relay daemon
makes it hard to cleanly share this piece of code between both
daemons.

The ctf-index.h header is still shared by both daemons which
is the most important part. The lttng/relay_index_file class
is a fairly thin wrapper around file system operations (unlink,
read, and write an index) so there is little value gained in
sharing the code vs heavily modifying it to handle the presence
of an fd-tracker in the process.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-relayd/Makefile.am
src/bin/lttng-relayd/index-file.c [new file with mode: 0644]
src/bin/lttng-relayd/index-file.h [new file with mode: 0644]
src/bin/lttng-relayd/index.c
src/bin/lttng-relayd/index.h
src/bin/lttng-relayd/live.c
src/bin/lttng-relayd/main.c
src/bin/lttng-relayd/stream.c
src/bin/lttng-relayd/stream.h
src/bin/lttng-relayd/viewer-stream.c
src/bin/lttng-relayd/viewer-stream.h

index 69f16636cf838fa4d0d65024866770d45ef323dd..f1b15604f255f738bebb7a3e1cd1b7fd72371c7a 100644 (file)
@@ -22,7 +22,8 @@ lttng_relayd_SOURCES = main.c lttng-relayd.h utils.h utils.c cmd.h \
                        connection.c connection.h \
                        viewer-session.c viewer-session.h \
                        tracefile-array.c tracefile-array.h \
-                       tcp_keep_alive.c tcp_keep_alive.h
+                       tcp_keep_alive.c tcp_keep_alive.h \
+                       index-file.c index-file.h
 
 # link on liblttngctl for check if relayd is already alive.
 lttng_relayd_LDADD = -lurcu-common -lurcu \
diff --git a/src/bin/lttng-relayd/index-file.c b/src/bin/lttng-relayd/index-file.c
new file mode 100644 (file)
index 0000000..010d0ad
--- /dev/null
@@ -0,0 +1,388 @@
+/*
+ * Copyright (C) 2018 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License, version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "index-file.h"
+#include "lttng-relayd.h"
+
+#include <common/defaults.h>
+#include <common/error.h>
+#include <common/utils.h>
+#include <common/readwrite.h>
+#include <common/fd-tracker/fd-tracker.h>
+#include <common/fd-tracker/utils.h>
+#include <lttng/constant.h>
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <urcu/ref.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+struct relay_index_file {
+       bool suspendable;
+       union {
+               /* Suspendable. */
+               struct fs_handle *handle;
+               /* Unsuspendable. */
+               int fd;
+       } u;
+       uint32_t major;
+       uint32_t minor;
+       uint32_t element_len;
+       struct urcu_ref ref;
+};
+
+/*
+ * Create the index file associated with a trace file.
+ *
+ * Return allocated struct lttng_index_file, NULL on error.
+ */
+struct relay_index_file *relay_index_file_create(const char *path_name,
+               const char *stream_name, uint64_t size, uint64_t count,
+               uint32_t idx_major, uint32_t idx_minor)
+{
+       struct relay_index_file *index_file;
+       struct fs_handle *fs_handle = NULL;
+       int ret, fd = -1;
+       ssize_t size_ret;
+       struct ctf_packet_index_file_hdr hdr;
+       char idx_dir_path[LTTNG_PATH_MAX];
+       char idx_file_path[LTTNG_PATH_MAX];
+       /*
+        * With the session rotation feature on the relay, we might need to seek
+        * and truncate a tracefile, so we need read and write access.
+        */
+       int flags = O_RDWR | O_CREAT | O_TRUNC;
+       /* Open with 660 mode */
+       mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
+
+       index_file = zmalloc(sizeof(*index_file));
+       if (!index_file) {
+               PERROR("allocating relay_index_file");
+               goto error;
+       }
+
+       /*
+        * The receiving end of the relay daemon is not expected to try
+        * to append to an index file. It is thus safe to create it as
+        * suspendable.
+        */
+       index_file->suspendable = true;
+
+       ret = snprintf(idx_dir_path, sizeof(idx_dir_path), "%s/" DEFAULT_INDEX_DIR,
+                       path_name);
+       if (ret < 0) {
+               PERROR("snprintf index path");
+               goto error;
+       }
+
+       /* Create index directory if necessary. */
+       ret = utils_mkdir(idx_dir_path, S_IRWXU | S_IRWXG, -1, -1);
+       if (ret < 0) {
+               if (errno != EEXIST) {
+                       PERROR("Index trace directory creation error");
+                       goto error;
+               }
+       }
+
+       ret = utils_stream_file_name(idx_file_path, idx_dir_path, stream_name,
+                       size, count, DEFAULT_INDEX_FILE_SUFFIX);
+       if (ret < 0) {
+               ERR("Could not build path of index file");
+               goto error;
+       }
+
+       /*
+        * For tracefile rotation. We need to unlink the old
+        * file if present to synchronize with the tail of the
+        * live viewer which could be working on this same file.
+        * By doing so, any reference to the old index file
+        * stays valid even if we re-create a new file with the
+        * same name afterwards.
+        */
+       unlink(idx_file_path);
+       if (ret < 0 && errno != ENOENT) {
+               PERROR("Failed to unlink index file");
+               goto error;
+       }
+
+       fs_handle = fd_tracker_open_fs_handle(the_fd_tracker, idx_file_path,
+                       flags, &mode);
+       if (!fs_handle) {
+               goto error;
+       }
+       index_file->u.handle = fs_handle;
+
+       fd = fs_handle_get_fd(fs_handle);
+       if (fd < 0) {
+               goto error;
+       }
+
+       ctf_packet_index_file_hdr_init(&hdr, idx_major, idx_minor);
+       size_ret = lttng_write(fd, &hdr, sizeof(hdr));
+       if (size_ret < sizeof(hdr)) {
+               PERROR("write index header");
+               goto error;
+       }
+
+       index_file->major = idx_major;
+       index_file->minor = idx_minor;
+       index_file->element_len = ctf_packet_index_len(idx_major, idx_minor);
+       urcu_ref_init(&index_file->ref);
+
+       fs_handle_put_fd(fs_handle);
+
+       return index_file;
+
+error:
+       if (fd >= 0) {
+               fs_handle_put_fd(fs_handle);
+       }
+       if (fs_handle) {
+               int close_ret;
+
+               close_ret = fs_handle_close(fs_handle);
+               if (close_ret < 0) {
+                       PERROR("Failed to close index filesystem handle");
+               }
+       }
+       free(index_file);
+       return NULL;
+}
+
+static
+int open_file(void *data, int *out_fd)
+{
+       int ret;
+       const char *path = data;
+
+       ret = open(path, O_RDONLY);
+       if (ret < 0) {
+               goto end;
+       }
+       *out_fd = ret;
+       ret = 0;
+end:
+       return ret;
+}
+
+struct relay_index_file *relay_index_file_open(const char *path_name,
+               const char *channel_name, uint64_t tracefile_count,
+               uint64_t tracefile_count_current)
+{
+       struct relay_index_file *index_file;
+       int ret, fd;
+       ssize_t read_len;
+       char fullpath[PATH_MAX];
+       char *path_param = fullpath;
+       struct ctf_packet_index_file_hdr hdr;
+       uint32_t major, minor, element_len;
+
+       assert(path_name);
+       assert(channel_name);
+
+       index_file = zmalloc(sizeof(*index_file));
+       if (!index_file) {
+               PERROR("Failed to allocate relay_index_file");
+               goto error;
+       }
+
+       index_file->suspendable = false;
+
+       if (tracefile_count > 0) {
+               ret = snprintf(fullpath, sizeof(fullpath), "%s/" DEFAULT_INDEX_DIR "/%s_%"
+                               PRIu64 DEFAULT_INDEX_FILE_SUFFIX, path_name,
+                               channel_name, tracefile_count_current);
+       } else {
+               ret = snprintf(fullpath, sizeof(fullpath), "%s/" DEFAULT_INDEX_DIR "/%s"
+                               DEFAULT_INDEX_FILE_SUFFIX, path_name, channel_name);
+       }
+       if (ret < 0) {
+               PERROR("Failed to build index path");
+               goto error;
+       }
+
+       DBG("Index opening file %s in read only", fullpath);
+       ret = fd_tracker_open_unsuspendable_fd(the_fd_tracker, &fd,
+                       (const char **) &path_param, 1,
+                       open_file, (void *) fullpath);
+       if (ret < 0) {
+               PERROR("Failed to open index file at %s", fullpath);
+               goto error;
+       }
+
+       read_len = lttng_read(fd, &hdr, sizeof(hdr));
+       if (read_len < 0) {
+               PERROR("Failed to read index header");
+               goto error_close;
+       }
+
+       if (be32toh(hdr.magic) != CTF_INDEX_MAGIC) {
+               ERR("Invalid header magic %#010x, expected %#010x",
+                               be32toh(hdr.magic), CTF_INDEX_MAGIC);
+               goto error_close;
+       }
+       major = be32toh(hdr.index_major);
+       minor = be32toh(hdr.index_minor);
+       element_len = be32toh(hdr.packet_index_len);
+
+       if (major != CTF_INDEX_MAJOR) {
+               ERR("Invalid header version, major = %" PRIu32 ", expected %i",
+                               major, CTF_INDEX_MAJOR);
+               goto error_close;
+       }
+       if (element_len > sizeof(struct ctf_packet_index)) {
+               ERR("Index element length too long (%" PRIu32 " bytes)",
+                               element_len);
+               goto error_close;
+       }
+
+       index_file->u.fd = fd;
+       index_file->major = major;
+       index_file->minor = minor;
+       index_file->element_len = element_len;
+       urcu_ref_init(&index_file->ref);
+
+       return index_file;
+
+error_close:
+       ret = fd_tracker_close_unsuspendable_fd(the_fd_tracker, &fd,
+                       1, fd_tracker_util_close_fd, NULL);
+       if (ret < 0) {
+               PERROR("Failed to close index fd %d", fd);
+       }
+
+error:
+       free(index_file);
+       return NULL;
+}
+
+int relay_index_file_write(const struct relay_index_file *index_file,
+               const struct ctf_packet_index *element)
+{
+       int fd, ret;
+       ssize_t write_ret;
+
+       assert(index_file);
+       assert(element);
+
+       fd = index_file->suspendable ?
+                       fs_handle_get_fd(index_file->u.handle) :
+                       index_file->u.fd;
+       if (fd < 0) {
+               ret = fd;
+               goto end;
+       }
+
+       write_ret = lttng_write(fd, element, index_file->element_len);
+       if (write_ret < index_file->element_len) {
+               PERROR("Failed to write packet index to index file");
+               ret = -1;
+       }
+       ret = 0;
+
+       if (index_file->suspendable) {
+               fs_handle_put_fd(index_file->u.handle);
+       }
+end:
+       return ret;
+}
+
+int relay_index_file_read(const struct relay_index_file *index_file,
+               struct ctf_packet_index *element)
+{
+       int fd, ret;
+       ssize_t read_ret;
+
+       assert(index_file);
+       assert(element);
+
+       fd = index_file->suspendable ?
+                       fs_handle_get_fd(index_file->u.handle) :
+                       index_file->u.fd;
+       if (fd < 0) {
+               ret = fd;
+               goto end;
+       }
+
+       read_ret = lttng_read(fd, element, index_file->element_len);
+       if (read_ret < index_file->element_len) {
+               PERROR("Failed to read packet index from file");
+               ret = -1;
+       }
+       ret = 0;
+
+       if (index_file->suspendable) {
+               fs_handle_put_fd(index_file->u.handle);
+       }
+end:
+       return ret;
+}
+
+int relay_index_file_seek_end(struct relay_index_file *index_file)
+{
+       int fd, ret = 0;
+       off_t lseek_ret;
+
+       fd = index_file->suspendable ?
+                       fs_handle_get_fd(index_file->u.handle) :
+                       index_file->u.fd;
+       if (fd < 0) {
+               ret = fd;
+               goto end;
+       }
+
+       lseek_ret = lseek(fd, 0, SEEK_END);
+       if (lseek_ret < 0) {
+               ret = lseek_ret;
+       }
+
+       if (index_file->suspendable) {
+               fs_handle_put_fd(index_file->u.handle);
+       }
+end:
+       return ret;
+}
+
+void relay_index_file_get(struct relay_index_file *index_file)
+{
+       urcu_ref_get(&index_file->ref);
+}
+
+static
+void relay_index_file_release(struct urcu_ref *ref)
+{
+       int ret;
+       struct relay_index_file *index_file = caa_container_of(ref,
+                       struct relay_index_file, ref);
+
+       if (index_file->suspendable) {
+               ret = fs_handle_close(index_file->u.handle);
+       } else {
+               ret = fd_tracker_close_unsuspendable_fd(the_fd_tracker, &index_file->u.fd,
+                               1, fd_tracker_util_close_fd, NULL);
+       }
+       if (ret < 0) {
+               PERROR("Failed to close index file");
+       }
+       free(index_file);
+}
+
+void relay_index_file_put(struct relay_index_file *index_file)
+{
+       urcu_ref_put(&index_file->ref, relay_index_file_release);
+}
diff --git a/src/bin/lttng-relayd/index-file.h b/src/bin/lttng-relayd/index-file.h
new file mode 100644 (file)
index 0000000..fa34f13
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License, version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef RELAY_INDEX_FILE_H
+#define RELAY_INDEX_FILE_H
+
+#include <stdint.h>
+#include <common/index/ctf-index.h>
+
+struct relay_index_file;
+
+/*
+ * create and open have refcount of 1. Use put to decrement the
+ * refcount. Destroys when reaching 0. Use "get" to increment refcount.
+ */
+struct relay_index_file *relay_index_file_create(const char *path_name,
+               const char *stream_name, uint64_t size,
+               uint64_t count, uint32_t major, uint32_t minor);
+struct relay_index_file *relay_index_file_open(const char *path_name,
+               const char *channel_name, uint64_t tracefile_count,
+               uint64_t tracefile_count_current);
+
+int relay_index_file_write(const struct relay_index_file *index_file,
+               const struct ctf_packet_index *element);
+int relay_index_file_read(const struct relay_index_file *index_file,
+               struct ctf_packet_index *element);
+
+int relay_index_file_seek_end(struct relay_index_file *index_file);
+
+void relay_index_file_get(struct relay_index_file *index_file);
+void relay_index_file_put(struct relay_index_file *index_file);
+
+#endif /* RELAY_INDEX_FILE_H */
index 92d4581d124a95921694129cba29213c08a7bd90..25c7b5c5d7125a894f88f0d11a48a391dd368f1a 100644 (file)
@@ -157,7 +157,7 @@ end:
 }
 
 int relay_index_set_file(struct relay_index *index,
-               struct lttng_index_file *index_file,
+               struct relay_index_file *index_file,
                uint64_t data_offset)
 {
        int ret = 0;
@@ -167,7 +167,7 @@ int relay_index_set_file(struct relay_index *index,
                ret = -1;
                goto end;
        }
-       lttng_index_file_get(index_file);
+       relay_index_file_get(index_file);
        index->index_file = index_file;
        index->index_data.offset = data_offset;
 end:
@@ -220,7 +220,7 @@ static void index_release(struct urcu_ref *ref)
        struct lttng_ht_iter iter;
 
        if (index->index_file) {
-               lttng_index_file_put(index->index_file);
+               relay_index_file_put(index->index_file);
                index->index_file = NULL;
        }
        if (index->in_hash_table) {
@@ -272,7 +272,6 @@ int relay_index_try_flush(struct relay_index *index)
 {
        int ret = 1;
        bool flushed = false;
-       int fd;
 
        pthread_mutex_lock(&index->lock);
        if (index->flushed) {
@@ -282,13 +281,12 @@ int relay_index_try_flush(struct relay_index *index)
        if (!index->has_index_data || !index->index_file) {
                goto skip;
        }
-       fd = index->index_file->fd;
-       DBG2("Writing index for stream ID %" PRIu64 " and seq num %" PRIu64
-                       " on fd %d", index->stream->stream_handle,
-                       index->index_n.key, fd);
+       DBG2("Writing index for stream ID %" PRIu64 " and seq num %" PRIu64,
+                       index->stream->stream_handle,
+                       index->index_n.key);
        flushed = true;
        index->flushed = true;
-       ret = lttng_index_file_write(index->index_file, &index->index_data);
+       ret = relay_index_file_write(index->index_file, &index->index_data);
 skip:
        pthread_mutex_unlock(&index->lock);
 
@@ -362,7 +360,7 @@ uint64_t relay_index_find_last(struct relay_stream *stream)
  */
 static
 int relay_index_switch_file(struct relay_index *index,
-               struct lttng_index_file *new_index_file,
+               struct relay_index_file *new_index_file,
                uint64_t removed_data_count)
 {
        int ret = 0;
@@ -375,8 +373,8 @@ int relay_index_switch_file(struct relay_index *index,
                goto end;
        }
 
-       lttng_index_file_put(index->index_file);
-       lttng_index_file_get(new_index_file);
+       relay_index_file_put(index->index_file);
+       relay_index_file_get(new_index_file);
        index->index_file = new_index_file;
        offset = be64toh(index->index_data.offset);
        index->index_data.offset = htobe64(offset - removed_data_count);
@@ -400,7 +398,7 @@ int relay_index_switch_all_files(struct relay_stream *stream)
        rcu_read_lock();
        cds_lfht_for_each_entry(stream->indexes_ht->ht, &iter.iter,
                        index, index_n.node) {
-               DBG("Update index to fd %d", stream->index_file->fd);
+               DBG("Update index");
                ret = relay_index_switch_file(index, stream->index_file,
                                stream->pos_after_last_complete_data_index);
                if (ret) {
index 08388c001872a221cbdd6f42960513619ca42759..e44eaa86c9764ab3fc94722f89f9cee161302972 100644 (file)
 
 #include <inttypes.h>
 #include <pthread.h>
+#include <urcu/ref.h>
 
 #include <common/hashtable/hashtable.h>
-#include <common/index/index.h>
 
+#include "index-file.h"
 #include "stream-fd.h"
 
 struct relay_stream;
@@ -42,7 +43,7 @@ struct relay_index {
         * index file on which to write the index data. May differ from
         * stream->index_file due to tracefile rotation.
         */
-       struct lttng_index_file *index_file;
+       struct relay_index_file *index_file;
 
        /* Index packet data. This is the data that is written on disk. */
        struct ctf_packet_index index_data;
@@ -66,7 +67,7 @@ struct relay_index *relay_index_get_by_id_or_create(struct relay_stream *stream,
                uint64_t net_seq_num);
 void relay_index_put(struct relay_index *index);
 int relay_index_set_file(struct relay_index *index,
-               struct lttng_index_file *index_file,
+               struct relay_index_file *index_file,
                uint64_t data_offset);
 int relay_index_set_data(struct relay_index *index,
                 const struct ctf_packet_index *data);
index 5718ac46c2a8221c0e2b7a4a3838d84db1fe3d37..3bf2b3e1cc019780bc2ed35bf857de62887a8139 100644 (file)
@@ -47,7 +47,6 @@
 #include <common/compat/endian.h>
 #include <common/defaults.h>
 #include <common/futex.h>
-#include <common/index/index.h>
 #include <common/sessiond-comm/sessiond-comm.h>
 #include <common/sessiond-comm/inet.h>
 #include <common/sessiond-comm/relayd.h>
@@ -67,6 +66,7 @@
 #include "ctf-trace.h"
 #include "connection.h"
 #include "viewer-session.h"
+#include "index-file.h"
 
 #define SESSION_BUF_DEFAULT_COUNT      16
 
@@ -1232,7 +1232,7 @@ static int try_open_index(struct relay_viewer_stream *vstream,
                ret = -ENOENT;
                goto end;
        }
-       vstream->index_file = lttng_index_file_open(vstream->path_name,
+       vstream->index_file = relay_index_file_open(vstream->path_name,
                        vstream->channel_name,
                        vstream->stream->tracefile_count,
                        vstream->current_tracefile_id);
@@ -1477,10 +1477,9 @@ int viewer_get_next_index(struct relay_connection *conn)
                viewer_index.flags |= LTTNG_VIEWER_FLAG_NEW_STREAM;
        }
 
-       ret = lttng_index_file_read(vstream->index_file, &packet_index);
+       ret = relay_index_file_read(vstream->index_file, &packet_index);
        if (ret) {
-               ERR("Relay error reading index file %d",
-                               vstream->index_file->fd);
+               ERR("Relay error reading index file");
                viewer_index.status = htobe32(LTTNG_VIEWER_INDEX_ERR);
                goto send_reply;
        } else {
index 6787a1d0f21fd93097f7850c58c9db65d9226aac..dc8cbadbcd89515a93ea8b13d2403af6c756d537 100644 (file)
@@ -1668,14 +1668,14 @@ int create_rotate_index_file(struct relay_stream *stream)
 
        /* Put ref on previous index_file. */
        if (stream->index_file) {
-               lttng_index_file_put(stream->index_file);
+               relay_index_file_put(stream->index_file);
                stream->index_file = NULL;
        }
        major = stream->trace->session->major;
        minor = stream->trace->session->minor;
-       stream->index_file = lttng_index_file_create(stream->path_name,
+       stream->index_file = relay_index_file_create(stream->path_name,
                        stream->channel_name,
-                       -1, -1, stream->tracefile_size,
+                       stream->tracefile_size,
                        tracefile_array_get_file_index_head(stream->tfa),
                        lttng_to_index_major(major, minor),
                        lttng_to_index_minor(major, minor));
index 935ab9a72249d6159276d5fa78d3cb06d1dd5a19..5291a0efa30f6b5aafd0cd46da92835b88302d06 100644 (file)
@@ -290,7 +290,7 @@ static void stream_release(struct urcu_ref *ref)
                stream->stream_fd = NULL;
        }
        if (stream->index_file) {
-               lttng_index_file_put(stream->index_file);
+               relay_index_file_put(stream->index_file);
                stream->index_file = NULL;
        }
        if (stream->trace) {
index fb3e1ed68b936e1fd7411273c4b7a9b338f76e0b..886fa0e480f72220560588e27b2cff760a2835b5 100644 (file)
@@ -30,6 +30,7 @@
 #include "session.h"
 #include "stream-fd.h"
 #include "tracefile-array.h"
+#include "index-file.h"
 
 struct relay_stream_chunk_id {
        bool is_set;
@@ -58,7 +59,7 @@ struct relay_stream {
        /* FD on which to write the stream data. */
        struct stream_fd *stream_fd;
        /* index file on which to write the index data. */
-       struct lttng_index_file *index_file;
+       struct relay_index_file *index_file;
 
        char *path_name;
        char *channel_name;
index 3c6926299a438fadb4827b8b39d5db05ad1a2fa0..67c037f77b82e12610b5d87e28cd05a3fefb355c 100644 (file)
 
 #define _LGPL_SOURCE
 #include <common/common.h>
-#include <common/index/index.h>
 #include <common/compat/string.h>
 
 #include "lttng-relayd.h"
 #include "viewer-stream.h"
+#include "index-file.h"
 
 static void viewer_stream_destroy(struct relay_viewer_stream *vstream)
 {
@@ -118,7 +118,7 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream,
        if (stream->index_received_seqcount == 0) {
                vstream->index_file = NULL;
        } else {
-               vstream->index_file = lttng_index_file_open(vstream->path_name,
+               vstream->index_file = relay_index_file_open(vstream->path_name,
                                vstream->channel_name,
                                stream->tracefile_count,
                                vstream->current_tracefile_id);
@@ -128,10 +128,10 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream,
        }
 
        if (seek_t == LTTNG_VIEWER_SEEK_LAST && vstream->index_file) {
-               off_t lseek_ret;
+               int ret;
 
-               lseek_ret = lseek(vstream->index_file->fd, 0, SEEK_END);
-               if (lseek_ret < 0) {
+               ret = relay_index_file_seek_end(vstream->index_file);
+               if (ret < 0) {
                        goto error_unlock;
                }
        }
@@ -183,7 +183,7 @@ static void viewer_stream_release(struct urcu_ref *ref)
                vstream->stream_fd = NULL;
        }
        if (vstream->index_file) {
-               lttng_index_file_put(vstream->index_file);
+               relay_index_file_put(vstream->index_file);
                vstream->index_file = NULL;
        }
        if (vstream->stream) {
@@ -285,7 +285,7 @@ int viewer_stream_rotate(struct relay_viewer_stream *vstream)
        }
 
        if (vstream->index_file) {
-               lttng_index_file_put(vstream->index_file);
+               relay_index_file_put(vstream->index_file);
                vstream->index_file = NULL;
        }
        if (vstream->stream_fd) {
@@ -293,7 +293,7 @@ int viewer_stream_rotate(struct relay_viewer_stream *vstream)
                vstream->stream_fd = NULL;
        }
 
-       vstream->index_file = lttng_index_file_open(vstream->path_name,
+       vstream->index_file = relay_index_file_open(vstream->path_name,
                        vstream->channel_name,
                        stream->tracefile_count,
                        vstream->current_tracefile_id);
index 3d9b076b75f533bf849e6eb6104fa33307d11f32..f394987ae6bce95e77b19285a46addf7685c5427 100644 (file)
@@ -29,6 +29,7 @@
 #include "ctf-trace.h"
 #include "lttng-viewer-abi.h"
 #include "stream.h"
+#include "index-file.h"
 
 struct relay_stream;
 
@@ -52,7 +53,7 @@ struct relay_viewer_stream {
        /* FD from which to read the stream data. */
        struct stream_fd *stream_fd;
        /* index file from which to read the index data. */
-       struct lttng_index_file *index_file;
+       struct relay_index_file *index_file;
 
        char *path_name;
        char *channel_name;
This page took 0.039467 seconds and 5 git commands to generate.