Backport: fd-tracker: remove duplicate clear of O_CREAT flag
[deliverable/lttng-tools.git] / src / common / fd-tracker / fd-tracker.c
index 2f743be942ed40be2e5f4e1bc80f7948f1a66567..36b2e4d2c4c3c9b583c47f86254cd76ecb240ede 100644 (file)
@@ -15,7 +15,6 @@
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include <urcu/ref.h>
 #include <urcu.h>
 #include <urcu/list.h>
 #include <urcu/rculfhash.h>
@@ -130,6 +129,7 @@ struct unsuspendable_fd {
        int fd;
        char *name;
        struct cds_lfht_node tracker_node;
+       struct rcu_head rcu_head;
 };
 
 static struct {
@@ -170,14 +170,23 @@ int match_fd(struct cds_lfht_node *node, const void *key)
                        (void *) key);
 }
 
+static
+void delete_unsuspendable_fd(struct rcu_head *head)
+{
+       struct unsuspendable_fd *fd = caa_container_of(head,
+                       struct unsuspendable_fd, rcu_head);
+
+       free(fd->name);
+       free(fd);
+}
+
 static
 void unsuspendable_fd_destroy(struct unsuspendable_fd *entry)
 {
        if (!entry) {
                return;
        }
-       free(entry->name);
-       free(entry);
+       call_rcu(&entry->rcu_head, delete_unsuspendable_fd);
 }
 
 static
@@ -501,11 +510,6 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker,
                goto error_destroy;
        }
 
-       /*
-        * Clear the create flag from the open flags as it would make no sense
-        * to use it when restoring a fs handle.
-        */
-       properties.flags &= ~O_CREAT;
        handle->properties = properties;
        properties.path = NULL;
 
@@ -754,6 +758,17 @@ int fs_handle_get_fd(struct fs_handle *handle)
 {
        int ret;
 
+       /*
+        * TODO This should be optimized as it is a fairly hot path.
+        * The fd-tracker's lock should only be taken when a fs_handle is
+        * restored (slow path). On the fast path (fs_handle is active),
+        * the only effect on the fd_tracker is marking the handle as the
+        * most recently used. Currently, it is done by a call to the
+        * track/untrack helpers, but it should be done atomically.
+        *
+        * Note that the lock's nesting order must still be respected here.
+        * The handle's lock nests inside the tracker's lock.
+        */
        pthread_mutex_lock(&handle->tracker->lock);
        pthread_mutex_lock(&handle->lock);
        assert(!handle->in_use);
@@ -786,6 +801,18 @@ void fs_handle_put_fd(struct fs_handle *handle)
        pthread_mutex_unlock(&handle->lock);
 }
 
+int fs_handle_unlink(struct fs_handle *handle)
+{
+       int ret;
+
+       pthread_mutex_lock(&handle->tracker->lock);
+       pthread_mutex_lock(&handle->lock);
+       ret = lttng_inode_defer_unlink(handle->inode);
+       pthread_mutex_unlock(&handle->lock);
+       pthread_mutex_unlock(&handle->tracker->lock);
+       return ret;
+}
+
 int fs_handle_close(struct fs_handle *handle)
 {
        int ret = 0;
This page took 0.031009 seconds and 5 git commands to generate.