2.4 Q: list of open files per inode?
Ah, yes, this was my intention, to keep the state in filp->private_data. But then at a timer routine I wanted to go over all the filps associated with the device and check/modify the state. That's why I needed the open files list. -Jacob
----- Original Message ----
From: Jan Engelhardt <[email protected]>
To: Jacob A <[email protected]>
Cc: Al Viro <[email protected]>; [email protected]
Sent: Sunday, July 22, 2007 3:28:30 PM
Subject: Re: 2.4 Q: list of open files per inode?
Quoted 2 lines · Jacob A
I want to keep an internal state per each registration instance, and I opted to use
open()as the registration mechanism.
So why not just store it in filp->private_data?
Jan
Quoted 1 line
Jan
Quoted 4 lines · Jacob A
Ah, yes, this was my intention, to keep the state in
filp->private_data. But then at a timer routine I wanted to go over all the filps associated with the device and check/modify the state. That's why I needed the open files list.
No. For each private_data that you allocate, create a linked list that also has them. In other words:
struct mystuff {
struct list_head list;
int other_fluff;
};int mydriver_open()
{
struct mystuff *pd = kmalloc(...);
filp->private_data = pd;
list_add(&pd->list);
}int mydriver_close()
{
struct mystuff *pd = filp->private_data;
list_del(&pd->list);
free(pd);
}Simple as that. *Of course* this requires that the file descriptor remains open. But that should not be a problem, would it?
Jan
Quoted 1 line
Jan
Quoted 1 line
Jan
Quoted 8 lines · Jacob Avraham
Quoted 8 lines
{ struct mystuff *pd = filp->private_data; list_del(&pd->list); free(pd); }Simple as that. *Of course* this requires that the file descriptor remains open. But that should not be a problem, would it?
First of all, that's obviously racy (list manipulations without any exclusion *or* preventing aforementioned timer running while you do it).
More important part is that stuff put into your private_data would better remain valid through the lifetime of opened file. In particular, you _can't_ expect that process that had opened the file in question is still alive.
Quoted 2 lines
I ended up implementing my own list (similar to the above), so now the question is more theoretical. BTW, does 2.6 has an easy way to get from an inode to all the open fds?
Same situation.