criu: Don't fail if ghost file has no parent dirs.

Submitted by Vitaly Ostrosablin on Dec. 6, 2017, 12:15 p.m.

Details

Message ID 20171206121520.13710-1-vostrosablin@virtuozzo.com
State New
Series "criu: Don't fail if ghost file has no parent dirs."
Headers show

Commit Message

Vitaly Ostrosablin Dec. 6, 2017, 12:15 p.m.
Due to way CRIU handles paths (as relative to workdir), there's a case,
where migration would fail. Simple example is a ghost file in filesystem
root (with root being cwd). For example, "/unlinked" becomes "unlinked".
And original code piece scans path for other slashes, which would be
missing in this case. But it's still a perfectly valid case, and there's
no need to fail. So if there's no parent dir - we just don't need to
create one and we can just return 0 here instead of failing.

Signed-off-by: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>
---
 criu/files-reg.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/files-reg.c b/criu/files-reg.c
index 9948d834f..27e4cf48d 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -1768,10 +1768,8 @@  static int make_parent_dirs_if_need(int mntns_root, char *path)
 	struct stat st;
 
 	p = last_delim = strrchr(path, '/');
-	if (!p) {
-		pr_err("Path %s has no parent dir\n", path);
-		return -1;
-	}
+	if (!p)
+		return 0;
 	*p = '\0';
 
 	if (fstatat(mntns_root, path, &st, AT_EMPTY_PATH) == 0)

Comments

Kirill Tkhai Dec. 6, 2017, 5:43 p.m.
On 06.12.2017 15:15, Vitaly Ostrosablin wrote:
> Due to way CRIU handles paths (as relative to workdir), there's a case,
> where migration would fail. Simple example is a ghost file in filesystem
> root (with root being cwd). For example, "/unlinked" becomes "unlinked".
> And original code piece scans path for other slashes, which would be
> missing in this case. But it's still a perfectly valid case, and there's
> no need to fail. So if there's no parent dir - we just don't need to
> create one and we can just return 0 here instead of failing.
> 
> Signed-off-by: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>

Acked-by: Kirill Tkhai <ktkhai@virtuozzo.com>

> ---
>  criu/files-reg.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/criu/files-reg.c b/criu/files-reg.c
> index 9948d834f..27e4cf48d 100644
> --- a/criu/files-reg.c
> +++ b/criu/files-reg.c
> @@ -1768,10 +1768,8 @@ static int make_parent_dirs_if_need(int mntns_root, char *path)
>  	struct stat st;
>  
>  	p = last_delim = strrchr(path, '/');
> -	if (!p) {
> -		pr_err("Path %s has no parent dir\n", path);
> -		return -1;
> -	}
> +	if (!p)
> +		return 0;
>  	*p = '\0';
>  
>  	if (fstatat(mntns_root, path, &st, AT_EMPTY_PATH) == 0)
>
Andrey Vagin Dec. 7, 2017, 5:38 a.m.
Could you add a test for this issue?

On Wed, Dec 06, 2017 at 03:15:20PM +0300, Vitaly Ostrosablin wrote:
> Due to way CRIU handles paths (as relative to workdir), there's a case,
> where migration would fail. Simple example is a ghost file in filesystem
> root (with root being cwd). For example, "/unlinked" becomes "unlinked".
> And original code piece scans path for other slashes, which would be
> missing in this case. But it's still a perfectly valid case, and there's
> no need to fail. So if there's no parent dir - we just don't need to
> create one and we can just return 0 here instead of failing.
> 
> Signed-off-by: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>
> ---
>  criu/files-reg.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/criu/files-reg.c b/criu/files-reg.c
> index 9948d834f..27e4cf48d 100644
> --- a/criu/files-reg.c
> +++ b/criu/files-reg.c
> @@ -1768,10 +1768,8 @@ static int make_parent_dirs_if_need(int mntns_root, char *path)
>  	struct stat st;
>  
>  	p = last_delim = strrchr(path, '/');
> -	if (!p) {
> -		pr_err("Path %s has no parent dir\n", path);
> -		return -1;
> -	}
> +	if (!p)
> +		return 0;
>  	*p = '\0';
>  
>  	if (fstatat(mntns_root, path, &st, AT_EMPTY_PATH) == 0)
> -- 
> 2.15.0
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu