mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
remap: Sanitize ghost file path printing
First -- avoid two memory copies by printing ns root directly, and second -- remove extra argument from create_ghost, the mnt_id value we need there can be found on the ghost_file object. Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
6cf77f6726
commit
152222a6b7
3 changed files with 24 additions and 23 deletions
26
files-reg.c
26
files-reg.c
|
|
@ -66,12 +66,20 @@ struct link_remap_rlb {
|
|||
};
|
||||
static LIST_HEAD(link_remaps);
|
||||
|
||||
static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, char *root, struct cr_img *img)
|
||||
static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, struct cr_img *img)
|
||||
{
|
||||
int gfd, ghost_flags, ret = -1;
|
||||
int gfd, ghost_flags, ret;
|
||||
char path[PATH_MAX];
|
||||
|
||||
snprintf(path, sizeof(path), "%s/%s", root, gf->remap.rpath);
|
||||
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;
|
||||
}
|
||||
|
||||
snprintf(path + ret, sizeof(path) - ret, "%s", gf->remap.rpath);
|
||||
ret = -1;
|
||||
|
||||
if (S_ISFIFO(gfe->mode)) {
|
||||
if (mknod(path, gfe->mode, 0)) {
|
||||
pr_perror("Can't create node for ghost file");
|
||||
|
|
@ -127,7 +135,6 @@ static int open_remap_ghost(struct reg_file_info *rfi,
|
|||
struct ghost_file *gf;
|
||||
GhostFileEntry *gfe = NULL;
|
||||
struct cr_img *img;
|
||||
char *root;
|
||||
|
||||
list_for_each_entry(gf, &ghost_files, list)
|
||||
if (gf->id == rfe->remap_id)
|
||||
|
|
@ -141,17 +148,11 @@ static int open_remap_ghost(struct reg_file_info *rfi,
|
|||
|
||||
pr_info("Opening ghost file %#x for %s\n", rfe->remap_id, rfi->path);
|
||||
|
||||
root = rst_get_mnt_root(rfi->rfe->mnt_id);
|
||||
if (root == NULL) {
|
||||
pr_err("The %d mount is not found\n", rfi->rfe->mnt_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
gf = shmalloc(sizeof(*gf));
|
||||
if (!gf)
|
||||
return -1;
|
||||
|
||||
gf->remap.rpath = xmalloc(PATH_MAX);
|
||||
gf->remap.rmnt_id = rfi->rfe->mnt_id;
|
||||
if (!gf->remap.rpath)
|
||||
goto err;
|
||||
|
||||
|
|
@ -169,13 +170,14 @@ static int open_remap_ghost(struct reg_file_info *rfi,
|
|||
*/
|
||||
gf->dev = gfe->dev;
|
||||
gf->ino = gfe->ino;
|
||||
gf->remap.rmnt_id = rfi->rfe->mnt_id;
|
||||
|
||||
if (S_ISDIR(gfe->mode))
|
||||
strncpy(gf->remap.rpath, rfi->path, PATH_MAX);
|
||||
else
|
||||
snprintf(gf->remap.rpath, PATH_MAX, "%s.cr.%x.ghost", rfi->path, rfe->remap_id);
|
||||
|
||||
if (create_ghost(gf, gfe, root, img))
|
||||
if (create_ghost(gf, gfe, img))
|
||||
goto close_ifd;
|
||||
|
||||
ghost_file_entry__free_unpacked(gfe, NULL);
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ extern bool phys_stat_dev_match(dev_t st_dev, dev_t phys_dev,
|
|||
extern int restore_task_mnt_ns(struct pstree_item *current);
|
||||
extern int depopulate_roots_yard(void);
|
||||
|
||||
extern char *rst_get_mnt_root(int mnt_id);
|
||||
extern int rst_get_mnt_root(int mnt_id, char *path, int plen);
|
||||
extern int ext_mount_add(char *key, char *val);
|
||||
extern int mntns_maybe_create_roots(void);
|
||||
extern void cleanup_mnt_ns(void);
|
||||
|
|
|
|||
19
mount.c
19
mount.c
|
|
@ -2526,25 +2526,24 @@ static int read_mnt_ns_img(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
char *rst_get_mnt_root(int mnt_id)
|
||||
int rst_get_mnt_root(int mnt_id, char *path, int plen)
|
||||
{
|
||||
struct mount_info *m;
|
||||
static char path[PATH_MAX] = "/";
|
||||
|
||||
if (!(root_ns_mask & CLONE_NEWNS))
|
||||
return path;
|
||||
|
||||
if (mnt_id == -1)
|
||||
return path;
|
||||
if (!(root_ns_mask & CLONE_NEWNS) || mnt_id == -1)
|
||||
goto rroot;
|
||||
|
||||
m = lookup_mnt_id(mnt_id);
|
||||
if (m == NULL)
|
||||
return NULL;
|
||||
return -1;
|
||||
|
||||
if (m->nsid->type == NS_OTHER)
|
||||
print_ns_root(m->nsid, path, sizeof(path));
|
||||
return print_ns_root(m->nsid, path, plen);
|
||||
|
||||
return path;
|
||||
rroot:
|
||||
path[0] = '/';
|
||||
path[1] = '\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
int mntns_maybe_create_roots(void)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue