[25/28] files: Add fake fle flag and close such fles after restore files

Submitted by Kirill Tkhai on June 5, 2017, 5:27 p.m.

Details

Message ID 149668362711.25229.4711600631839863051.stgit@localhost.localdomain
State New
Series "Support sockets leaked to child user_ns task"
Headers show

Commit Message

Kirill Tkhai June 5, 2017, 5:27 p.m.
Allow to mark some fles as "fake" and close them, when they are not needed.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/files.c         |   14 ++++++++++++++
 criu/include/files.h |    1 +
 2 files changed, 15 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/files.c b/criu/files.c
index a2b57ca01..f97b7a0a2 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -710,6 +710,7 @@  static struct fdinfo_list_entry *alloc_fle(int pid, FdinfoEntry *fe)
 	fle->pid = pid;
 	fle->fe = fe;
 	fle->received = 0;
+	fle->fake = 0;
 	fle->stage = FLE_INITIALIZED;
 	fle->task = pstree_item_by_virt(pid);
 	if (!fle->task) {
@@ -1199,6 +1200,17 @@  static int open_fdinfos(struct pstree_item *me)
 	return ret;
 }
 
+static void close_fake_fdinfos(struct pstree_item *me)
+{
+	struct list_head *list = &rsti(me)->fds;
+	struct fdinfo_list_entry *fle;
+
+	list_for_each_entry(fle, list, ps_list) {
+		if (fle->fake)
+			close(fle->fe->fd);
+	}
+}
+
 static struct inherit_fd *inherit_fd_lookup_fd(int fd, const char *caller);
 
 int close_old_fds(void)
@@ -1268,6 +1280,8 @@  int prepare_fds(struct pstree_item *me)
 	BUG_ON(current->pid->state == TASK_HELPER);
 	ret = open_fdinfos(me);
 
+	close_fake_fdinfos(me);
+
 	if (rsti(me)->fdt)
 		futex_inc_and_wake(&rsti(me)->fdt->fdt_lock);
 out:
diff --git a/criu/include/files.h b/criu/include/files.h
index fd2d20761..fb47eb879 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -80,6 +80,7 @@  struct fdinfo_list_entry {
 	FdinfoEntry		*fe;
 	u8			received:1;
 	u8			stage:3;
+	u8			fake:1;
 };
 
 /* reports whether fd_a takes prio over fd_b */

Comments

