Skip to content

Commit 11276ef

Browse files
committed
external: normalize file id lookup and warn on fallback reopen
Signed-off-by: Farzan Aman Khan <farzanaman99@gmail.com>
1 parent c180188 commit 11276ef

File tree

4 files changed

+74
-3
lines changed

4 files changed

+74
-3
lines changed

Documentation/criu.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ In other words, do not use it unless really needed.
243243
from the current mount namespace, which can not be dumped without using
244244
this option. The file is identified by 'mnt_id' (a field obtained from
245245
**/proc/**__pid__**/fdinfo/**__N__) and 'inode' (as returned by
246-
*stat*(2)).
246+
*stat*(2)). Both values can be provided either in decimal or in
247+
hexadecimal (with or without a 0x prefix).
247248

248249
*--external* **tty[**__rdev__**:**__dev__**]**::
249250
Dump an external TTY, identified by *st_rdev* and *st_dev* fields

criu/crtools.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ int main(int argc, char *argv[], char *envp[])
432432
" --external RES dump objects from this list as external resources:\n"
433433
" Formats of RES on dump:\n"
434434
" tty[rdev:dev]\n"
435-
" file[mnt_id:inode]\n"
435+
" file[mnt_id:inode] (mnt_id/inode: decimal or hex)\n"
436436
" dev[major/minor]:NAME\n"
437437
" unix[ino]\n"
438438
" mnt[MOUNTPOINT]:COOKIE\n"
@@ -505,7 +505,7 @@ int main(int argc, char *argv[], char *envp[])
505505
" tty[rdev:dev]\n"
506506
" pipe:[inode]\n"
507507
" socket:[inode]\n"
508-
" file[mnt_id:inode]\n"
508+
" file[mnt_id:inode] (mnt_id/inode: decimal or hex)\n"
509509
" /memfd:name\n"
510510
" path/to/file\n"
511511
" --empty-ns net Create a namespace, but don't restore its properties\n"

criu/external.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#include <errno.h>
2+
#include <limits.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
16
#include "common/err.h"
27
#include "common/list.h"
38
#include "cr_options.h"
@@ -8,6 +13,60 @@
813

914
#include "net.h"
1015

16+
static bool parse_external_id_component(const char *id, char **end, unsigned long long *val)
17+
{
18+
char *tmp;
19+
20+
errno = 0;
21+
*val = strtoull(id, &tmp, 0);
22+
if (!errno && tmp != id) {
23+
*end = tmp;
24+
return true;
25+
}
26+
27+
/*
28+
* External regular file ids are emitted as hex without 0x prefix.
29+
* Accept such values for normalized matching as well.
30+
*/
31+
errno = 0;
32+
*val = strtoull(id, &tmp, 16);
33+
if (errno || tmp == id)
34+
return false;
35+
36+
*end = tmp;
37+
return true;
38+
}
39+
40+
static bool parse_external_file_id(const char *id, unsigned int *mnt_id, uint64_t *inode)
41+
{
42+
char *end = NULL;
43+
unsigned long long val;
44+
45+
if (!strstartswith(id, "file["))
46+
return false;
47+
id += strlen("file[");
48+
49+
if (!parse_external_id_component(id, &end, &val))
50+
return false;
51+
if (val > UINT_MAX)
52+
return false;
53+
if (*end != ':')
54+
return false;
55+
*mnt_id = (unsigned int)val;
56+
57+
id = end + 1;
58+
if (!parse_external_id_component(id, &end, &val))
59+
return false;
60+
if (*end != ']')
61+
return false;
62+
end++;
63+
if (*end != '\0')
64+
return false;
65+
66+
*inode = val;
67+
return true;
68+
}
69+
1170
int add_external(char *key)
1271
{
1372
struct external *ext;
@@ -39,10 +98,18 @@ int add_external(char *key)
3998
bool external_lookup_id(char *id)
4099
{
41100
struct external *ext;
101+
unsigned int id_mnt_id, ext_mnt_id;
102+
uint64_t id_inode, ext_inode;
103+
bool normalized_id;
104+
105+
normalized_id = parse_external_file_id(id, &id_mnt_id, &id_inode);
42106

43107
list_for_each_entry(ext, &opts.external, node)
44108
if (!strcmp(ext->id, id))
45109
return true;
110+
else if (normalized_id && parse_external_file_id(ext->id, &ext_mnt_id, &ext_inode) &&
111+
ext_mnt_id == id_mnt_id && ext_inode == id_inode)
112+
return true;
46113
return false;
47114
}
48115

criu/files-reg.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,6 +2216,9 @@ int open_path(struct file_desc *d, int (*open_cb)(int mntns_root, struct reg_fil
22162216
rfi->path = path;
22172217
goto ext;
22182218
}
2219+
2220+
pr_warn("No --inherit-fd mapping found for external file id %s, falling back to path-based reopen\n",
2221+
rfi->rfe->name);
22192222
}
22202223

22212224
if (rfi->remap) {

0 commit comments

Comments
 (0)