From cf7f2fd55e41a7992bd9b11fb836e66422daf044 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 5 Jul 2018 22:29:59 -0400 Subject: [PATCH] fd-tracker: add the unlink operation to fs handles MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/common/fd-tracker/fd-tracker.c | 12 ++++++++++++ src/common/fd-tracker/fd-tracker.h | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/common/fd-tracker/fd-tracker.c b/src/common/fd-tracker/fd-tracker.c index cdc1691f6..3720e075c 100644 --- a/src/common/fd-tracker/fd-tracker.c +++ b/src/common/fd-tracker/fd-tracker.c @@ -796,6 +796,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; diff --git a/src/common/fd-tracker/fd-tracker.h b/src/common/fd-tracker/fd-tracker.h index ff5f49a1b..b8082c9a7 100644 --- a/src/common/fd-tracker/fd-tracker.h +++ b/src/common/fd-tracker/fd-tracker.h @@ -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. */ -- 2.34.1