fd-tracker: add the unlink operation to fs handles
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 23 Nov 2019 00:08:18 +0000 (19:08 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 23 Nov 2019 01:11:40 +0000 (20:11 -0500)
The unlink method allows user to unlink the file refered-to by
an fs_handle. As indicated in the comments, the unlink operation
leverages the lttng_inode to ensure the actual unlink system call
is only performed when the last reference to an lttng_inode is
released by an fs_handle.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/fd-tracker/fd-tracker.c
src/common/fd-tracker/fd-tracker.h

index 67da7eab4d51bd98b2a7d082e5520ab92e836708..a4f4bcba77323f84990d91d6df8df328750f65d3 100644 (file)
@@ -801,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;
index ff5f49a1b8d2afc62e731e04e2ce66ab36457b78..b8082c9a7697f51eb9b2c7d30e3ef94610f6d450 100644 (file)
@@ -156,6 +156,20 @@ int fs_handle_get_fd(struct fs_handle *handle);
  */
 void fs_handle_put_fd(struct fs_handle *handle);
 
+/*
+ * Unlink the file associated to an fs_handle. Note that the unlink
+ * operation will not be performed immediately. It will only be performed
+ * once all references to the underlying file (through other fs_handle objects)
+ * have been released.
+ *
+ * However, note that the file will be renamed so as to provide the observable
+ * effect of an unlink(), that is removing a name from the filesystem.
+ *
+ * Returns 0 on success, otherwise a negative value will be returned
+ * if the operation failed.
+ */
+int fs_handle_unlink(struct fs_handle *handle);
+
 /*
  * Frees the handle and discards the underlying fd.
  */
This page took 0.035403 seconds and 4 git commands to generate.