* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <urcu/ref.h>
#include <urcu.h>
#include <urcu/list.h>
#include <urcu/rculfhash.h>
int fd;
char *name;
struct cds_lfht_node tracker_node;
+ struct rcu_head rcu_head;
};
static struct {
(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
tracker->capacity = capacity;
tracker->unsuspendable_fds = cds_lfht_new(DEFAULT_HT_SIZE, 1, 0,
CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, NULL);
+ DBG("File descriptor tracker created with a limit of %u simultaneously-opened FDs",
+ capacity);
end:
return 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;
{
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);
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;