Andrei Vagin June 6, 2017, 7:02 p.m.
On Mon, Jun 05, 2017 at 08:27:07PM +0300, Kirill Tkhai wrote:
> Allow to mark some fles as "fake" and close them, when they are not needed.
> 
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---
>  criu/files.c         |   14 ++++++++++++++
>  criu/include/files.h |    1 +
>  2 files changed, 15 insertions(+)
> 
> diff --git a/criu/files.c b/criu/files.c
> index a2b57ca01..f97b7a0a2 100644
> --- a/criu/files.c
> +++ b/criu/files.c
> @@ -710,6 +710,7 @@ static struct fdinfo_list_entry *alloc_fle(int pid, FdinfoEntry *fe)
>  	fle->pid = pid;
>  	fle->fe = fe;
>  	fle->received = 0;
> +	fle->fake = 0;
>  	fle->stage = FLE_INITIALIZED;
>  	fle->task = pstree_item_by_virt(pid);
>  	if (!fle->task) {
> @@ -1199,6 +1200,17 @@ static int open_fdinfos(struct pstree_item *me)
>  	return ret;
>  }
>  
> +static void close_fake_fdinfos(struct pstree_item *me)
> +{
> +	struct list_head *list = &rsti(me)->fds;
> +	struct fdinfo_list_entry *fle;
> +
> +	list_for_each_entry(fle, list, ps_list) {
> +		if (fle->fake)
> +			close(fle->fe->fd);
> +	}

Why we can't to close it immediately after sending it to all recipients?

> +}
> +
>  static struct inherit_fd *inherit_fd_lookup_fd(int fd, const char *caller);
>  
>  int close_old_fds(void)
> @@ -1268,6 +1280,8 @@ int prepare_fds(struct pstree_item *me)
>  	BUG_ON(current->pid->state == TASK_HELPER);
>  	ret = open_fdinfos(me);
>  
> +	close_fake_fdinfos(me);
> +
>  	if (rsti(me)->fdt)
>  		futex_inc_and_wake(&rsti(me)->fdt->fdt_lock);
>  out:
> diff --git a/criu/include/files.h b/criu/include/files.h
> index fd2d20761..fb47eb879 100644
> --- a/criu/include/files.h
> +++ b/criu/include/files.h
> @@ -80,6 +80,7 @@ struct fdinfo_list_entry {
>  	FdinfoEntry		*fe;
>  	u8			received:1;
>  	u8			stage:3;
> +	u8			fake:1;
>  };
>  
>  /* reports whether fd_a takes prio over fd_b */
>
Kirill Tkhai June 6, 2017, 10:08 p.m.
On 06.06.2017 22:02, Andrei Vagin wrote:
> On Mon, Jun 05, 2017 at 08:27:07PM +0300, Kirill Tkhai wrote:
>> Allow to mark some fles as "fake" and close them, when they are not needed.
>>
>> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
>> ---
>>  criu/files.c         |   14 ++++++++++++++
>>  criu/include/files.h |    1 +
>>  2 files changed, 15 insertions(+)
>>
>> diff --git a/criu/files.c b/criu/files.c
>> index a2b57ca01..f97b7a0a2 100644
>> --- a/criu/files.c
>> +++ b/criu/files.c
>> @@ -710,6 +710,7 @@ static struct fdinfo_list_entry *alloc_fle(int pid, FdinfoEntry *fe)
>>  	fle->pid = pid;
>>  	fle->fe = fe;
>>  	fle->received = 0;
>> +	fle->fake = 0;
>>  	fle->stage = FLE_INITIALIZED;
>>  	fle->task = pstree_item_by_virt(pid);
>>  	if (!fle->task) {
>> @@ -1199,6 +1200,17 @@ static int open_fdinfos(struct pstree_item *me)
>>  	return ret;
>>  }
>>  
>> +static void close_fake_fdinfos(struct pstree_item *me)
>> +{
>> +	struct list_head *list = &rsti(me)->fds;
>> +	struct fdinfo_list_entry *fle;
>> +
>> +	list_for_each_entry(fle, list, ps_list) {
>> +		if (fle->fake)
>> +			close(fle->fe->fd);
>> +	}
> Why we can't to close it immediately after sending it to all recipients?

Please, see the answer to [27/28] . Thanks.
>
>> +}
>> +
>>  static struct inherit_fd *inherit_fd_lookup_fd(int fd, const char *caller);
>>  
>>  int close_old_fds(void)
>> @@ -1268,6 +1280,8 @@ int prepare_fds(struct pstree_item *me)
>>  	BUG_ON(current->pid->state == TASK_HELPER);
>>  	ret = open_fdinfos(me);
>>  
>> +	close_fake_fdinfos(me);
>> +
>>  	if (rsti(me)->fdt)
>>  		futex_inc_and_wake(&rsti(me)->fdt->fdt_lock);
>>  out:
>> diff --git a/criu/include/files.h b/criu/include/files.h
>> index fd2d20761..fb47eb879 100644
>> --- a/criu/include/files.h
>> +++ b/criu/include/files.h
>> @@ -80,6 +80,7 @@ struct fdinfo_list_entry {
>>  	FdinfoEntry		*fe;
>>  	u8			received:1;
>>  	u8			stage:3;
>> +	u8			fake:1;
>>  };
>>  
>>  /* reports whether fd_a takes prio over fd_b */
>>