[CRIU] [PATCH 2/2] BPF map files are now dumped.

Abhishek Vijeev abhishek.vijeev at gmail.com
Thu Apr 23 11:02:17 MSK 2020


Hi Andrei,

Thank you for your response.

I will take into account all your suggestions and submit a consolidated
pull request
with these changes after implementing a test for BPF map files.

Thank you,
Abhishek.

On Thu, Apr 23, 2020 at 8:58 AM Andrei Vagin <avagin at gmail.com> wrote:

> You need to implement a test for BPF map files.
>
> You can look at the existing tests as examples:
> https://github.com/checkpoint-restore/criu/tree/criu-dev/test/zdtm/static
>
> Thanks,
> Andrei
>
> On Wed, Apr 22, 2020 at 12:57:41AM +0530, Abhishek Vijeev wrote:
> > ---
> >  criu/proc_parse.c        | 81 ++++++++++++++++++++++++++++++++++++++++
> >  images/bpfmap-file.proto |  6 +--
> >  2 files changed, 84 insertions(+), 3 deletions(-)
> >
> > diff --git a/criu/proc_parse.c b/criu/proc_parse.c
> > index 4a22700a..46d6afd6 100644
> > --- a/criu/proc_parse.c
> > +++ b/criu/proc_parse.c
> > @@ -1683,6 +1683,73 @@ nodata:
> >       goto parse_err;
> >  }
> >
> > +static int parse_bpfmap(struct bfd *f, char *str, BpfmapFileEntry *bpf)
> > +{
> > +     /*
> > +      * Format is
> > +      * map_type: 3
> > +      * key_size: 4
> > +      * value_size: 4
> > +      * max_entries: 4
> > +      * map_flags: 0x0
> > +      * memlock: 4096
> > +      * map_id: 10
> > +      * frozen: 0
> > +      */
> > +
> > +     if (sscanf(str, "map_type: %u", &bpf->map_type) != 1)
> > +             goto parse_err;
> > +
> > +     str = breadline(f);
> > +     if (IS_ERR_OR_NULL(str))
> > +             goto nodata;
> > +     if (sscanf(str, "key_size: %u", &bpf->key_size) != 1)
> > +             goto parse_err;
> > +
> > +     str = breadline(f);
> > +     if (IS_ERR_OR_NULL(str))
> > +             goto nodata;
> > +     if (sscanf(str, "value_size: %u", &bpf->value_size) != 1)
> > +             goto parse_err;
> > +
> > +     str = breadline(f);
> > +     if (IS_ERR_OR_NULL(str))
> > +             goto nodata;
> > +     if (sscanf(str, "max_entries: %u", &bpf->max_entries) != 1)
> > +             goto parse_err;
> > +
> > +     str = breadline(f);
> > +     if (IS_ERR_OR_NULL(str))
> > +             goto nodata;
> > +     if (sscanf(str, "map_flags: %lu", &bpf->map_flags) != 1)
> > +             goto parse_err;
> > +
> > +     str = breadline(f);
> > +     if (IS_ERR_OR_NULL(str))
> > +             goto nodata;
> > +     if (sscanf(str, "memlock: %lu", &bpf->memlock) != 1)
> > +             goto parse_err;
> > +
> > +     str = breadline(f);
> > +     if (IS_ERR_OR_NULL(str))
> > +             goto nodata;
> > +     if (sscanf(str, "map_id: %u", &bpf->map_id) != 1)
> > +             goto parse_err;
> > +
> > +     str = breadline(f);
> > +     if (IS_ERR_OR_NULL(str))
> > +             goto nodata;
> > +     if (sscanf(str, "frozen: %d", &bpf->frozen) != 1)
> > +             goto parse_err;
> > +     return 0;
> > +
> > +parse_err:
> > +     return -1;
> > +nodata:
> > +     pr_err("No data left in proc file while parsing bpfmap\n");
> > +     goto parse_err;
> > +}
> > +
> >  #define fdinfo_field(str, field)     !strncmp(str, field":",
> sizeof(field))
> >
> >  static int parse_file_lock_buf(char *buf, struct file_lock *fl,
> > @@ -2015,6 +2082,20 @@ static int parse_fdinfo_pid_s(int pid, int fd,
> int type, void *arg)
> >                       entry_met = true;
> >                       continue;
> >               }
> > +             if (fdinfo_field(str, "map_type")) {
> > +
> > +                     BpfmapFileEntry *bpf = arg;
> > +
> > +                     if (type != FD_TYPES__BPFMAP)
> > +                             goto parse_err;
> > +
> > +                     ret = parse_bpfmap(&f, str, bpf);
> > +                     if (ret)
> > +                             goto parse_err;
> > +
> > +                     entry_met = true;
> > +                     continue;
> > +             }
> >       }
> >
> >       exit_code = 0;
> > diff --git a/images/bpfmap-file.proto b/images/bpfmap-file.proto
> > index a21c032c..9f0b8593 100644
> > --- a/images/bpfmap-file.proto
> > +++ b/images/bpfmap-file.proto
> > @@ -15,9 +15,9 @@ message bpfmap_file_entry {
> >      required uint32     max_entries = 10;
> >
> >      optional sint32          mnt_id  = 11 [default = -1];
> > -    optional uint64     map_flags   = 12;
> > -    optional uint64     memlock = 13;
> > -    optional bool       frozen  = 14;
> > +    required uint64     map_flags   = 12;
> > +    required uint64     memlock = 13;
> > +    required bool       frozen  = 14;
> >
> >
> >  }
> > \ No newline at end of file
> > --
> > 2.17.1
> >
> > _______________________________________________
> > CRIU mailing list
> > CRIU at openvz.org
> > https://lists.openvz.org/mailman/listinfo/criu
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvz.org/pipermail/criu/attachments/20200423/93082b8a/attachment-0001.html>


More information about the CRIU mailing list