X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Ffd-tracker%2Ffd-tracker.cpp;h=7f4c2b5b2b698f81116570d94380720c7ceda7c6;hb=HEAD;hp=e1f9b14fbba8fa618e072d5addc422f2c5cbdaec;hpb=f149493493fbd8a3efa4748832c03278c96c38ca;p=lttng-tools.git diff --git a/src/common/fd-tracker/fd-tracker.cpp b/src/common/fd-tracker/fd-tracker.cpp index e1f9b14fb..7f4c2b5b2 100644 --- a/src/common/fd-tracker/fd-tracker.cpp +++ b/src/common/fd-tracker/fd-tracker.cpp @@ -5,16 +5,8 @@ * */ -#include -#include -#include - -#include -#include -#include -#include -#include -#include +#include "fd-tracker.hpp" +#include "inode.hpp" #include #include @@ -23,30 +15,35 @@ #include #include #include +#include -#include "fd-tracker.hpp" -#include "inode.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include /* Tracker lock must be taken by the user. */ -#define TRACKED_COUNT(tracker) \ - (tracker->count.suspendable.active + \ - tracker->count.suspendable.suspended + \ - tracker->count.unsuspendable) +#define TRACKED_COUNT(tracker) \ + ((tracker)->count.suspendable.active + (tracker)->count.suspendable.suspended + \ + (tracker)->count.unsuspendable) /* Tracker lock must be taken by the user. */ -#define ACTIVE_COUNT(tracker) \ - (tracker->count.suspendable.active + tracker->count.unsuspendable) +#define ACTIVE_COUNT(tracker) ((tracker)->count.suspendable.active + (tracker)->count.unsuspendable) /* Tracker lock must be taken by the user. */ -#define SUSPENDED_COUNT(tracker) (tracker->count.suspendable.suspended) +#define SUSPENDED_COUNT(tracker) ((tracker)->count.suspendable.suspended) /* Tracker lock must be taken by the user. */ -#define SUSPENDABLE_COUNT(tracker) \ - (tracker->count.suspendable.active + \ - tracker->count.suspendable.suspended) +#define SUSPENDABLE_COUNT(tracker) \ + ((tracker)->count.suspendable.active + (tracker)->count.suspendable.suspended) /* Tracker lock must be taken by the user. */ -#define UNSUSPENDABLE_COUNT(tracker) (tracker->count.unsuspendable) +#define UNSUSPENDABLE_COUNT(tracker) ((tracker)->count.unsuspendable) struct fd_tracker { pthread_mutex_t lock; @@ -138,10 +135,10 @@ struct { static int match_fd(struct cds_lfht_node *node, const void *key); static void unsuspendable_fd_destroy(struct unsuspendable_fd *entry); -static struct unsuspendable_fd *unsuspendable_fd_create( - const char *name, int fd); +static struct unsuspendable_fd *unsuspendable_fd_create(const char *name, int fd); static int open_from_properties(const struct lttng_directory_handle *dir_handle, - const char *path, struct open_properties *properties); + const char *path, + struct open_properties *properties); static void fs_handle_tracked_log(struct fs_handle_tracked *handle); static int fs_handle_tracked_suspend(struct fs_handle_tracked *handle); @@ -151,29 +148,23 @@ static void fs_handle_tracked_put_fd(struct fs_handle *_handle); static int fs_handle_tracked_unlink(struct fs_handle *_handle); static int fs_handle_tracked_close(struct fs_handle *_handle); -static void fd_tracker_track( - struct fd_tracker *tracker, struct fs_handle_tracked *handle); -static void fd_tracker_untrack( - struct fd_tracker *tracker, struct fs_handle_tracked *handle); -static int fd_tracker_suspend_handles( - struct fd_tracker *tracker, unsigned int count); -static int fd_tracker_restore_handle( - struct fd_tracker *tracker, struct fs_handle_tracked *handle); +static void fd_tracker_track(struct fd_tracker *tracker, struct fs_handle_tracked *handle); +static void fd_tracker_untrack(struct fd_tracker *tracker, struct fs_handle_tracked *handle); +static int fd_tracker_suspend_handles(struct fd_tracker *tracker, unsigned int count); +static int fd_tracker_restore_handle(struct fd_tracker *tracker, struct fs_handle_tracked *handle); /* Match function of the tracker's unsuspendable_fds hash table. */ static int match_fd(struct cds_lfht_node *node, const void *key) { - struct unsuspendable_fd *entry = caa_container_of( - node, struct unsuspendable_fd, tracker_node); + struct unsuspendable_fd *entry = + lttng::utils::container_of(node, &unsuspendable_fd::tracker_node); - return hash_match_key_ulong( - (void *) (unsigned long) entry->fd, (void *) key); + return hash_match_key_ulong((void *) (unsigned long) entry->fd, (void *) key); } static void delete_unsuspendable_fd(struct rcu_head *head) { - struct unsuspendable_fd *fd = caa_container_of( - head, struct unsuspendable_fd, rcu_head); + struct unsuspendable_fd *fd = caa_container_of(head, struct unsuspendable_fd, rcu_head); free(fd->name); free(fd); @@ -187,8 +178,7 @@ static void unsuspendable_fd_destroy(struct unsuspendable_fd *entry) call_rcu(&entry->rcu_head, delete_unsuspendable_fd); } -static struct unsuspendable_fd *unsuspendable_fd_create( - const char *name, int fd) +static struct unsuspendable_fd *unsuspendable_fd_create(const char *name, int fd) { struct unsuspendable_fd *entry = zmalloc(); @@ -206,7 +196,7 @@ static struct unsuspendable_fd *unsuspendable_fd_create( return entry; error: unsuspendable_fd_destroy(entry); - return NULL; + return nullptr; } static void fs_handle_tracked_log(struct fs_handle_tracked *handle) @@ -214,11 +204,13 @@ static void fs_handle_tracked_log(struct fs_handle_tracked *handle) const char *path; pthread_mutex_lock(&handle->lock); - lttng_inode_borrow_location(handle->inode, NULL, &path); + lttng_inode_borrow_location(handle->inode, nullptr, &path); if (handle->fd >= 0) { - DBG_NO_LOC(" %s [active, fd %d%s]", path, handle->fd, - handle->in_use ? ", in use" : ""); + DBG_NO_LOC(" %s [active, fd %d%s]", + path, + handle->fd, + handle->in_use ? ", in use" : ""); } else { DBG_NO_LOC(" %s [suspended]", path); } @@ -234,8 +226,7 @@ static int fs_handle_tracked_suspend(struct fs_handle_tracked *handle) const struct lttng_directory_handle *node_directory_handle; pthread_mutex_lock(&handle->lock); - lttng_inode_borrow_location( - handle->inode, &node_directory_handle, &path); + lttng_inode_borrow_location(handle->inode, &node_directory_handle, &path); LTTNG_ASSERT(handle->fd >= 0); if (handle->in_use) { /* This handle can't be suspended as it is currently in use. */ @@ -243,19 +234,16 @@ static int fs_handle_tracked_suspend(struct fs_handle_tracked *handle) goto end; } - ret = lttng_directory_handle_stat( - node_directory_handle, path, &fs_stat); + ret = lttng_directory_handle_stat(node_directory_handle, path, &fs_stat); if (ret) { - PERROR("Filesystem handle to %s cannot be suspended as stat() failed", - path); + PERROR("Filesystem handle to %s cannot be suspended as stat() failed", path); ret = -errno; goto end; } if (fs_stat.st_ino != handle->ino) { /* Don't suspend as the handle would not be restorable. */ - WARN("Filesystem handle to %s cannot be suspended as its inode changed", - path); + WARN("Filesystem handle to %s cannot be suspended as its inode changed", path); ret = -ENOENT; goto end; } @@ -263,20 +251,21 @@ static int fs_handle_tracked_suspend(struct fs_handle_tracked *handle) handle->offset = lseek(handle->fd, 0, SEEK_CUR); if (handle->offset == -1) { WARN("Filesystem handle to %s cannot be suspended as lseek() failed to sample its current position", - path); + path); ret = -errno; goto end; } ret = close(handle->fd); if (ret) { - PERROR("Filesystem handle to %s cannot be suspended as close() failed", - path); + PERROR("Filesystem handle to %s cannot be suspended as close() failed", path); ret = -errno; goto end; } DBG("Suspended filesystem handle to %s (fd %i) at position %" PRId64, - path, handle->fd, handle->offset); + path, + handle->fd, + handle->offset); handle->fd = -1; end: if (ret) { @@ -293,16 +282,13 @@ static int fs_handle_tracked_restore(struct fs_handle_tracked *handle) const char *path; const struct lttng_directory_handle *node_directory_handle; - lttng_inode_borrow_location( - handle->inode, &node_directory_handle, &path); + lttng_inode_borrow_location(handle->inode, &node_directory_handle, &path); LTTNG_ASSERT(handle->fd == -1); LTTNG_ASSERT(path); - ret = open_from_properties( - node_directory_handle, path, &handle->properties); + ret = open_from_properties(node_directory_handle, path, &handle->properties); if (ret < 0) { - PERROR("Failed to restore filesystem handle to %s, open() failed", - path); + PERROR("Failed to restore filesystem handle to %s, open() failed", path); ret = -errno; goto end; } @@ -310,13 +296,14 @@ static int fs_handle_tracked_restore(struct fs_handle_tracked *handle) ret = lseek(fd, handle->offset, SEEK_SET); if (ret < 0) { - PERROR("Failed to restore filesystem handle to %s, lseek() failed", - path); + PERROR("Failed to restore filesystem handle to %s, lseek() failed", path); ret = -errno; goto end; } DBG("Restored filesystem handle to %s (fd %i) at position %" PRId64, - path, fd, handle->offset); + path, + fd, + handle->offset); ret = 0; handle->fd = fd; fd = -1; @@ -328,7 +315,8 @@ end: } static int open_from_properties(const struct lttng_directory_handle *dir_handle, - const char *path, struct open_properties *properties) + const char *path, + struct open_properties *properties) { int ret; @@ -339,11 +327,10 @@ static int open_from_properties(const struct lttng_directory_handle *dir_handle, * thus it is ignored here. */ if ((properties->flags & O_CREAT) && properties->mode.is_set) { - ret = lttng_directory_handle_open_file(dir_handle, path, - properties->flags, properties->mode.value); + ret = lttng_directory_handle_open_file( + dir_handle, path, properties->flags, properties->mode.value); } else { - ret = lttng_directory_handle_open_file(dir_handle, path, - properties->flags, 0); + ret = lttng_directory_handle_open_file(dir_handle, path, properties->flags, 0); } /* * Some flags should not be used beyond the initial open() of a @@ -364,8 +351,7 @@ end: return ret; } -struct fd_tracker *fd_tracker_create(const char *unlinked_file_path, - unsigned int capacity) +struct fd_tracker *fd_tracker_create(const char *unlinked_file_path, unsigned int capacity) { struct fd_tracker *tracker = zmalloc(); @@ -375,7 +361,7 @@ struct fd_tracker *fd_tracker_create(const char *unlinked_file_path, pthread_mutex_lock(&seed.lock); if (!seed.initialized) { - seed.value = (unsigned long) time(NULL); + seed.value = (unsigned long) time(nullptr); seed.initialized = true; } pthread_mutex_unlock(&seed.lock); @@ -383,8 +369,8 @@ struct fd_tracker *fd_tracker_create(const char *unlinked_file_path, CDS_INIT_LIST_HEAD(&tracker->active_handles); CDS_INIT_LIST_HEAD(&tracker->suspended_handles); tracker->capacity = capacity; - tracker->unsuspendable_fds = cds_lfht_new(DEFAULT_HT_SIZE, 1, 0, - CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, NULL); + tracker->unsuspendable_fds = cds_lfht_new( + DEFAULT_HT_SIZE, 1, 0, CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, nullptr); if (!tracker->unsuspendable_fds) { ERR("Failed to create fd-tracker's unsuspendable_fds hash table"); goto error; @@ -395,18 +381,17 @@ struct fd_tracker *fd_tracker_create(const char *unlinked_file_path, goto error; } - tracker->unlinked_file_pool = - lttng_unlinked_file_pool_create(unlinked_file_path); + tracker->unlinked_file_pool = lttng_unlinked_file_pool_create(unlinked_file_path); if (!tracker->unlinked_file_pool) { goto error; } DBG("File descriptor tracker created with a limit of %u simultaneously-opened FDs", - capacity); + capacity); end: return tracker; error: fd_tracker_destroy(tracker); - return NULL; + return nullptr; } void fd_tracker_log(struct fd_tracker *tracker) @@ -429,12 +414,10 @@ void fd_tracker_log(struct fd_tracker *tracker) DBG_NO_LOC(" capacity: %u", tracker->capacity); DBG_NO_LOC(" Tracked suspendable file descriptors"); - cds_list_for_each_entry( - handle, &tracker->active_handles, handles_list_node) { + cds_list_for_each_entry (handle, &tracker->active_handles, handles_list_node) { fs_handle_tracked_log(handle); } - cds_list_for_each_entry(handle, &tracker->suspended_handles, - handles_list_node) { + cds_list_for_each_entry (handle, &tracker->suspended_handles, handles_list_node) { fs_handle_tracked_log(handle); } if (!SUSPENDABLE_COUNT(tracker)) { @@ -442,14 +425,18 @@ void fd_tracker_log(struct fd_tracker *tracker) } DBG_NO_LOC(" Tracked unsuspendable file descriptors"); - rcu_read_lock(); - cds_lfht_for_each_entry(tracker->unsuspendable_fds, &iter, - unsuspendable_fd, tracker_node) { - DBG_NO_LOC(" %s [active, fd %d]", - unsuspendable_fd->name ?: "Unnamed", - unsuspendable_fd->fd); - } - rcu_read_unlock(); + + { + lttng::urcu::read_lock_guard read_lock; + + cds_lfht_for_each_entry ( + tracker->unsuspendable_fds, &iter, unsuspendable_fd, tracker_node) { + DBG_NO_LOC(" %s [active, fd %d]", + unsuspendable_fd->name ?: "Unnamed", + unsuspendable_fd->fd); + } + } + if (!UNSUSPENDABLE_COUNT(tracker)) { DBG_NO_LOC(" None"); } @@ -471,7 +458,7 @@ int fd_tracker_destroy(struct fd_tracker *tracker) pthread_mutex_lock(&tracker->lock); if (TRACKED_COUNT(tracker)) { ERR("A file descriptor leak has been detected: %u tracked file descriptors are still being tracked", - TRACKED_COUNT(tracker)); + TRACKED_COUNT(tracker)); pthread_mutex_unlock(&tracker->lock); fd_tracker_log(tracker); ret = -1; @@ -480,7 +467,7 @@ int fd_tracker_destroy(struct fd_tracker *tracker) pthread_mutex_unlock(&tracker->lock); if (tracker->unsuspendable_fds) { - ret = cds_lfht_destroy(tracker->unsuspendable_fds, NULL); + ret = cds_lfht_destroy(tracker->unsuspendable_fds, nullptr); LTTNG_ASSERT(!ret); } @@ -493,21 +480,20 @@ end: } struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker, - struct lttng_directory_handle *directory, - const char *path, - int flags, - mode_t *mode) + struct lttng_directory_handle *directory, + const char *path, + int flags, + mode_t *mode) { int ret; - struct fs_handle_tracked *handle = NULL; + struct fs_handle_tracked *handle = nullptr; struct stat fd_stat; - struct open_properties properties = { - .flags = flags, - .mode = { - .is_set = !!mode, - .value = static_cast(mode ? *mode : 0), - } - }; + struct open_properties properties = { .flags = flags, + .mode = { + .is_set = !!mode, + .value = + static_cast(mode ? *mode : 0), + } }; pthread_mutex_lock(&tracker->lock); if (ACTIVE_COUNT(tracker) == tracker->capacity) { @@ -523,7 +509,7 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker, * the tracker's capacity. */ WARN("Cannot open file system handle, too many unsuspendable file descriptors are opened (%u)", - tracker->count.unsuspendable); + tracker->count.unsuspendable); goto end; } } @@ -532,7 +518,7 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker, if (!handle) { goto end; } - handle->parent = (typeof(handle->parent)) { + handle->parent = (typeof(handle->parent)){ .get_fd = fs_handle_tracked_get_fd, .put_fd = fs_handle_tracked_put_fd, .unlink = fs_handle_tracked_unlink, @@ -541,7 +527,7 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker, handle->tracker = tracker; - ret = pthread_mutex_init(&handle->lock, NULL); + ret = pthread_mutex_init(&handle->lock, nullptr); if (ret) { PERROR("Failed to initialize handle mutex while creating fs handle"); goto error_mutex_init; @@ -555,9 +541,8 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker, handle->properties = properties; - handle->inode = lttng_inode_registry_get_inode(tracker->inode_registry, - directory, path, handle->fd, - tracker->unlinked_file_pool); + handle->inode = lttng_inode_registry_get_inode( + tracker->inode_registry, directory, path, handle->fd, tracker->unlinked_file_pool); if (!handle->inode) { ERR("Failed to get lttng_inode corresponding to file %s", path); goto error; @@ -572,7 +557,7 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker, fd_tracker_track(tracker, handle); end: pthread_mutex_unlock(&tracker->lock); - return handle ? &handle->parent : NULL; + return handle ? &handle->parent : nullptr; error: if (handle->inode) { lttng_inode_put(handle->inode); @@ -580,20 +565,18 @@ error: pthread_mutex_destroy(&handle->lock); error_mutex_init: free(handle); - handle = NULL; + handle = nullptr; goto end; } /* Caller must hold the tracker's lock. */ -static int fd_tracker_suspend_handles( - struct fd_tracker *tracker, unsigned int count) +static int fd_tracker_suspend_handles(struct fd_tracker *tracker, unsigned int count) { unsigned int left_to_close = count; unsigned int attempts_left = tracker->count.suspendable.active; struct fs_handle_tracked *handle, *tmp; - cds_list_for_each_entry_safe(handle, tmp, &tracker->active_handles, - handles_list_node) { + cds_list_for_each_entry_safe (handle, tmp, &tracker->active_handles, handles_list_node) { int ret; fd_tracker_untrack(tracker, handle); @@ -612,15 +595,16 @@ static int fd_tracker_suspend_handles( } int fd_tracker_open_unsuspendable_fd(struct fd_tracker *tracker, - int *out_fds, - const char **names, - unsigned int fd_count, - fd_open_cb open, - void *user_data) + int *out_fds, + const char **names, + unsigned int fd_count, + fd_open_cb open, + void *user_data) { int ret, user_ret, i, fds_to_suspend; unsigned int active_fds; struct unsuspendable_fd **entries; + lttng::urcu::read_lock_guard read_lock; entries = calloc(fd_count); if (!entries) { @@ -631,12 +615,10 @@ int fd_tracker_open_unsuspendable_fd(struct fd_tracker *tracker, pthread_mutex_lock(&tracker->lock); active_fds = ACTIVE_COUNT(tracker); - fds_to_suspend = (int) active_fds + (int) fd_count - - (int) tracker->capacity; + fds_to_suspend = (int) active_fds + (int) fd_count - (int) tracker->capacity; if (fds_to_suspend > 0) { if (fds_to_suspend <= tracker->count.suspendable.active) { - ret = fd_tracker_suspend_handles( - tracker, fds_to_suspend); + ret = fd_tracker_suspend_handles(tracker, fds_to_suspend); if (ret) { goto end_unlock; } @@ -647,7 +629,7 @@ int fd_tracker_open_unsuspendable_fd(struct fd_tracker *tracker, * tracker's capacity. */ WARN("Cannot open unsuspendable fd, too many unsuspendable file descriptors are opened (%u)", - tracker->count.unsuspendable); + tracker->count.unsuspendable); ret = -EMFILE; goto end_unlock; } @@ -664,8 +646,8 @@ int fd_tracker_open_unsuspendable_fd(struct fd_tracker *tracker, * of unsuspendable fds. */ for (i = 0; i < fd_count; i++) { - struct unsuspendable_fd *entry = unsuspendable_fd_create( - names ? names[i] : NULL, out_fds[i]); + struct unsuspendable_fd *entry = + unsuspendable_fd_create(names ? names[i] : nullptr, out_fds[i]); if (!entry) { ret = -1; @@ -674,27 +656,24 @@ int fd_tracker_open_unsuspendable_fd(struct fd_tracker *tracker, entries[i] = entry; } - rcu_read_lock(); for (i = 0; i < fd_count; i++) { struct cds_lfht_node *node; struct unsuspendable_fd *entry = entries[i]; node = cds_lfht_add_unique(tracker->unsuspendable_fds, - hash_key_ulong((void *) (unsigned long) - out_fds[i], - seed.value), - match_fd, (void *) (unsigned long) out_fds[i], - &entry->tracker_node); + hash_key_ulong((void *) (unsigned long) out_fds[i], + seed.value), + match_fd, + (void *) (unsigned long) out_fds[i], + &entry->tracker_node); if (node != &entry->tracker_node) { ret = -EEXIST; - rcu_read_unlock(); goto end_free_entries; } - entries[i] = NULL; + entries[i] = nullptr; } tracker->count.unsuspendable += fd_count; - rcu_read_unlock(); ret = user_ret; end_unlock: pthread_mutex_unlock(&tracker->lock); @@ -709,13 +688,14 @@ end_free_entries: } int fd_tracker_close_unsuspendable_fd(struct fd_tracker *tracker, - int *fds_in, - unsigned int fd_count, - fd_close_cb close, - void *user_data) + int *fds_in, + unsigned int fd_count, + fd_close_cb close, + void *user_data) { int i, ret, user_ret; - int *fds = NULL; + int *fds = nullptr; + lttng::urcu::read_lock_guard read_lock; /* * Maintain a local copy of fds_in as the user's callback may modify its @@ -729,7 +709,6 @@ int fd_tracker_close_unsuspendable_fd(struct fd_tracker *tracker, memcpy(fds, fds_in, sizeof(*fds) * fd_count); pthread_mutex_lock(&tracker->lock); - rcu_read_lock(); /* Let the user close the file descriptors. */ user_ret = close(user_data, fds_in); @@ -745,20 +724,19 @@ int fd_tracker_close_unsuspendable_fd(struct fd_tracker *tracker, struct unsuspendable_fd *entry; cds_lfht_lookup(tracker->unsuspendable_fds, - hash_key_ulong((void *) (unsigned long) fds[i], - seed.value), - match_fd, (void *) (unsigned long) fds[i], + hash_key_ulong((void *) (unsigned long) fds[i], seed.value), + match_fd, + (void *) (unsigned long) fds[i], &iter); node = cds_lfht_iter_get_node(&iter); if (!node) { /* Unknown file descriptor. */ WARN("Untracked file descriptor %d passed to fd_tracker_close_unsuspendable_fd()", - fds[i]); + fds[i]); ret = -EINVAL; goto end_unlock; } - entry = caa_container_of( - node, struct unsuspendable_fd, tracker_node); + entry = lttng::utils::container_of(node, &unsuspendable_fd::tracker_node); cds_lfht_del(tracker->unsuspendable_fds, node); unsuspendable_fd_destroy(entry); @@ -768,7 +746,6 @@ int fd_tracker_close_unsuspendable_fd(struct fd_tracker *tracker, tracker->count.unsuspendable -= fd_count; ret = 0; end_unlock: - rcu_read_unlock(); pthread_mutex_unlock(&tracker->lock); free(fds); end: @@ -776,23 +753,19 @@ end: } /* Caller must have taken the tracker's and handle's locks. */ -static void fd_tracker_track( - struct fd_tracker *tracker, struct fs_handle_tracked *handle) +static void fd_tracker_track(struct fd_tracker *tracker, struct fs_handle_tracked *handle) { if (handle->fd >= 0) { tracker->count.suspendable.active++; - cds_list_add_tail(&handle->handles_list_node, - &tracker->active_handles); + cds_list_add_tail(&handle->handles_list_node, &tracker->active_handles); } else { tracker->count.suspendable.suspended++; - cds_list_add_tail(&handle->handles_list_node, - &tracker->suspended_handles); + cds_list_add_tail(&handle->handles_list_node, &tracker->suspended_handles); } } /* Caller must have taken the tracker's and handle's locks. */ -static void fd_tracker_untrack( - struct fd_tracker *tracker, struct fs_handle_tracked *handle) +static void fd_tracker_untrack(struct fd_tracker *tracker, struct fs_handle_tracked *handle) { if (handle->fd >= 0) { tracker->count.suspendable.active--; @@ -803,8 +776,7 @@ static void fd_tracker_untrack( } /* Caller must have taken the tracker's and handle's locks. */ -static int fd_tracker_restore_handle( - struct fd_tracker *tracker, struct fs_handle_tracked *handle) +static int fd_tracker_restore_handle(struct fd_tracker *tracker, struct fs_handle_tracked *handle) { int ret; @@ -825,7 +797,7 @@ static int fs_handle_tracked_get_fd(struct fs_handle *_handle) { int ret; struct fs_handle_tracked *handle = - container_of(_handle, struct fs_handle_tracked, parent); + lttng::utils::container_of(_handle, &fs_handle_tracked::parent); /* * TODO This should be optimized as it is a fairly hot path. @@ -866,7 +838,7 @@ end: static void fs_handle_tracked_put_fd(struct fs_handle *_handle) { struct fs_handle_tracked *handle = - container_of(_handle, struct fs_handle_tracked, parent); + lttng::utils::container_of(_handle, &fs_handle_tracked::parent); pthread_mutex_lock(&handle->lock); handle->in_use = false; @@ -877,7 +849,7 @@ static int fs_handle_tracked_unlink(struct fs_handle *_handle) { int ret; struct fs_handle_tracked *handle = - container_of(_handle, struct fs_handle_tracked, parent); + lttng::utils::container_of(_handle, &fs_handle_tracked::parent); pthread_mutex_lock(&handle->tracker->lock); pthread_mutex_lock(&handle->lock); @@ -890,10 +862,10 @@ static int fs_handle_tracked_unlink(struct fs_handle *_handle) static int fs_handle_tracked_close(struct fs_handle *_handle) { int ret = 0; - const char *path = NULL; + const char *path = nullptr; struct fs_handle_tracked *handle = - container_of(_handle, struct fs_handle_tracked, parent); - struct lttng_directory_handle *inode_directory_handle = NULL; + lttng::utils::container_of(_handle, &fs_handle_tracked::parent); + struct lttng_directory_handle *inode_directory_handle = nullptr; if (!handle) { ret = -EINVAL; @@ -903,7 +875,7 @@ static int fs_handle_tracked_close(struct fs_handle *_handle) pthread_mutex_lock(&handle->tracker->lock); pthread_mutex_lock(&handle->lock); if (handle->inode) { - lttng_inode_borrow_location(handle->inode, NULL, &path); + lttng_inode_borrow_location(handle->inode, nullptr, &path); /* * Here a reference to the inode's directory handle is acquired * to prevent the last reference to it from being released while @@ -923,9 +895,7 @@ static int fs_handle_tracked_close(struct fs_handle *_handle) * enough to not attempt to recursively acquire the tracker's * lock twice. */ - inode_directory_handle = - lttng_inode_get_location_directory_handle( - handle->inode); + inode_directory_handle = lttng_inode_get_location_directory_handle(handle->inode); } fd_tracker_untrack(handle->tracker, handle); if (handle->fd >= 0) { @@ -935,7 +905,8 @@ static int fs_handle_tracked_close(struct fs_handle *_handle) */ if (close(handle->fd)) { PERROR("Failed to close the file descriptor (%d) of fs handle to %s, close() returned", - handle->fd, path ? path : "Unknown"); + handle->fd, + path ? path : "Unknown"); } handle->fd = -1; }