'Why can the posix thread id be NULL in Linux kernel function filp_close?
Below is excerpted from linux kernel:
/*
* "id" is the POSIX thread ID. We use the
* files pointer for this..
*/
int filp_close(struct file *filp, fl_owner_t id)
The documentation says id
is the posix thread id, and it should be current->files
.
However, I found many usages in Linux kernel, e.g. acct_on, use it as filp_close(filp, NULL)
My questions are:
Why is NULL acceptable when calling filp_close
?
What is the intent of the argument id
?
Solution 1:[1]
According to this discussion, formal description of fl_owner_t
would be
A generic "file lock owner" value. This is set differently for different
types of locks.
The POSIX file lock owner is determined by the "struct files_struct" in the
thread group.
Flock (BSD) locks, OFD locks and leases set the fl_owner to the
file description pointer.
but actually this is opaque pointer
legacy typedef, should eventually go away
which refers to process file descriptor table (struct files_struct
).
As for filp_close
function, only fs/file.c
source uses non-NULL id
parameter. All other users create filp
by hands (using filp_open
or file_open_name
) and pass id
as NULL.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |