[09/18] file: Find descs by ID only (v2)

Submitted by Pavel Emelianov on July 10, 2017, 9:39 a.m.

Details

Message ID 9fe34230-0d45-dba8-1b25-6e343d31919d@virtuozzo.com
State Accepted
Series "Support descriptors sent over unix sockets"
Commit abc686f7af226556105da07f948495af53670e30
Headers show

Commit Message

Pavel Emelianov July 10, 2017, 9:39 a.m.
Actually all file-s we dump have unique IDs, regardless of
their types. This fact will be used to reduce complexity
of the SCM code -- instead of keeping TYPE:ID pair it'll
save only the ID.

Siad that -- we will need the way to lookup desc by ID only.

v2: Older images had fifo-s and tty-s having matching IDs
    with respective reg-file entries

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/files.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/files.c b/criu/files.c
index affdac0..a0e40f1 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -101,7 +101,15 @@  struct file_desc *find_file_desc_raw(int type, u32 id)
 
 	chain = &file_desc_hash[id % FDESC_HASH_SIZE];
 	hlist_for_each_entry(d, chain, hash)
-		if (d->ops->type == type && d->id == id)
+		if ((d->id == id) &&
+				(d->ops->type == type || type == FD_TYPES__UND))
+			/*
+			 * Warning -- old CRIU might generate matching IDs
+			 * for different file types! So any code that uses
+			 * FD_TYPES__UND for fdesc search MUST make sure it's
+			 * dealing with the merged files images where all
+			 * descs are forced to have different IDs.
+			 */
 			return d;
 
 	return NULL;