Commit 5d4cf626 authored by Egor Gorbunov's avatar Egor Gorbunov Committed by Pavel Emelyanov

files-reg: find appropriate dir to create link remap

Currently during criu dump we create link remap in the same dir
where original file was opened. But that dir may not exist during
link remap creation. At the same time it's okay to create link
remap in any dir on the same mount point.
In this patch we do this. We check existance of every dir bottom
up through the original file path. We use the first existing dir.

Similar approach is used on criu restore during ghost file creation.
Signed-off-by: 's avatarEgor Gorbunov <egor-mailbox@ya.ru>
Signed-off-by: 's avatarEugene Batalov <eabatalov89@gmail.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent fad23922
......@@ -718,6 +718,7 @@ static int create_link_remap(char *path, int len, int lfd,
RegFileEntry rfe = REG_FILE_ENTRY__INIT;
FownEntry fwn = FOWN_ENTRY__INIT;
int mntns_root;
int ret;
if (!opts.link_remap_ok) {
pr_err("Can't create link remap for %s. "
......@@ -754,7 +755,16 @@ static int create_link_remap(char *path, int len, int lfd,
mntns_root = mntns_get_root_fd(nsid);
if (linkat(lfd, "", mntns_root, link_name, AT_EMPTY_PATH) < 0) {
again:
ret = linkat(lfd, "", mntns_root, link_name, AT_EMPTY_PATH);
if (ret < 0 && errno == ENOENT) {
/* Use grand parent, if parent directory does not exist. */
if (trim_last_parent(link_name) < 0) {
pr_err("trim failed: @%s@\n", link_name);
return -1;
}
goto again;
} else if (ret < 0) {
pr_perror("Can't link remap to %s", path);
return -1;
}
......
{'flavor': 'ns', 'flags': 'suid crfail', 'opts': '--link-remap'}
{'flavor': 'ns', 'flags': 'suid', 'opts': '--link-remap'}
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