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/fs-handle-internal.h>
32 #include <common/hashtable/hashtable.h>
33 #include <common/hashtable/utils.h>
34 #include <common/macros.h>
35 #include <common/optional.h>
37 #include "fd-tracker.h"
40 /* Tracker lock must be taken by the user. */
41 #define TRACKED_COUNT(tracker) \
42 (tracker->count.suspendable.active + \
43 tracker->count.suspendable.suspended + \
44 tracker->count.unsuspendable)
46 /* Tracker lock must be taken by the user. */
47 #define ACTIVE_COUNT(tracker) \
48 (tracker->count.suspendable.active + tracker->count.unsuspendable)
50 /* Tracker lock must be taken by the user. */
51 #define SUSPENDED_COUNT(tracker) (tracker->count.suspendable.suspended)
53 /* Tracker lock must be taken by the user. */
54 #define SUSPENDABLE_COUNT(tracker) \
55 (tracker->count.suspendable.active + \
56 tracker->count.suspendable.suspended)
58 /* Tracker lock must be taken by the user. */
59 #define UNSUSPENDABLE_COUNT(tracker) (tracker->count.unsuspendable)
66 unsigned int suspended
;
68 unsigned int unsuspendable
;
70 unsigned int capacity
;
74 /* Failures to suspend or restore fs handles. */
78 * The head of the active_handles list is always the least recently
79 * used active handle. When an handle is used, it is removed from the
80 * list and added to the end. When a file has to be suspended, the
81 * first element in the list is "popped", suspended, and added to the
82 * list of suspended handles.
84 struct cds_list_head active_handles
;
85 struct cds_list_head suspended_handles
;
86 struct cds_lfht
*unsuspendable_fds
;
87 struct lttng_inode_registry
*inode_registry
;
90 struct open_properties
{
92 LTTNG_OPTIONAL(mode_t
) mode
;
96 * A fs_handle_tracked is not ref-counted. Therefore, it is assumed that a
97 * handle is never in-use while it is being reclaimed. It can be
98 * shared by multiple threads, but external synchronization is required
99 * to ensure it is not still being used when it is reclaimed (close method).
100 * In this respect, it is not different from a regular file descriptor.
102 * The fs_handle lock always nests _within_ the tracker's lock.
104 struct fs_handle_tracked
{
105 struct fs_handle parent
;
106 pthread_mutex_t lock
;
108 * Weak reference to the tracker. All fs_handles are assumed to have
109 * been closed at the moment of the destruction of the fd_tracker.
111 struct fd_tracker
*tracker
;
112 struct open_properties properties
;
113 struct lttng_inode
*inode
;
115 /* inode number of the file at the time of the handle's creation. */
118 /* Offset to which the file should be restored. */
120 struct cds_list_head handles_list_node
;
123 struct unsuspendable_fd
{
125 * Accesses are only performed through the tracker, which is protected
130 struct cds_lfht_node tracker_node
;
131 struct rcu_head rcu_head
;
135 pthread_mutex_t lock
;
139 .lock
= PTHREAD_MUTEX_INITIALIZER
,
142 static int match_fd(struct cds_lfht_node
*node
, const void *key
);
143 static void unsuspendable_fd_destroy(struct unsuspendable_fd
*entry
);
144 static struct unsuspendable_fd
*unsuspendable_fd_create(
145 const char *name
, int fd
);
146 static int open_from_properties(
147 const char *path
, struct open_properties
*properties
);
149 static void fs_handle_tracked_log(struct fs_handle_tracked
*handle
);
150 static int fs_handle_tracked_suspend(struct fs_handle_tracked
*handle
);
151 static int fs_handle_tracked_restore(struct fs_handle_tracked
*handle
);
152 static int fs_handle_tracked_get_fd(struct fs_handle
*_handle
);
153 static void fs_handle_tracked_put_fd(struct fs_handle
*_handle
);
154 static int fs_handle_tracked_unlink(struct fs_handle
*_handle
);
155 static int fs_handle_tracked_close(struct fs_handle
*_handle
);
157 static void fd_tracker_track(
158 struct fd_tracker
*tracker
, struct fs_handle_tracked
*handle
);
159 static void fd_tracker_untrack(
160 struct fd_tracker
*tracker
, struct fs_handle_tracked
*handle
);
161 static int fd_tracker_suspend_handles(
162 struct fd_tracker
*tracker
, unsigned int count
);
163 static int fd_tracker_restore_handle(
164 struct fd_tracker
*tracker
, struct fs_handle_tracked
*handle
);
166 static const struct fs_handle fs_handle_tracked_callbacks
= {
167 .get_fd
= fs_handle_tracked_get_fd
,
168 .put_fd
= fs_handle_tracked_put_fd
,
169 .unlink
= fs_handle_tracked_unlink
,
170 .close
= fs_handle_tracked_close
,
173 /* Match function of the tracker's unsuspendable_fds hash table. */
174 static int match_fd(struct cds_lfht_node
*node
, const void *key
)
176 struct unsuspendable_fd
*entry
= caa_container_of(
177 node
, struct unsuspendable_fd
, tracker_node
);
179 return hash_match_key_ulong(
180 (void *) (unsigned long) entry
->fd
, (void *) key
);
183 static void delete_unsuspendable_fd(struct rcu_head
*head
)
185 struct unsuspendable_fd
*fd
= caa_container_of(
186 head
, struct unsuspendable_fd
, rcu_head
);
192 static void unsuspendable_fd_destroy(struct unsuspendable_fd
*entry
)
197 call_rcu(&entry
->rcu_head
, delete_unsuspendable_fd
);
200 static struct unsuspendable_fd
*unsuspendable_fd_create(
201 const char *name
, int fd
)
203 struct unsuspendable_fd
*entry
= zmalloc(sizeof(*entry
));
209 entry
->name
= strdup(name
);
214 cds_lfht_node_init(&entry
->tracker_node
);
218 unsuspendable_fd_destroy(entry
);
222 static void fs_handle_tracked_log(struct fs_handle_tracked
*handle
)
226 pthread_mutex_lock(&handle
->lock
);
227 path
= lttng_inode_get_path(handle
->inode
);
229 if (handle
->fd
>= 0) {
230 DBG_NO_LOC(" %s [active, fd %d%s]", path
, handle
->fd
,
231 handle
->in_use
? ", in use" : "");
233 DBG_NO_LOC(" %s [suspended]", path
);
235 pthread_mutex_unlock(&handle
->lock
);
238 /* Tracker lock must be held by the caller. */
239 static int fs_handle_tracked_suspend(struct fs_handle_tracked
*handle
)
245 pthread_mutex_lock(&handle
->lock
);
246 path
= lttng_inode_get_path(handle
->inode
);
247 assert(handle
->fd
>= 0);
248 if (handle
->in_use
) {
249 /* This handle can't be suspended as it is currently in use. */
254 ret
= stat(path
, &fs_stat
);
256 PERROR("Filesystem handle to %s cannot be suspended as stat() failed",
262 if (fs_stat
.st_ino
!= handle
->ino
) {
263 /* Don't suspend as the handle would not be restorable. */
264 WARN("Filesystem handle to %s cannot be suspended as its inode changed",
270 handle
->offset
= lseek(handle
->fd
, 0, SEEK_CUR
);
271 if (handle
->offset
== -1) {
272 WARN("Filesystem handle to %s cannot be suspended as lseek() failed to sample its current position",
278 ret
= close(handle
->fd
);
280 PERROR("Filesystem handle to %s cannot be suspended as close() failed",
285 DBG("Suspended filesystem handle to %s (fd %i) at position %" PRId64
,
286 path
, handle
->fd
, handle
->offset
);
290 handle
->tracker
->stats
.errors
++;
292 pthread_mutex_unlock(&handle
->lock
);
296 /* Caller must hold the tracker and handle's locks. */
297 static int fs_handle_tracked_restore(struct fs_handle_tracked
*handle
)
300 const char *path
= lttng_inode_get_path(handle
->inode
);
302 assert(handle
->fd
== -1);
304 ret
= open_from_properties(path
, &handle
->properties
);
306 PERROR("Failed to restore filesystem handle to %s, open() failed",
313 ret
= lseek(fd
, handle
->offset
, SEEK_SET
);
315 PERROR("Failed to restore filesystem handle to %s, lseek() failed",
320 DBG("Restored filesystem handle to %s (fd %i) at position %" PRId64
,
321 path
, fd
, handle
->offset
);
332 static int open_from_properties(
333 const char *path
, struct open_properties
*properties
)
338 * open() ignores the 'flags' parameter unless the O_CREAT or O_TMPFILE
339 * flags are set. O_TMPFILE would not make sense in the context of a
340 * suspendable fs_handle as it would not be restorable (see OPEN(2)),
341 * thus it is ignored here.
343 if ((properties
->flags
& O_CREAT
) && properties
->mode
.is_set
) {
344 ret
= open(path
, properties
->flags
, properties
->mode
.value
);
346 ret
= open(path
, properties
->flags
);
349 * Some flags should not be used beyond the initial open() of a
350 * restorable file system handle. O_CREAT and O_TRUNC must
351 * be cleared since it would be unexpected to re-use them
352 * when the handle is retored:
353 * - O_CREAT should not be needed as the file has been created
354 * on the initial call to open(),
355 * - O_TRUNC would destroy the file's contents by truncating it
358 properties
->flags
&= ~(O_CREAT
| O_TRUNC
);
367 struct fd_tracker
*fd_tracker_create(unsigned int capacity
)
369 struct fd_tracker
*tracker
= zmalloc(sizeof(struct fd_tracker
));
375 pthread_mutex_lock(&seed
.lock
);
376 if (!seed
.initialized
) {
377 seed
.value
= (unsigned long) time(NULL
);
378 seed
.initialized
= true;
380 pthread_mutex_unlock(&seed
.lock
);
382 CDS_INIT_LIST_HEAD(&tracker
->active_handles
);
383 CDS_INIT_LIST_HEAD(&tracker
->suspended_handles
);
384 tracker
->capacity
= capacity
;
385 tracker
->unsuspendable_fds
= cds_lfht_new(DEFAULT_HT_SIZE
, 1, 0,
386 CDS_LFHT_AUTO_RESIZE
| CDS_LFHT_ACCOUNTING
, NULL
);
387 if (!tracker
->unsuspendable_fds
) {
388 ERR("Failed to create fd-tracker's unsuspendable_fds hash table");
391 tracker
->inode_registry
= lttng_inode_registry_create();
392 if (!tracker
->inode_registry
) {
393 ERR("Failed to create fd-tracker's inode registry");
396 DBG("File descriptor tracker created with a limit of %u simultaneously-opened FDs",
401 fd_tracker_destroy(tracker
);
405 void fd_tracker_log(struct fd_tracker
*tracker
)
407 struct fs_handle_tracked
*handle
;
408 struct unsuspendable_fd
*unsuspendable_fd
;
409 struct cds_lfht_iter iter
;
411 pthread_mutex_lock(&tracker
->lock
);
412 DBG_NO_LOC("File descriptor tracker");
413 DBG_NO_LOC(" Stats:");
414 DBG_NO_LOC(" uses: %" PRIu64
, tracker
->stats
.uses
);
415 DBG_NO_LOC(" misses: %" PRIu64
, tracker
->stats
.misses
);
416 DBG_NO_LOC(" errors: %" PRIu64
, tracker
->stats
.errors
);
417 DBG_NO_LOC(" Tracked: %u", TRACKED_COUNT(tracker
));
418 DBG_NO_LOC(" active: %u", ACTIVE_COUNT(tracker
));
419 DBG_NO_LOC(" suspendable: %u", SUSPENDABLE_COUNT(tracker
));
420 DBG_NO_LOC(" unsuspendable: %u", UNSUSPENDABLE_COUNT(tracker
));
421 DBG_NO_LOC(" suspended: %u", SUSPENDED_COUNT(tracker
));
422 DBG_NO_LOC(" capacity: %u", tracker
->capacity
);
424 DBG_NO_LOC(" Tracked suspendable file descriptors");
425 cds_list_for_each_entry(
426 handle
, &tracker
->active_handles
, handles_list_node
) {
427 fs_handle_tracked_log(handle
);
429 cds_list_for_each_entry(handle
, &tracker
->suspended_handles
,
431 fs_handle_tracked_log(handle
);
433 if (!SUSPENDABLE_COUNT(tracker
)) {
437 DBG_NO_LOC(" Tracked unsuspendable file descriptors");
439 cds_lfht_for_each_entry(tracker
->unsuspendable_fds
, &iter
,
440 unsuspendable_fd
, tracker_node
) {
441 DBG_NO_LOC(" %s [active, fd %d]",
442 unsuspendable_fd
->name
?: "Unnamed",
443 unsuspendable_fd
->fd
);
446 if (!UNSUSPENDABLE_COUNT(tracker
)) {
450 pthread_mutex_unlock(&tracker
->lock
);
453 int fd_tracker_destroy(struct fd_tracker
*tracker
)
458 * Refuse to destroy the tracker as fs_handles may still old
459 * weak references to the tracker.
461 pthread_mutex_lock(&tracker
->lock
);
462 if (TRACKED_COUNT(tracker
)) {
463 ERR("A file descriptor leak has been detected: %u tracked file descriptors are still being tracked",
464 TRACKED_COUNT(tracker
));
465 pthread_mutex_unlock(&tracker
->lock
);
466 fd_tracker_log(tracker
);
470 pthread_mutex_unlock(&tracker
->lock
);
472 if (tracker
->unsuspendable_fds
) {
473 ret
= cds_lfht_destroy(tracker
->unsuspendable_fds
, NULL
);
477 lttng_inode_registry_destroy(tracker
->inode_registry
);
478 pthread_mutex_destroy(&tracker
->lock
);
484 struct fs_handle
*fd_tracker_open_fs_handle(struct fd_tracker
*tracker
,
490 struct fs_handle_tracked
*handle
= NULL
;
492 struct open_properties properties
= {
494 .mode
.is_set
= !!mode
,
495 .mode
.value
= mode
? *mode
: 0,
498 pthread_mutex_lock(&tracker
->lock
);
499 if (ACTIVE_COUNT(tracker
) == tracker
->capacity
) {
500 if (tracker
->count
.suspendable
.active
> 0) {
501 ret
= fd_tracker_suspend_handles(tracker
, 1);
507 * There are not enough active suspendable file
508 * descriptors to open a new fd and still accommodate
509 * the tracker's capacity.
511 WARN("Cannot open file system handle, too many unsuspendable file descriptors are opened (%u)",
512 tracker
->count
.unsuspendable
);
517 handle
= zmalloc(sizeof(*handle
));
521 handle
->parent
= fs_handle_tracked_callbacks
;
522 handle
->tracker
= tracker
;
524 ret
= pthread_mutex_init(&handle
->lock
, NULL
);
526 PERROR("Failed to initialize handle mutex while creating fs handle");
527 goto error_mutex_init
;
530 handle
->fd
= open_from_properties(path
, &properties
);
531 if (handle
->fd
< 0) {
532 PERROR("Failed to open fs handle to %s, open() returned", path
);
536 handle
->properties
= properties
;
538 handle
->inode
= lttng_inode_registry_get_inode(
539 tracker
->inode_registry
, handle
->fd
, path
);
540 if (!handle
->inode
) {
541 ERR("Failed to get lttng_inode corresponding to file %s", path
);
545 if (fstat(handle
->fd
, &fd_stat
)) {
546 PERROR("Failed to retrieve file descriptor inode while creating fs handle, fstat() returned");
549 handle
->ino
= fd_stat
.st_ino
;
551 fd_tracker_track(tracker
, handle
);
553 pthread_mutex_unlock(&tracker
->lock
);
554 return handle
? &handle
->parent
: NULL
;
557 lttng_inode_put(handle
->inode
);
559 pthread_mutex_destroy(&handle
->lock
);
566 /* Caller must hold the tracker's lock. */
567 static int fd_tracker_suspend_handles(
568 struct fd_tracker
*tracker
, unsigned int count
)
570 unsigned int left_to_close
= count
;
571 struct fs_handle_tracked
*handle
, *tmp
;
573 cds_list_for_each_entry_safe(handle
, tmp
, &tracker
->active_handles
,
577 fd_tracker_untrack(tracker
, handle
);
578 ret
= fs_handle_tracked_suspend(handle
);
579 fd_tracker_track(tracker
, handle
);
584 if (!left_to_close
) {
588 return left_to_close
? -EMFILE
: 0;
591 int fd_tracker_open_unsuspendable_fd(struct fd_tracker
*tracker
,
594 unsigned int fd_count
,
598 int ret
, user_ret
, i
, fds_to_suspend
;
599 unsigned int active_fds
;
600 struct unsuspendable_fd
**entries
;
602 entries
= zmalloc(fd_count
* sizeof(*entries
));
608 pthread_mutex_lock(&tracker
->lock
);
610 active_fds
= ACTIVE_COUNT(tracker
);
611 fds_to_suspend
= (int) active_fds
+ (int) fd_count
-
612 (int) tracker
->capacity
;
613 if (fds_to_suspend
> 0) {
614 if (fds_to_suspend
<= tracker
->count
.suspendable
.active
) {
615 ret
= fd_tracker_suspend_handles(
616 tracker
, fds_to_suspend
);
622 * There are not enough active suspendable file
623 * descriptors to open a new fd and still accomodate the
624 * tracker's capacity.
626 WARN("Cannot open unsuspendable fd, too many unsuspendable file descriptors are opened (%u)",
627 tracker
->count
.unsuspendable
);
633 user_ret
= open(user_data
, out_fds
);
640 * Add the fds returned by the user's callback to the hashtable
641 * of unsuspendable fds.
643 for (i
= 0; i
< fd_count
; i
++) {
644 struct unsuspendable_fd
*entry
= unsuspendable_fd_create(
645 names
? names
[i
] : NULL
, out_fds
[i
]);
649 goto end_free_entries
;
655 for (i
= 0; i
< fd_count
; i
++) {
656 struct cds_lfht_node
*node
;
657 struct unsuspendable_fd
*entry
= entries
[i
];
659 node
= cds_lfht_add_unique(tracker
->unsuspendable_fds
,
660 hash_key_ulong((void *) (unsigned long)
663 match_fd
, (void *) (unsigned long) out_fds
[i
],
664 &entry
->tracker_node
);
666 if (node
!= &entry
->tracker_node
) {
669 goto end_free_entries
;
673 tracker
->count
.unsuspendable
+= fd_count
;
677 pthread_mutex_unlock(&tracker
->lock
);
682 for (i
= 0; i
< fd_count
; i
++) {
683 unsuspendable_fd_destroy(entries
[i
]);
688 int fd_tracker_close_unsuspendable_fd(struct fd_tracker
*tracker
,
690 unsigned int fd_count
,
694 int i
, ret
, user_ret
;
698 * Maintain a local copy of fds_in as the user's callback may modify its
699 * contents (e.g. setting the fd(s) to -1 after close).
701 fds
= malloc(sizeof(*fds
) * fd_count
);
706 memcpy(fds
, fds_in
, sizeof(*fds
) * fd_count
);
708 pthread_mutex_lock(&tracker
->lock
);
711 /* Let the user close the file descriptors. */
712 user_ret
= close(user_data
, fds_in
);
718 /* Untrack the fds that were just closed by the user's callback. */
719 for (i
= 0; i
< fd_count
; i
++) {
720 struct cds_lfht_node
*node
;
721 struct cds_lfht_iter iter
;
722 struct unsuspendable_fd
*entry
;
724 cds_lfht_lookup(tracker
->unsuspendable_fds
,
725 hash_key_ulong((void *) (unsigned long) fds
[i
],
727 match_fd
, (void *) (unsigned long) fds
[i
],
729 node
= cds_lfht_iter_get_node(&iter
);
731 /* Unknown file descriptor. */
732 WARN("Untracked file descriptor %d passed to fd_tracker_close_unsuspendable_fd()",
737 entry
= caa_container_of(
738 node
, struct unsuspendable_fd
, tracker_node
);
740 cds_lfht_del(tracker
->unsuspendable_fds
, node
);
741 unsuspendable_fd_destroy(entry
);
745 tracker
->count
.unsuspendable
-= fd_count
;
749 pthread_mutex_unlock(&tracker
->lock
);
755 /* Caller must have taken the tracker's and handle's locks. */
756 static void fd_tracker_track(
757 struct fd_tracker
*tracker
, struct fs_handle_tracked
*handle
)
759 if (handle
->fd
>= 0) {
760 tracker
->count
.suspendable
.active
++;
761 cds_list_add_tail(&handle
->handles_list_node
,
762 &tracker
->active_handles
);
764 tracker
->count
.suspendable
.suspended
++;
765 cds_list_add_tail(&handle
->handles_list_node
,
766 &tracker
->suspended_handles
);
770 /* Caller must have taken the tracker's and handle's locks. */
771 static void fd_tracker_untrack(
772 struct fd_tracker
*tracker
, struct fs_handle_tracked
*handle
)
774 if (handle
->fd
>= 0) {
775 tracker
->count
.suspendable
.active
--;
777 tracker
->count
.suspendable
.suspended
--;
779 cds_list_del(&handle
->handles_list_node
);
782 /* Caller must have taken the tracker's and handle's locks. */
783 static int fd_tracker_restore_handle(
784 struct fd_tracker
*tracker
, struct fs_handle_tracked
*handle
)
788 fd_tracker_untrack(tracker
, handle
);
789 if (ACTIVE_COUNT(tracker
) >= tracker
->capacity
) {
790 ret
= fd_tracker_suspend_handles(tracker
, 1);
795 ret
= fs_handle_tracked_restore(handle
);
797 fd_tracker_track(tracker
, handle
);
798 return ret
? ret
: handle
->fd
;
801 static int fs_handle_tracked_get_fd(struct fs_handle
*_handle
)
804 struct fs_handle_tracked
*handle
=
805 container_of(_handle
, struct fs_handle_tracked
, parent
);
808 * TODO This should be optimized as it is a fairly hot path.
809 * The fd-tracker's lock should only be taken when a fs_handle is
810 * restored (slow path). On the fast path (fs_handle is active),
811 * the only effect on the fd_tracker is marking the handle as the
812 * most recently used. Currently, it is done by a call to the
813 * track/untrack helpers, but it should be done atomically.
815 * Note that the lock's nesting order must still be respected here.
816 * The handle's lock nests inside the tracker's lock.
818 pthread_mutex_lock(&handle
->tracker
->lock
);
819 pthread_mutex_lock(&handle
->lock
);
820 assert(!handle
->in_use
);
822 handle
->tracker
->stats
.uses
++;
823 if (handle
->fd
>= 0) {
825 /* Mark as most recently used. */
826 fd_tracker_untrack(handle
->tracker
, handle
);
827 fd_tracker_track(handle
->tracker
, handle
);
829 handle
->tracker
->stats
.misses
++;
830 ret
= fd_tracker_restore_handle(handle
->tracker
, handle
);
832 handle
->tracker
->stats
.errors
++;
836 handle
->in_use
= true;
838 pthread_mutex_unlock(&handle
->lock
);
839 pthread_mutex_unlock(&handle
->tracker
->lock
);
843 static void fs_handle_tracked_put_fd(struct fs_handle
*_handle
)
845 struct fs_handle_tracked
*handle
=
846 container_of(_handle
, struct fs_handle_tracked
, parent
);
848 pthread_mutex_lock(&handle
->lock
);
849 handle
->in_use
= false;
850 pthread_mutex_unlock(&handle
->lock
);
853 static int fs_handle_tracked_unlink(struct fs_handle
*_handle
)
856 struct fs_handle_tracked
*handle
=
857 container_of(_handle
, struct fs_handle_tracked
, parent
);
859 pthread_mutex_lock(&handle
->tracker
->lock
);
860 pthread_mutex_lock(&handle
->lock
);
861 ret
= lttng_inode_defer_unlink(handle
->inode
);
862 pthread_mutex_unlock(&handle
->lock
);
863 pthread_mutex_unlock(&handle
->tracker
->lock
);
867 static int fs_handle_tracked_close(struct fs_handle
*_handle
)
870 const char *path
= NULL
;
871 struct fs_handle_tracked
*handle
=
872 container_of(_handle
, struct fs_handle_tracked
, parent
);
879 pthread_mutex_lock(&handle
->tracker
->lock
);
880 pthread_mutex_lock(&handle
->lock
);
882 path
= lttng_inode_get_path(handle
->inode
);
884 fd_tracker_untrack(handle
->tracker
, handle
);
885 if (handle
->fd
>= 0) {
887 * The return value of close() is not propagated as there
888 * isn't much the user can do about it.
890 if (close(handle
->fd
)) {
891 PERROR("Failed to close the file descritptor (%d) of fs handle to %s, close() returned",
892 handle
->fd
, path
? path
: "Unknown");
897 lttng_inode_put(handle
->inode
);
899 pthread_mutex_unlock(&handle
->lock
);
900 pthread_mutex_destroy(&handle
->lock
);
901 pthread_mutex_unlock(&handle
->tracker
->lock
);