2 * Copyright (C) 2018, 2020 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <urcu/list.h>
20 #include <urcu/rculfhash.h>
27 #include <sys/types.h>
29 #include <common/defaults.h>
30 #include <common/error.h>
31 #include <common/hashtable/hashtable.h>
32 #include <common/hashtable/utils.h>
33 #include <common/macros.h>
34 #include <common/fs-handle-internal.h>
36 #include "fd-tracker.h"
39 /* Tracker lock must be taken by the user. */
40 #define TRACKED_COUNT(tracker) \
41 (tracker->count.suspendable.active + \
42 tracker->count.suspendable.suspended + \
43 tracker->count.unsuspendable)
45 /* Tracker lock must be taken by the user. */
46 #define ACTIVE_COUNT(tracker) \
47 (tracker->count.suspendable.active + tracker->count.unsuspendable)
49 /* Tracker lock must be taken by the user. */
50 #define SUSPENDED_COUNT(tracker) (tracker->count.suspendable.suspended)
52 /* Tracker lock must be taken by the user. */
53 #define SUSPENDABLE_COUNT(tracker) \
54 (tracker->count.suspendable.active + \
55 tracker->count.suspendable.suspended)
57 /* Tracker lock must be taken by the user. */
58 #define UNSUSPENDABLE_COUNT(tracker) (tracker->count.unsuspendable)
65 unsigned int suspended
;
67 unsigned int unsuspendable
;
69 unsigned int capacity
;
73 /* Failures to suspend or restore fs handles. */
77 * The head of the active_handles list is always the least recently
78 * used active handle. When an handle is used, it is removed from the
79 * list and added to the end. When a file has to be suspended, the
80 * first element in the list is "popped", suspended, and added to the
81 * list of suspended handles.
83 struct cds_list_head active_handles
;
84 struct cds_list_head suspended_handles
;
85 struct cds_lfht
*unsuspendable_fds
;
86 struct lttng_inode_registry
*inode_registry
;
89 struct open_properties
{
98 * A fs_handle_tracked is not ref-counted. Therefore, it is assumed that a
99 * handle is never in-use while it is being reclaimed. It can be
100 * shared by multiple threads, but external synchronization is required
101 * to ensure it is not still being used when it is reclaimed (close method).
102 * In this respect, it is not different from a regular file descriptor.
104 * The fs_handle lock always nests _within_ the tracker's lock.
106 struct fs_handle_tracked
{
107 struct fs_handle parent
;
108 pthread_mutex_t lock
;
110 * Weak reference to the tracker. All fs_handles are assumed to have
111 * been closed at the moment of the destruction of the fd_tracker.
113 struct fd_tracker
*tracker
;
114 struct open_properties properties
;
115 struct lttng_inode
*inode
;
117 /* inode number of the file at the time of the handle's creation. */
120 /* Offset to which the file should be restored. */
122 struct cds_list_head handles_list_node
;
125 struct unsuspendable_fd
{
127 * Accesses are only performed through the tracker, which is protected
132 struct cds_lfht_node tracker_node
;
133 struct rcu_head rcu_head
;
137 pthread_mutex_t lock
;
141 .lock
= PTHREAD_MUTEX_INITIALIZER
,
144 static int match_fd(struct cds_lfht_node
*node
, const void *key
);
145 static void unsuspendable_fd_destroy(struct unsuspendable_fd
*entry
);
146 static struct unsuspendable_fd
*unsuspendable_fd_create(
147 const char *name
, int fd
);
148 static int open_from_properties(
149 const char *path
, struct open_properties
*properties
);
151 static void fs_handle_tracked_log(struct fs_handle_tracked
*handle
);
152 static int fs_handle_tracked_suspend(struct fs_handle_tracked
*handle
);
153 static int fs_handle_tracked_restore(struct fs_handle_tracked
*handle
);
154 static int fs_handle_tracked_get_fd(struct fs_handle
*_handle
);
155 static void fs_handle_tracked_put_fd(struct fs_handle
*_handle
);
156 static int fs_handle_tracked_unlink(struct fs_handle
*_handle
);
157 static int fs_handle_tracked_close(struct fs_handle
*_handle
);
159 static void fd_tracker_track(
160 struct fd_tracker
*tracker
, struct fs_handle_tracked
*handle
);
161 static void fd_tracker_untrack(
162 struct fd_tracker
*tracker
, struct fs_handle_tracked
*handle
);
163 static int fd_tracker_suspend_handles(
164 struct fd_tracker
*tracker
, unsigned int count
);
165 static int fd_tracker_restore_handle(
166 struct fd_tracker
*tracker
, struct fs_handle_tracked
*handle
);
168 static const struct fs_handle fs_handle_tracked_callbacks
= {
169 .get_fd
= fs_handle_tracked_get_fd
,
170 .put_fd
= fs_handle_tracked_put_fd
,
171 .unlink
= fs_handle_tracked_unlink
,
172 .close
= fs_handle_tracked_close
,
175 /* Match function of the tracker's unsuspendable_fds hash table. */
176 static int match_fd(struct cds_lfht_node
*node
, const void *key
)
178 struct unsuspendable_fd
*entry
= caa_container_of(
179 node
, struct unsuspendable_fd
, tracker_node
);
181 return hash_match_key_ulong(
182 (void *) (unsigned long) entry
->fd
, (void *) key
);
185 static void delete_unsuspendable_fd(struct rcu_head
*head
)
187 struct unsuspendable_fd
*fd
= caa_container_of(
188 head
, struct unsuspendable_fd
, rcu_head
);
194 static void unsuspendable_fd_destroy(struct unsuspendable_fd
*entry
)
199 call_rcu(&entry
->rcu_head
, delete_unsuspendable_fd
);
202 static struct unsuspendable_fd
*unsuspendable_fd_create(
203 const char *name
, int fd
)
205 struct unsuspendable_fd
*entry
= zmalloc(sizeof(*entry
));
211 entry
->name
= strdup(name
);
216 cds_lfht_node_init(&entry
->tracker_node
);
220 unsuspendable_fd_destroy(entry
);
224 static void fs_handle_tracked_log(struct fs_handle_tracked
*handle
)
228 pthread_mutex_lock(&handle
->lock
);
229 path
= lttng_inode_get_path(handle
->inode
);
231 if (handle
->fd
>= 0) {
232 DBG_NO_LOC(" %s [active, fd %d%s]", path
, handle
->fd
,
233 handle
->in_use
? ", in use" : "");
235 DBG_NO_LOC(" %s [suspended]", path
);
237 pthread_mutex_unlock(&handle
->lock
);
240 /* Tracker lock must be held by the caller. */
241 static int fs_handle_tracked_suspend(struct fs_handle_tracked
*handle
)
247 pthread_mutex_lock(&handle
->lock
);
248 path
= lttng_inode_get_path(handle
->inode
);
249 assert(handle
->fd
>= 0);
250 if (handle
->in_use
) {
251 /* This handle can't be suspended as it is currently in use. */
256 ret
= stat(path
, &fs_stat
);
258 PERROR("Filesystem handle to %s cannot be suspended as stat() failed",
264 if (fs_stat
.st_ino
!= handle
->ino
) {
265 /* Don't suspend as the handle would not be restorable. */
266 WARN("Filesystem handle to %s cannot be suspended as its inode changed",
272 handle
->offset
= lseek(handle
->fd
, 0, SEEK_CUR
);
273 if (handle
->offset
== -1) {
274 WARN("Filesystem handle to %s cannot be suspended as lseek() failed to sample its current position",
280 ret
= close(handle
->fd
);
282 PERROR("Filesystem handle to %s cannot be suspended as close() failed",
287 DBG("Suspended filesystem handle to %s (fd %i) at position %" PRId64
,
288 path
, handle
->fd
, handle
->offset
);
292 handle
->tracker
->stats
.errors
++;
294 pthread_mutex_unlock(&handle
->lock
);
298 /* Caller must hold the tracker and handle's locks. */
299 static int fs_handle_tracked_restore(struct fs_handle_tracked
*handle
)
302 const char *path
= lttng_inode_get_path(handle
->inode
);
304 assert(handle
->fd
== -1);
306 ret
= open_from_properties(path
, &handle
->properties
);
308 PERROR("Failed to restore filesystem handle to %s, open() failed",
315 ret
= lseek(fd
, handle
->offset
, SEEK_SET
);
317 PERROR("Failed to restore filesystem handle to %s, lseek() failed",
322 DBG("Restored filesystem handle to %s (fd %i) at position %" PRId64
,
323 path
, fd
, handle
->offset
);
334 static int open_from_properties(
335 const char *path
, struct open_properties
*properties
)
340 * open() ignores the 'flags' parameter unless the O_CREAT or O_TMPFILE
341 * flags are set. O_TMPFILE would not make sense in the context of a
342 * suspendable fs_handle as it would not be restorable (see OPEN(2)),
343 * thus it is ignored here.
345 if ((properties
->flags
& O_CREAT
) && properties
->mode
.is_set
) {
346 ret
= open(path
, properties
->flags
, properties
->mode
.value
);
348 ret
= open(path
, properties
->flags
);
351 * Some flags should not be used beyond the initial open() of a
352 * restorable file system handle. O_CREAT and O_TRUNC must
353 * be cleared since it would be unexpected to re-use them
354 * when the handle is retored:
355 * - O_CREAT should not be needed as the file has been created
356 * on the initial call to open(),
357 * - O_TRUNC would destroy the file's contents by truncating it
360 properties
->flags
&= ~(O_CREAT
| O_TRUNC
);
369 struct fd_tracker
*fd_tracker_create(unsigned int capacity
)
371 struct fd_tracker
*tracker
= zmalloc(sizeof(struct fd_tracker
));
377 pthread_mutex_lock(&seed
.lock
);
378 if (!seed
.initialized
) {
379 seed
.value
= (unsigned long) time(NULL
);
380 seed
.initialized
= true;
382 pthread_mutex_unlock(&seed
.lock
);
384 CDS_INIT_LIST_HEAD(&tracker
->active_handles
);
385 CDS_INIT_LIST_HEAD(&tracker
->suspended_handles
);
386 tracker
->capacity
= capacity
;
387 tracker
->unsuspendable_fds
= cds_lfht_new(DEFAULT_HT_SIZE
, 1, 0,
388 CDS_LFHT_AUTO_RESIZE
| CDS_LFHT_ACCOUNTING
, NULL
);
389 if (!tracker
->unsuspendable_fds
) {
390 ERR("Failed to create fd-tracker's unsuspendable_fds hash table");
393 tracker
->inode_registry
= lttng_inode_registry_create();
394 if (!tracker
->inode_registry
) {
395 ERR("Failed to create fd-tracker's inode registry");
398 DBG("File descriptor tracker created with a limit of %u simultaneously-opened FDs",
403 fd_tracker_destroy(tracker
);
407 void fd_tracker_log(struct fd_tracker
*tracker
)
409 struct fs_handle_tracked
*handle
;
410 struct unsuspendable_fd
*unsuspendable_fd
;
411 struct cds_lfht_iter iter
;
413 pthread_mutex_lock(&tracker
->lock
);
414 DBG_NO_LOC("File descriptor tracker");
415 DBG_NO_LOC(" Stats:");
416 DBG_NO_LOC(" uses: %" PRIu64
, tracker
->stats
.uses
);
417 DBG_NO_LOC(" misses: %" PRIu64
, tracker
->stats
.misses
);
418 DBG_NO_LOC(" errors: %" PRIu64
, tracker
->stats
.errors
);
419 DBG_NO_LOC(" Tracked: %u", TRACKED_COUNT(tracker
));
420 DBG_NO_LOC(" active: %u", ACTIVE_COUNT(tracker
));
421 DBG_NO_LOC(" suspendable: %u", SUSPENDABLE_COUNT(tracker
));
422 DBG_NO_LOC(" unsuspendable: %u", UNSUSPENDABLE_COUNT(tracker
));
423 DBG_NO_LOC(" suspended: %u", SUSPENDED_COUNT(tracker
));
424 DBG_NO_LOC(" capacity: %u", tracker
->capacity
);
426 DBG_NO_LOC(" Tracked suspendable file descriptors");
427 cds_list_for_each_entry(
428 handle
, &tracker
->active_handles
, handles_list_node
) {
429 fs_handle_tracked_log(handle
);
431 cds_list_for_each_entry(handle
, &tracker
->suspended_handles
,
433 fs_handle_tracked_log(handle
);
435 if (!SUSPENDABLE_COUNT(tracker
)) {
439 DBG_NO_LOC(" Tracked unsuspendable file descriptors");
441 cds_lfht_for_each_entry(tracker
->unsuspendable_fds
, &iter
,
442 unsuspendable_fd
, tracker_node
) {
443 DBG_NO_LOC(" %s [active, fd %d]",
444 unsuspendable_fd
->name
?: "Unnamed",
445 unsuspendable_fd
->fd
);
448 if (!UNSUSPENDABLE_COUNT(tracker
)) {
452 pthread_mutex_unlock(&tracker
->lock
);
455 int fd_tracker_destroy(struct fd_tracker
*tracker
)
460 * Refuse to destroy the tracker as fs_handles may still old
461 * weak references to the tracker.
463 pthread_mutex_lock(&tracker
->lock
);
464 if (TRACKED_COUNT(tracker
)) {
465 ERR("A file descriptor leak has been detected: %u tracked file descriptors are still being tracked",
466 TRACKED_COUNT(tracker
));
467 pthread_mutex_unlock(&tracker
->lock
);
468 fd_tracker_log(tracker
);
472 pthread_mutex_unlock(&tracker
->lock
);
474 if (tracker
->unsuspendable_fds
) {
475 ret
= cds_lfht_destroy(tracker
->unsuspendable_fds
, NULL
);
479 lttng_inode_registry_destroy(tracker
->inode_registry
);
480 pthread_mutex_destroy(&tracker
->lock
);
486 struct fs_handle
*fd_tracker_open_fs_handle(struct fd_tracker
*tracker
,
492 struct fs_handle_tracked
*handle
= NULL
;
494 struct open_properties properties
= {
496 .mode
.is_set
= !!mode
,
497 .mode
.value
= mode
? *mode
: 0,
500 pthread_mutex_lock(&tracker
->lock
);
501 if (ACTIVE_COUNT(tracker
) == tracker
->capacity
) {
502 if (tracker
->count
.suspendable
.active
> 0) {
503 ret
= fd_tracker_suspend_handles(tracker
, 1);
509 * There are not enough active suspendable file
510 * descriptors to open a new fd and still accommodate
511 * the tracker's capacity.
513 WARN("Cannot open file system handle, too many unsuspendable file descriptors are opened (%u)",
514 tracker
->count
.unsuspendable
);
519 handle
= zmalloc(sizeof(*handle
));
523 handle
->parent
= fs_handle_tracked_callbacks
;
524 handle
->tracker
= tracker
;
526 ret
= pthread_mutex_init(&handle
->lock
, NULL
);
528 PERROR("Failed to initialize handle mutex while creating fs handle");
529 goto error_mutex_init
;
532 handle
->fd
= open_from_properties(path
, &properties
);
533 if (handle
->fd
< 0) {
534 PERROR("Failed to open fs handle to %s, open() returned", path
);
538 handle
->properties
= properties
;
540 handle
->inode
= lttng_inode_registry_get_inode(
541 tracker
->inode_registry
, handle
->fd
, path
);
542 if (!handle
->inode
) {
543 ERR("Failed to get lttng_inode corresponding to file %s", path
);
547 if (fstat(handle
->fd
, &fd_stat
)) {
548 PERROR("Failed to retrieve file descriptor inode while creating fs handle, fstat() returned");
551 handle
->ino
= fd_stat
.st_ino
;
553 fd_tracker_track(tracker
, handle
);
555 pthread_mutex_unlock(&tracker
->lock
);
556 return handle
? &handle
->parent
: NULL
;
559 lttng_inode_put(handle
->inode
);
561 pthread_mutex_destroy(&handle
->lock
);
568 /* Caller must hold the tracker's lock. */
569 static int fd_tracker_suspend_handles(
570 struct fd_tracker
*tracker
, unsigned int count
)
572 unsigned int left_to_close
= count
;
573 struct fs_handle_tracked
*handle
, *tmp
;
575 cds_list_for_each_entry_safe(handle
, tmp
, &tracker
->active_handles
,
579 fd_tracker_untrack(tracker
, handle
);
580 ret
= fs_handle_tracked_suspend(handle
);
581 fd_tracker_track(tracker
, handle
);
586 if (!left_to_close
) {
590 return left_to_close
? -EMFILE
: 0;
593 int fd_tracker_open_unsuspendable_fd(struct fd_tracker
*tracker
,
596 unsigned int fd_count
,
600 int ret
, user_ret
, i
, fds_to_suspend
;
601 unsigned int active_fds
;
602 struct unsuspendable_fd
**entries
;
604 entries
= zmalloc(fd_count
* sizeof(*entries
));
610 pthread_mutex_lock(&tracker
->lock
);
612 active_fds
= ACTIVE_COUNT(tracker
);
613 fds_to_suspend
= (int) active_fds
+ (int) fd_count
-
614 (int) tracker
->capacity
;
615 if (fds_to_suspend
> 0) {
616 if (fds_to_suspend
<= tracker
->count
.suspendable
.active
) {
617 ret
= fd_tracker_suspend_handles(
618 tracker
, fds_to_suspend
);
624 * There are not enough active suspendable file
625 * descriptors to open a new fd and still accomodate the
626 * tracker's capacity.
628 WARN("Cannot open unsuspendable fd, too many unsuspendable file descriptors are opened (%u)",
629 tracker
->count
.unsuspendable
);
635 user_ret
= open(user_data
, out_fds
);
642 * Add the fds returned by the user's callback to the hashtable
643 * of unsuspendable fds.
645 for (i
= 0; i
< fd_count
; i
++) {
646 struct unsuspendable_fd
*entry
= unsuspendable_fd_create(
647 names
? names
[i
] : NULL
, out_fds
[i
]);
651 goto end_free_entries
;
657 for (i
= 0; i
< fd_count
; i
++) {
658 struct cds_lfht_node
*node
;
659 struct unsuspendable_fd
*entry
= entries
[i
];
661 node
= cds_lfht_add_unique(tracker
->unsuspendable_fds
,
662 hash_key_ulong((void *) (unsigned long)
665 match_fd
, (void *) (unsigned long) out_fds
[i
],
666 &entry
->tracker_node
);
668 if (node
!= &entry
->tracker_node
) {
671 goto end_free_entries
;
675 tracker
->count
.unsuspendable
+= fd_count
;
679 pthread_mutex_unlock(&tracker
->lock
);
684 for (i
= 0; i
< fd_count
; i
++) {
685 unsuspendable_fd_destroy(entries
[i
]);
690 int fd_tracker_close_unsuspendable_fd(struct fd_tracker
*tracker
,
692 unsigned int fd_count
,
696 int i
, ret
, user_ret
;
700 * Maintain a local copy of fds_in as the user's callback may modify its
701 * contents (e.g. setting the fd(s) to -1 after close).
703 fds
= malloc(sizeof(*fds
) * fd_count
);
708 memcpy(fds
, fds_in
, sizeof(*fds
) * fd_count
);
710 pthread_mutex_lock(&tracker
->lock
);
713 /* Let the user close the file descriptors. */
714 user_ret
= close(user_data
, fds_in
);
720 /* Untrack the fds that were just closed by the user's callback. */
721 for (i
= 0; i
< fd_count
; i
++) {
722 struct cds_lfht_node
*node
;
723 struct cds_lfht_iter iter
;
724 struct unsuspendable_fd
*entry
;
726 cds_lfht_lookup(tracker
->unsuspendable_fds
,
727 hash_key_ulong((void *) (unsigned long) fds
[i
],
729 match_fd
, (void *) (unsigned long) fds
[i
],
731 node
= cds_lfht_iter_get_node(&iter
);
733 /* Unknown file descriptor. */
734 WARN("Untracked file descriptor %d passed to fd_tracker_close_unsuspendable_fd()",
739 entry
= caa_container_of(
740 node
, struct unsuspendable_fd
, tracker_node
);
742 cds_lfht_del(tracker
->unsuspendable_fds
, node
);
743 unsuspendable_fd_destroy(entry
);
747 tracker
->count
.unsuspendable
-= fd_count
;
751 pthread_mutex_unlock(&tracker
->lock
);
757 /* Caller must have taken the tracker's and handle's locks. */
758 static void fd_tracker_track(
759 struct fd_tracker
*tracker
, struct fs_handle_tracked
*handle
)
761 if (handle
->fd
>= 0) {
762 tracker
->count
.suspendable
.active
++;
763 cds_list_add_tail(&handle
->handles_list_node
,
764 &tracker
->active_handles
);
766 tracker
->count
.suspendable
.suspended
++;
767 cds_list_add_tail(&handle
->handles_list_node
,
768 &tracker
->suspended_handles
);
772 /* Caller must have taken the tracker's and handle's locks. */
773 static void fd_tracker_untrack(
774 struct fd_tracker
*tracker
, struct fs_handle_tracked
*handle
)
776 if (handle
->fd
>= 0) {
777 tracker
->count
.suspendable
.active
--;
779 tracker
->count
.suspendable
.suspended
--;
781 cds_list_del(&handle
->handles_list_node
);
784 /* Caller must have taken the tracker's and handle's locks. */
785 static int fd_tracker_restore_handle(
786 struct fd_tracker
*tracker
, struct fs_handle_tracked
*handle
)
790 fd_tracker_untrack(tracker
, handle
);
791 if (ACTIVE_COUNT(tracker
) >= tracker
->capacity
) {
792 ret
= fd_tracker_suspend_handles(tracker
, 1);
797 ret
= fs_handle_tracked_restore(handle
);
799 fd_tracker_track(tracker
, handle
);
800 return ret
? ret
: handle
->fd
;
803 static int fs_handle_tracked_get_fd(struct fs_handle
*_handle
)
806 struct fs_handle_tracked
*handle
=
807 container_of(_handle
, struct fs_handle_tracked
, parent
);
810 * TODO This should be optimized as it is a fairly hot path.
811 * The fd-tracker's lock should only be taken when a fs_handle is
812 * restored (slow path). On the fast path (fs_handle is active),
813 * the only effect on the fd_tracker is marking the handle as the
814 * most recently used. Currently, it is done by a call to the
815 * track/untrack helpers, but it should be done atomically.
817 * Note that the lock's nesting order must still be respected here.
818 * The handle's lock nests inside the tracker's lock.
820 pthread_mutex_lock(&handle
->tracker
->lock
);
821 pthread_mutex_lock(&handle
->lock
);
822 assert(!handle
->in_use
);
824 handle
->tracker
->stats
.uses
++;
825 if (handle
->fd
>= 0) {
827 /* Mark as most recently used. */
828 fd_tracker_untrack(handle
->tracker
, handle
);
829 fd_tracker_track(handle
->tracker
, handle
);
831 handle
->tracker
->stats
.misses
++;
832 ret
= fd_tracker_restore_handle(handle
->tracker
, handle
);
834 handle
->tracker
->stats
.errors
++;
838 handle
->in_use
= true;
840 pthread_mutex_unlock(&handle
->lock
);
841 pthread_mutex_unlock(&handle
->tracker
->lock
);
845 static void fs_handle_tracked_put_fd(struct fs_handle
*_handle
)
847 struct fs_handle_tracked
*handle
=
848 container_of(_handle
, struct fs_handle_tracked
, parent
);
850 pthread_mutex_lock(&handle
->lock
);
851 handle
->in_use
= false;
852 pthread_mutex_unlock(&handle
->lock
);
855 static int fs_handle_tracked_unlink(struct fs_handle
*_handle
)
858 struct fs_handle_tracked
*handle
=
859 container_of(_handle
, struct fs_handle_tracked
, parent
);
861 pthread_mutex_lock(&handle
->tracker
->lock
);
862 pthread_mutex_lock(&handle
->lock
);
863 ret
= lttng_inode_defer_unlink(handle
->inode
);
864 pthread_mutex_unlock(&handle
->lock
);
865 pthread_mutex_unlock(&handle
->tracker
->lock
);
869 static int fs_handle_tracked_close(struct fs_handle
*_handle
)
872 const char *path
= NULL
;
873 struct fs_handle_tracked
*handle
=
874 container_of(_handle
, struct fs_handle_tracked
, parent
);
881 pthread_mutex_lock(&handle
->tracker
->lock
);
882 pthread_mutex_lock(&handle
->lock
);
884 path
= lttng_inode_get_path(handle
->inode
);
886 fd_tracker_untrack(handle
->tracker
, handle
);
887 if (handle
->fd
>= 0) {
889 * The return value of close() is not propagated as there
890 * isn't much the user can do about it.
892 if (close(handle
->fd
)) {
893 PERROR("Failed to close the file descritptor (%d) of fs handle to %s, close() returned",
894 handle
->fd
, path
? path
: "Unknown");
899 lttng_inode_put(handle
->inode
);
901 pthread_mutex_unlock(&handle
->lock
);
902 pthread_mutex_destroy(&handle
->lock
);
903 pthread_mutex_unlock(&handle
->tracker
->lock
);