Commit 70be2395 authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Pavel Emelyanov

files: Add fake fle flag and close such fles after restore files

Allow to mark some fles as "fake" and close them, when they are not needed.

v2: Cache fake file in separate list, when they are restored,
to do not iterate over files list again.
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 82acfd44
...@@ -702,6 +702,7 @@ static struct fdinfo_list_entry *alloc_fle(int pid, FdinfoEntry *fe) ...@@ -702,6 +702,7 @@ static struct fdinfo_list_entry *alloc_fle(int pid, FdinfoEntry *fe)
fle->pid = pid; fle->pid = pid;
fle->fe = fe; fle->fe = fe;
fle->received = 0; fle->received = 0;
fle->fake = 0;
fle->stage = FLE_INITIALIZED; fle->stage = FLE_INITIALIZED;
return fle; return fle;
...@@ -1106,11 +1107,20 @@ static int receive_fd(struct fdinfo_list_entry *fle) ...@@ -1106,11 +1107,20 @@ static int receive_fd(struct fdinfo_list_entry *fle)
return 0; return 0;
} }
static void close_fdinfos(struct list_head *list)
{
struct fdinfo_list_entry *fle;
list_for_each_entry(fle, list, ps_list)
close(fle->fe->fd);
}
static int open_fdinfos(struct pstree_item *me) static int open_fdinfos(struct pstree_item *me)
{ {
struct list_head *list = &rsti(me)->fds; struct list_head *list = &rsti(me)->fds;
struct fdinfo_list_entry *fle, *tmp; struct fdinfo_list_entry *fle, *tmp;
LIST_HEAD(completed); LIST_HEAD(completed);
LIST_HEAD(fake);
bool progress, again; bool progress, again;
int st, ret = 0; int st, ret = 0;
...@@ -1136,7 +1146,10 @@ static int open_fdinfos(struct pstree_item *me) ...@@ -1136,7 +1146,10 @@ static int open_fdinfos(struct pstree_item *me)
* and reduce number of fles in their checks. * and reduce number of fles in their checks.
*/ */
list_del(&fle->ps_list); list_del(&fle->ps_list);
list_add(&fle->ps_list, &completed); if (!fle->fake)
list_add(&fle->ps_list, &completed);
else
list_add(&fle->ps_list, &fake);
} }
if (ret == 1) if (ret == 1)
again = true; again = true;
...@@ -1146,7 +1159,13 @@ static int open_fdinfos(struct pstree_item *me) ...@@ -1146,7 +1159,13 @@ static int open_fdinfos(struct pstree_item *me)
} while (again || progress); } while (again || progress);
BUG_ON(!list_empty(list)); BUG_ON(!list_empty(list));
/*
* Fake fles may be used for restore other
* file types, so their closing is delayed.
*/
close_fdinfos(&fake);
splice: splice:
list_splice(&fake, list);
list_splice(&completed, list); list_splice(&completed, list);
return ret; return ret;
......
...@@ -87,6 +87,7 @@ struct fdinfo_list_entry { ...@@ -87,6 +87,7 @@ struct fdinfo_list_entry {
FdinfoEntry *fe; FdinfoEntry *fe;
u8 received:1; u8 received:1;
u8 stage:3; u8 stage:3;
u8 fake:1;
}; };
/* reports whether fd_a takes prio over fd_b */ /* reports whether fd_a takes prio over fd_b */
......
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