[v2,02/15] files: Implement find_used_fd()

Submitted by Kirill Tkhai on May 27, 2016, 1:05 p.m.

Details

Message ID 146435435165.31234.9483217102793356281.stgit@pro
State Rejected
Series "Support for packet's msg_name in receive queue of promiscous DGRAM sockets"
Headers show

Commit Message

Kirill Tkhai May 27, 2016, 1:05 p.m.
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/files.c         |   13 +++++++++++++
 criu/include/files.h |    1 +
 2 files changed, 14 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/files.c b/criu/files.c
index a52e12f..0e9e41d 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -128,6 +128,19 @@  unsigned int find_unused_fd(struct list_head *head, int hint_fd)
 	return fd;
 }
 
+struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd)
+{
+	struct fdinfo_list_entry *fle;
+
+	list_for_each_entry_reverse(fle, head, used_list) {
+		if (fle->fe->fd == fd)
+			return fle;
+	}
+	pr_err("Trying to unhash unexisting fd %d\n", fd);
+	BUG();
+	return NULL;
+}
+
 /*
  * A file may be shared between several file descriptors. E.g
  * when doing a fork() every fd of a forker and respective fds
diff --git a/criu/include/files.h b/criu/include/files.h
index d46b3cd..025c7d0 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -138,6 +138,7 @@  static inline bool fd_is_used(struct list_head *head, int fd)
 }
 
 unsigned int find_unused_fd(struct list_head *head, int hint_fd);
+struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd);
 
 struct file_desc {
 	u32			id;		/* File id, unique */

Comments

Pavel Emelianov May 30, 2016, 11:33 a.m.
On 05/27/2016 04:05 PM, Kirill Tkhai wrote:
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---
>  criu/files.c         |   13 +++++++++++++
>  criu/include/files.h |    1 +
>  2 files changed, 14 insertions(+)
> 
> diff --git a/criu/files.c b/criu/files.c
> index a52e12f..0e9e41d 100644
> --- a/criu/files.c
> +++ b/criu/files.c
> @@ -128,6 +128,19 @@ unsigned int find_unused_fd(struct list_head *head, int hint_fd)
>  	return fd;
>  }
>  
> +struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd)
> +{
> +	struct fdinfo_list_entry *fle;
> +
> +	list_for_each_entry_reverse(fle, head, used_list) {
> +		if (fle->fe->fd == fd)
> +			return fle;

This only differs from fd_is_used() with return argument. Can we squash two routines together?

> +	}
> +	pr_err("Trying to unhash unexisting fd %d\n", fd);
> +	BUG();
> +	return NULL;
 +}
> +
>  /*
>   * A file may be shared between several file descriptors. E.g
>   * when doing a fork() every fd of a forker and respective fds
> diff --git a/criu/include/files.h b/criu/include/files.h
> index d46b3cd..025c7d0 100644
> --- a/criu/include/files.h
> +++ b/criu/include/files.h
> @@ -138,6 +138,7 @@ static inline bool fd_is_used(struct list_head *head, int fd)
>  }
>  
>  unsigned int find_unused_fd(struct list_head *head, int hint_fd);
> +struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd);
>  
>  struct file_desc {
>  	u32			id;		/* File id, unique */
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
> .
>
Kirill Tkhai May 30, 2016, 12:15 p.m.
On 30.05.2016 14:33, Pavel Emelyanov wrote:
> On 05/27/2016 04:05 PM, Kirill Tkhai wrote:
>> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
>> ---
>>  criu/files.c         |   13 +++++++++++++
>>  criu/include/files.h |    1 +
>>  2 files changed, 14 insertions(+)
>>
>> diff --git a/criu/files.c b/criu/files.c
>> index a52e12f..0e9e41d 100644
>> --- a/criu/files.c
>> +++ b/criu/files.c
>> @@ -128,6 +128,19 @@ unsigned int find_unused_fd(struct list_head *head, int hint_fd)
>>  	return fd;
>>  }
>>  
>> +struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd)
>> +{
>> +	struct fdinfo_list_entry *fle;
>> +
>> +	list_for_each_entry_reverse(fle, head, used_list) {
>> +		if (fle->fe->fd == fd)
>> +			return fle;
> 
> This only differs from fd_is_used() with return argument. Can we squash two routines together?

Ok. I'll change fd_is_used() to return struct fdinfo_list_entry pointer or NULL.

>> +	}
>> +	pr_err("Trying to unhash unexisting fd %d\n", fd);
>> +	BUG();
>> +	return NULL;
>  +}
>> +
>>  /*
>>   * A file may be shared between several file descriptors. E.g
>>   * when doing a fork() every fd of a forker and respective fds
>> diff --git a/criu/include/files.h b/criu/include/files.h
>> index d46b3cd..025c7d0 100644
>> --- a/criu/include/files.h
>> +++ b/criu/include/files.h
>> @@ -138,6 +138,7 @@ static inline bool fd_is_used(struct list_head *head, int fd)
>>  }
>>  
>>  unsigned int find_unused_fd(struct list_head *head, int hint_fd);
>> +struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd);
>>  
>>  struct file_desc {
>>  	u32			id;		/* File id, unique */
>>
>> _______________________________________________
>> CRIU mailing list
>> CRIU@openvz.org
>> https://lists.openvz.org/mailman/listinfo/criu
>> .
>>
>