Commit 7a5919cc authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Andrei Vagin

files: Implement find_unused_file_desc_id()

This function will be used to allocate id for fake files
(don't confuse with fake fds, e.g. fles).
Suggested-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 22371247
...@@ -57,6 +57,8 @@ static struct hlist_head file_desc_hash[FDESC_HASH_SIZE]; ...@@ -57,6 +57,8 @@ static struct hlist_head file_desc_hash[FDESC_HASH_SIZE];
/* file_desc's, which fle is not owned by a process, that is able to open them */ /* file_desc's, which fle is not owned by a process, that is able to open them */
static LIST_HEAD(fake_master_head); static LIST_HEAD(fake_master_head);
static u32 max_file_desc_id = 0;
static void init_fdesc_hash(void) static void init_fdesc_hash(void)
{ {
int i; int i;
...@@ -79,6 +81,10 @@ int file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops) ...@@ -79,6 +81,10 @@ int file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops)
{ {
file_desc_init(d, id, ops); file_desc_init(d, id, ops);
hlist_add_head(&d->hash, &file_desc_hash[id % FDESC_HASH_SIZE]); hlist_add_head(&d->hash, &file_desc_hash[id % FDESC_HASH_SIZE]);
if (id > max_file_desc_id)
max_file_desc_id = id;
return 0; /* this is to make tail-calls in collect_one_foo look nice */ return 0; /* this is to make tail-calls in collect_one_foo look nice */
} }
...@@ -108,6 +114,11 @@ static inline struct file_desc *find_file_desc(FdinfoEntry *fe) ...@@ -108,6 +114,11 @@ static inline struct file_desc *find_file_desc(FdinfoEntry *fe)
return find_file_desc_raw(fe->type, fe->id); return find_file_desc_raw(fe->type, fe->id);
} }
u32 find_unused_file_desc_id(void)
{
return max_file_desc_id + 1;
}
struct fdinfo_list_entry *find_used_fd(struct pstree_item *task, int fd) struct fdinfo_list_entry *find_used_fd(struct pstree_item *task, int fd)
{ {
struct list_head *head; struct list_head *head;
......
...@@ -117,6 +117,7 @@ struct fdinfo_list_entry *collect_fd_to(int pid, FdinfoEntry *e, ...@@ -117,6 +117,7 @@ struct fdinfo_list_entry *collect_fd_to(int pid, FdinfoEntry *e,
struct rst_info *rst_info, struct file_desc *fdesc, struct rst_info *rst_info, struct file_desc *fdesc,
bool fake, bool force_master); bool fake, bool force_master);
u32 find_unused_file_desc_id(void);
unsigned int find_unused_fd(struct pstree_item *, int hint_fd); unsigned int find_unused_fd(struct pstree_item *, int hint_fd);
struct fdinfo_list_entry *find_used_fd(struct pstree_item *, int fd); struct fdinfo_list_entry *find_used_fd(struct pstree_item *, int fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment