[CRIU] [PATCH 13/19] files: Implement find_unused_file_desc_id()
Kirill Tkhai
ktkhai at virtuozzo.com
Tue Jan 30 18:42:48 MSK 2018
This function will be used to allocate id for fake files
(don't confuse with fake fds, e.g. fles).
Suggested-by: Pavel Emelyanov <xemul at virtuozzo.com>
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/files.c | 11 +++++++++++
criu/include/files.h | 1 +
2 files changed, 12 insertions(+)
diff --git a/criu/files.c b/criu/files.c
index b34a2b302..8d46e58e3 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -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 */
static LIST_HEAD(fake_master_head);
+static u32 max_file_desc_id = 0;
+
static void init_fdesc_hash(void)
{
int i;
@@ -91,6 +93,10 @@ int file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops)
if (d->setns_userns)
list_add(&d->fake_master_list, &fake_master_head);
}
+
+ 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 */
}
@@ -120,6 +126,11 @@ static inline struct file_desc *find_file_desc(FdinfoEntry *fe)
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 list_head *head;
diff --git a/criu/include/files.h b/criu/include/files.h
index 06e031313..f016525ea 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -124,6 +124,7 @@ struct fdinfo_list_entry *collect_fd_to(int pid, FdinfoEntry *e,
struct rst_info *rst_info, struct file_desc *fdesc,
bool fake, bool force_master);
+u32 find_unused_file_desc_id(void);
unsigned int find_unused_fd(struct pstree_item *, int hint_fd);
struct fdinfo_list_entry *find_used_fd(struct pstree_item *, int fd);
More information about the CRIU
mailing list