fd-tracker Fix: do not warn on index file not found
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 6 Aug 2018 01:38:10 +0000 (21:38 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 21 Sep 2018 04:35:43 +0000 (00:35 -0400)
Upstream status pending on fd-tracker merge

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
src/bin/lttng-relayd/index-file.c
src/common/fd-tracker/fd-tracker.c

index 04dac4068aafeb8490a8717398d3672bbb95901b..4a69f39bc0d670f7e9f60c4dc6a946336838e658 100644 (file)
@@ -65,8 +65,9 @@ int unlink_through_handle(const char *path)
        DBG("Unlinking index at %s through a filesystem handle", path);
        handle = fd_tracker_open_fs_handle(the_fd_tracker, path, flags, NULL);
        if (!handle) {
-               /* There is nothing to do. */
-               DBG("File %s does not exist, ignoring unlink", path);
+               if (errno == ENOENT) {
+                       DBG("File %s does not exist, ignoring unlink", path);
+               }
                goto end;
        }
 
@@ -151,12 +152,14 @@ struct relay_index_file *relay_index_file_create(const char *path_name,
        fs_handle = fd_tracker_open_fs_handle(the_fd_tracker, idx_file_path,
                        flags, &mode);
        if (!fs_handle) {
+               PERROR("Failed to open index file at %s", idx_file_path);
                goto error;
        }
        index_file->handle = fs_handle;
 
        fd = fs_handle_get_fd(fs_handle);
        if (fd < 0) {
+               PERROR("Failed to get fd of index file at %s", idx_file_path);
                goto error;
        }
 
@@ -302,6 +305,7 @@ int relay_index_file_write(const struct relay_index_file *index_file,
 
        fd = fs_handle_get_fd(index_file->handle);
        if (fd < 0) {
+               PERROR("Failed to get fd from handle");
                ret = fd;
                goto end;
        }
@@ -329,6 +333,7 @@ int relay_index_file_read(const struct relay_index_file *index_file,
 
        fd = fs_handle_get_fd(index_file->handle);
        if (fd < 0) {
+               PERROR("Failed to get fd of handle %p", index_file->handle);
                ret = fd;
                goto end;
        }
@@ -352,6 +357,7 @@ int relay_index_file_seek_end(struct relay_index_file *index_file)
 
        fd = fs_handle_get_fd(index_file->handle);
        if (fd < 0) {
+               PERROR("Failed to get fd of handle %p", index_file->handle);
                ret = fd;
                goto end;
        }
index 2cf26f723234a382ae1355468af8a130dc5b61ce..eddf5ada6189dedf90cae7b407f1b4bcb2a0b9f8 100644 (file)
@@ -305,9 +305,9 @@ int fs_handle_restore(struct fs_handle *handle)
        ret = open_from_properties(path,
                        &handle->properties);
        if (ret < 0) {
+               errno = -ret;
                PERROR("Failed to restore filesystem handle to %s, open() failed",
                                path);
-               ret = -errno;
                goto end;
        }
        fd = ret;
@@ -483,10 +483,13 @@ end:
        return ret;
 }
 
+/*
+ * If return NULL check errno for error.
+ */
 struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker,
                const char *path, int flags, mode_t *mode)
 {
-       int ret;
+       int ret = 0;
        struct fs_handle *handle = NULL;
        struct stat fd_stat;
        struct open_properties properties = {
@@ -500,6 +503,8 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker,
                if (tracker->count.suspendable.active > 0) {
                        ret = fd_tracker_suspend_handles(tracker, 1);
                        if (ret) {
+                               ERR("Suspend handled failed");
+                               ret = EMFILE;
                                goto end;
                        }
                } else {
@@ -510,12 +515,14 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker,
                         */
                        WARN("Cannot open file system handle, too many unsuspendable file descriptors are opened (%u)",
                                        tracker->count.unsuspendable);
+                       ret = EMFILE;
                        goto end;
                }
        }
 
        handle = zmalloc(sizeof(*handle));
        if (!handle) {
+               ret = ENOMEM;
                goto end;
        }
        handle->tracker = tracker;
@@ -523,12 +530,14 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker,
        ret = pthread_mutex_init(&handle->lock, NULL);
        if (ret) {
                PERROR("Failed to initialize handle mutex while creating fs handle");
+               ret = errno;
                goto error_mutex_init;
        }
 
        handle->fd = open_from_properties(path, &properties);
        if (handle->fd < 0) {
-               PERROR("Failed to open fs handle to %s, open() returned", path);
+               /* ret contains -errno on error. */
+               ret = -ret;
                goto error;
        }
 
@@ -537,6 +546,7 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker,
        handle->inode = lttng_inode_registry_get_inode(tracker->inode_registry,
                        handle->fd, path);
        if (!handle->inode) {
+               ret = errno;
                ERR("Failed to get lttng_inode corresponding to file %s",
                                path);
                goto error;
@@ -544,6 +554,7 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker,
 
        if (fstat(handle->fd, &fd_stat)) {
                PERROR("Failed to retrieve file descriptor inode while creating fs handle, fstat() returned");
+               ret = errno;
                goto error;
        }
        handle->ino = fd_stat.st_ino;
@@ -551,6 +562,7 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker,
        fd_tracker_track(tracker, handle);
 end:
        pthread_mutex_unlock(&tracker->lock);
+       errno = ret;
        return handle;
 error:
        if (handle->inode) {
This page took 0.02855 seconds and 5 git commands to generate.