[CRIU] [PATCH 08/16] files-ids: generate id-s accoding with mnt_id, st->st_dev and st->st_ino
Pavel Emelyanov
xemul at parallels.com
Wed Apr 9 08:00:32 PDT 2014
On 04/09/2014 03:35 AM, Andrey Vagin wrote:
> One device can be mounted a few times, so files are identical only,
> if they have the same mnt_id.
I see no changes in fdid generation, only it the caching.
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
> cr-dump.c | 8 ++++----
> file-ids.c | 32 +++++++++++++++++++-------------
> files.c | 2 +-
> include/file-ids.h | 5 +++--
> 4 files changed, 27 insertions(+), 20 deletions(-)
>
> diff --git a/cr-dump.c b/cr-dump.c
> index 075a75f..ca85ca8 100644
> --- a/cr-dump.c
> +++ b/cr-dump.c
> @@ -268,7 +268,7 @@ static int dump_task_exe_link(pid_t pid, MmEntry *mm)
> if (get_fd_mntid(fd, ¶ms.mnt_id))
> 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);
> }
>
> @@ -297,7 +297,7 @@ static int dump_task_fs(pid_t pid, struct parasite_dump_misc *misc, struct cr_fd
> if (get_fd_mntid(fd, &p.mnt_id))
> 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;
> @@ -318,7 +318,7 @@ static int dump_task_fs(pid_t pid, struct parasite_dump_misc *misc, struct cr_fd
> if (get_fd_mntid(fd, &p.mnt_id))
> 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;
> @@ -372,7 +372,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);
> }
>
> diff --git a/file-ids.c b/file-ids.c
> index 30f1bbc..3226d15 100644
> --- a/file-ids.c
> +++ b/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;
> diff --git a/files.c b/files.c
> index cfbbb4b..f2b7435 100644
> --- a/files.c
> +++ b/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);
>
> diff --git a/include/file-ids.h b/include/file-ids.h
> index 28434f3..6323d98 100644
> --- a/include/file-ids.h
> +++ b/include/file-ids.h
> @@ -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__ */
>
More information about the CRIU
mailing list