Skip to content

Commit e80fa95

Browse files
committed
net: remember the name of the lock chain (nftables)
Using libnftables the chain to lock the network is composed of ("CRIU-%d", real_pid). This leads to around 40 zdtm tests failing with errors like this: Error: No such file or directory; did you mean table 'CRIU-62' in family inet? delete table inet CRIU-86 The reason is that as soon as a process is running in a namespace the real PID can be anything and only the PID in the namespace is restored correctly. Relying on the real PID does not work for the chain name. Using the PID of the innermost namespace would lead to the chain be called 'CRIU-1' most of the time which is also not really unique. With this commit the change is now named using the already existing CRIU run ID. To be able to correctly restore the process and delete the locking table, the CRIU run id during checkpointing is now stored in the inventory as dump_criu_run_id. Signed-off-by: Adrian Reber <areber@redhat.com>
1 parent 7aaf8d9 commit e80fa95

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

criu/image.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ bool img_common_magic = true;
2525
TaskKobjIdsEntry *root_ids;
2626
u32 root_cg_set;
2727
Lsmtype image_lsm;
28+
char dump_criu_run_id[RUN_ID_HASH_LENGTH];
2829

2930
struct inventory_plugin {
3031
struct list_head node;
@@ -120,6 +121,24 @@ int check_img_inventory(bool restore)
120121
goto out_err;
121122
}
122123
}
124+
125+
/**
126+
* This contains the criu_run_id during dumping of the process.
127+
* For things like removing network locking (nftables) this
128+
* information is needed to identify the name of the network
129+
* locking table.
130+
*/
131+
if (he->dump_criu_run_id) {
132+
strncpy(dump_criu_run_id, he->dump_criu_run_id, sizeof(dump_criu_run_id) - 1);
133+
pr_info("Dump CRIU run id = %s\n", dump_criu_run_id);
134+
} else {
135+
/**
136+
* If restoring from an old image this is a marker
137+
* that no dump_criu_run_id exists.
138+
*/
139+
dump_criu_run_id[0] = NO_DUMP_CRIU_RUN_ID;
140+
}
141+
123142
}
124143

125144
ret = 0;
@@ -367,6 +386,17 @@ int prepare_inventory(InventoryEntry *he)
367386
he->has_network_lock_method = true;
368387
he->network_lock_method = opts.network_lock_method;
369388

389+
/**
390+
* This contains the criu_run_id during dumping of the process.
391+
* For things like removing network locking (nftables) this
392+
* information is needed to identify the name of the network
393+
* locking table.
394+
*/
395+
he->dump_criu_run_id = xstrdup(criu_run_id);
396+
397+
if (!he->dump_criu_run_id)
398+
return -1;
399+
370400
return 0;
371401
}
372402

criu/include/util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ extern int run_command(char *buf, size_t buf_size, int (*child_fn)(void *), void
424424
*/
425425
extern char criu_run_id[RUN_ID_HASH_LENGTH];
426426
extern void util_init(void);
427+
#define NO_DUMP_CRIU_RUN_ID 0x7f
428+
extern char dump_criu_run_id[RUN_ID_HASH_LENGTH];
427429

428430
extern char *resolve_mountpoint(char *path);
429431

criu/netfilter.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,25 @@ int nftables_lock_connection(struct inet_sk_desc *sk)
299299

300300
int nftables_get_table(char *table, int n)
301301
{
302-
if (snprintf(table, n, "inet CRIU-%d", root_item->pid->real) < 0) {
302+
int ret;
303+
304+
switch(dump_criu_run_id[0]) {
305+
case 0:
306+
/* This is not a restore.*/
307+
ret = snprintf(table, n, "inet CRIU-%s", criu_run_id);
308+
break;
309+
case NO_DUMP_CRIU_RUN_ID:
310+
/**
311+
* This is a restore from an older image with no
312+
* dump_criu_run_id available. Let's use the old ID.
313+
*/
314+
ret = snprintf(table, n, "inet CRIU-%d", root_item->pid->real);
315+
break;
316+
default:
317+
ret = snprintf(table, n, "inet CRIU-%s", dump_criu_run_id);
318+
}
319+
320+
if (ret < 0) {
303321
pr_err("Cannot generate CRIU's nftables table name\n");
304322
return -1;
305323
}

images/inventory.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ message inventory_entry {
2929
optional bool tcp_close = 10;
3030
optional uint32 network_lock_method = 11;
3131
optional plugins_entry plugins_entry = 12;
32+
// Remember the criu_run_id when CRIU dumped the process.
33+
// This is currently used to delete the correct nftables
34+
// network locking rule.
35+
optional string dump_criu_run_id = 13;
3236
}

0 commit comments

Comments
 (0)