diff --git a/criu/files-reg.c b/criu/files-reg.c index 95f84a29f..b400559e1 100644 --- a/criu/files-reg.c +++ b/criu/files-reg.c @@ -355,32 +355,11 @@ err: return ret; } -static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, struct cr_img *img) +static int create_ghost_dentry(char *path, GhostFileEntry *gfe, struct cr_img *img) { - struct mount_info *mi; - char path[PATH_MAX]; - int ret, root_len; + int ret = -1; char *msg; - root_len = ret = rst_get_mnt_root(gf->remap.rmnt_id, path, sizeof(path)); - if (ret < 0) { - pr_err("The %d mount is not found for ghost\n", gf->remap.rmnt_id); - goto err; - } - - /* Add a '/' only if we have no at the end */ - if (path[root_len - 1] != '/') { - path[root_len++] = '/'; - path[root_len] = '\0'; - } - - snprintf(path + root_len, sizeof(path) - root_len, "%s", gf->remap.rpath); - ret = -1; - - mi = lookup_mnt_id(gf->remap.rmnt_id); - /* We get here while in service mntns */ - if (mi && try_remount_writable(mi, false)) - goto err; again: if (S_ISFIFO(gfe->mode)) { if ((ret = mknod(path, gfe->mode, 0)) < 0) @@ -417,18 +396,49 @@ again: goto err; } - strcpy(gf->remap.rpath, path + root_len); - pr_debug("Remap rpath is %s\n", gf->remap.rpath); - - ret = -1; - if (ghost_apply_metadata(path, gfe)) - goto err; - ret = 0; err: return ret; } +static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, struct cr_img *img) +{ + struct mount_info *mi; + char path[PATH_MAX]; + int ret, root_len; + + root_len = ret = rst_get_mnt_root(gf->remap.rmnt_id, path, sizeof(path)); + if (ret < 0) { + pr_err("The %d mount is not found for ghost\n", gf->remap.rmnt_id); + return -1; + } + + /* Add a '/' only if we have no at the end */ + if (path[root_len - 1] != '/') { + path[root_len++] = '/'; + path[root_len] = '\0'; + } + + snprintf(path + root_len, sizeof(path) - root_len, "%s", gf->remap.rpath); + ret = -1; + + mi = lookup_mnt_id(gf->remap.rmnt_id); + /* We get here while in service mntns */ + if (mi && try_remount_writable(mi, false)) + return -1; + + ret = create_ghost_dentry(path, gfe, img); + if (ret) + return -1; + + if (ghost_apply_metadata(path, gfe)) + return -1; + + strcpy(gf->remap.rpath, path + root_len); + pr_debug("Remap rpath is %s\n", gf->remap.rpath); + return 0; +} + static inline void ghost_path(char *path, int plen, struct reg_file_info *rfi, RemapFilePathEntry *rpe) { snprintf(path, plen, "%s.cr.%x.ghost", rfi->path, rpe->remap_id);