mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-30 22:05:36 +00:00
files-ids: generate id-s accoding with mnt_id, st->st_dev and st->st_ino
One device can be mounted a few times, so files are identical only, if they have the same mnt_id. Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
6639464503
commit
22d384536d
@@ -278,7 +278,7 @@ static int dump_task_exe_link(pid_t pid, MmEntry *mm)
|
||||
if (fill_fd_params_special(fd, ¶ms))
|
||||
return -1;
|
||||
|
||||
if (fd_id_generate_special(¶ms.stat, &mm->exe_file_id))
|
||||
if (fd_id_generate_special(¶ms, &mm->exe_file_id))
|
||||
ret = dump_one_reg_file(fd, mm->exe_file_id, ¶ms);
|
||||
|
||||
close(fd);
|
||||
@@ -301,7 +301,7 @@ static int dump_task_fs(pid_t pid, struct parasite_dump_misc *misc, struct cr_fd
|
||||
if (fill_fd_params_special(fd, &p))
|
||||
return -1;
|
||||
|
||||
if (fd_id_generate_special(&p.stat, &fe.cwd_id)) {
|
||||
if (fd_id_generate_special(&p, &fe.cwd_id)) {
|
||||
ret = dump_one_reg_file(fd, fe.cwd_id, &p);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@@ -316,7 +316,7 @@ static int dump_task_fs(pid_t pid, struct parasite_dump_misc *misc, struct cr_fd
|
||||
if (fill_fd_params_special(fd, &p))
|
||||
return -1;
|
||||
|
||||
if (fd_id_generate_special(&p.stat, &fe.root_id)) {
|
||||
if (fd_id_generate_special(&p, &fe.root_id)) {
|
||||
ret = dump_one_reg_file(fd, fe.root_id, &p);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@@ -370,7 +370,7 @@ static int dump_filemap(pid_t pid, struct vma_area *vma_area,
|
||||
|
||||
/* Flags will be set during restore in get_filemap_fd() */
|
||||
|
||||
if (fd_id_generate_special(&p.stat, &id))
|
||||
if (fd_id_generate_special(&p, &id))
|
||||
ret = dump_one_reg_file(vma_area->vm_file_fd, id, &p);
|
||||
|
||||
vma->shmid = id;
|
||||
|
32
file-ids.c
32
file-ids.c
@@ -18,6 +18,7 @@
|
||||
#include "image.h"
|
||||
#include "util.h"
|
||||
#include "irmap.h"
|
||||
#include "files.h"
|
||||
|
||||
static DECLARE_KCMP_TREE(fd_tree, KCMP_FILE);
|
||||
|
||||
@@ -36,6 +37,7 @@ static inline int fdid_hashfn(unsigned int s_dev, unsigned long i_ino)
|
||||
}
|
||||
|
||||
struct fd_id {
|
||||
int mnt_id;
|
||||
unsigned int dev;
|
||||
unsigned long ino;
|
||||
u32 id;
|
||||
@@ -44,41 +46,45 @@ struct fd_id {
|
||||
|
||||
static struct fd_id *fd_id_cache[FDID_SIZE];
|
||||
|
||||
static void fd_id_cache_one(u32 id, struct stat *st)
|
||||
static void fd_id_cache_one(u32 id, struct fd_parms *p)
|
||||
{
|
||||
struct fd_id *fi;
|
||||
unsigned hv;
|
||||
|
||||
fi = xmalloc(sizeof(*fi));
|
||||
if (fi) {
|
||||
fi->dev = st->st_dev;
|
||||
fi->ino = st->st_ino;
|
||||
fi->dev = p->stat.st_dev;
|
||||
fi->ino = p->stat.st_ino;
|
||||
fi->mnt_id = p->mnt_id;
|
||||
fi->id = id;
|
||||
|
||||
hv = fdid_hashfn(st->st_dev, st->st_ino);
|
||||
hv = fdid_hashfn(p->stat.st_dev, p->stat.st_ino);
|
||||
fi->n = fd_id_cache[hv];
|
||||
fd_id_cache[hv] = fi;
|
||||
}
|
||||
}
|
||||
|
||||
static struct fd_id *fd_id_cache_lookup(struct stat *st)
|
||||
static struct fd_id *fd_id_cache_lookup(struct fd_parms *p)
|
||||
{
|
||||
struct stat *st = &p->stat;
|
||||
struct fd_id *fi;
|
||||
|
||||
for (fi = fd_id_cache[fdid_hashfn(st->st_dev, st->st_ino)];
|
||||
fi; fi = fi->n)
|
||||
if (fi->dev == st->st_dev && fi->ino == st->st_ino)
|
||||
if (fi->dev == st->st_dev &&
|
||||
fi->ino == st->st_ino &&
|
||||
fi->mnt_id == p->mnt_id)
|
||||
return fi;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fd_id_generate_special(struct stat *st, u32 *id)
|
||||
int fd_id_generate_special(struct fd_parms *p, u32 *id)
|
||||
{
|
||||
if (st) {
|
||||
if (p) {
|
||||
struct fd_id *fi;
|
||||
|
||||
fi = fd_id_cache_lookup(st);
|
||||
fi = fd_id_cache_lookup(p);
|
||||
if (fi) {
|
||||
*id = fi->id;
|
||||
return 0;
|
||||
@@ -86,12 +92,12 @@ int fd_id_generate_special(struct stat *st, u32 *id)
|
||||
}
|
||||
|
||||
*id = fd_tree.subid++;
|
||||
if (st)
|
||||
fd_id_cache_one(*id, st);
|
||||
if (p)
|
||||
fd_id_cache_one(*id, p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct stat *st)
|
||||
int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct fd_parms *p)
|
||||
{
|
||||
u32 id;
|
||||
struct kid_elem e;
|
||||
@@ -106,7 +112,7 @@ int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct stat *st)
|
||||
return -ENOMEM;
|
||||
|
||||
if (new_id)
|
||||
fd_id_cache_one(id, st);
|
||||
fd_id_cache_one(id, p);
|
||||
|
||||
fe->id = id;
|
||||
return new_id;
|
||||
|
2
files.c
2
files.c
@@ -171,7 +171,7 @@ int do_dump_gen_file(struct fd_parms *p, int lfd,
|
||||
e.fd = p->fd;
|
||||
e.flags = p->fd_flags;
|
||||
|
||||
ret = fd_id_generate(p->pid, &e, &p->stat);
|
||||
ret = fd_id_generate(p->pid, &e, p);
|
||||
if (ret == 1) /* new ID generated */
|
||||
ret = ops->dump(lfd, e.id, p);
|
||||
|
||||
|
@@ -13,8 +13,9 @@
|
||||
struct fdinfo_entry;
|
||||
struct stat;
|
||||
|
||||
extern int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct stat *st);
|
||||
extern int fd_id_generate_special(struct stat *, u32 *id);
|
||||
struct fd_parms;
|
||||
extern int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct fd_parms *p);
|
||||
extern int fd_id_generate_special(struct fd_parms *p, u32 *id);
|
||||
extern void fd_id_show_tree(void);
|
||||
|
||||
#endif /* __CR_FILE_IDS_H__ */
|
||||
|
Reference in New Issue
Block a user