[CRIU] [PATCH 1/1] Preliminary set of changes to support dumping BPF map files. A major task is yet to be completed: parsing BPF file info from the proc filesystem in the function parse_fdinfo_pid_s()

Abhishek Vijeev abhishek.vijeev at gmail.com
Mon Apr 20 21:52:30 MSK 2020


---
 criu/Makefile.crtools    |  1 +
 criu/bpfmap.c            | 49 ++++++++++++++++++++++++++++++++++++++++
 criu/files.c             |  5 ++++
 criu/include/bpfmap.h    |  9 ++++++++
 images/Makefile          |  1 +
 images/bpfmap-file.proto | 23 +++++++++++++++++++
 images/fdinfo.proto      |  4 ++++
 7 files changed, 92 insertions(+)
 create mode 100644 criu/bpfmap.c
 create mode 100644 criu/include/bpfmap.h
 create mode 100644 images/bpfmap-file.proto

diff --git a/criu/Makefile.crtools b/criu/Makefile.crtools
index de1590dd..1378ab90 100644
--- a/criu/Makefile.crtools
+++ b/criu/Makefile.crtools
@@ -91,6 +91,7 @@ obj-y			+= servicefd.o
 obj-y			+= pie-util-vdso.o
 obj-y			+= vdso.o
 obj-y			+= timens.o
+obj-y                  += bpfmap.o
 obj-$(CONFIG_COMPAT)	+= pie-util-vdso-elf32.o
 CFLAGS_pie-util-vdso-elf32.o	+= -DCONFIG_VDSO_32
 obj-$(CONFIG_COMPAT)	+= vdso-compat.o
diff --git a/criu/bpfmap.c b/criu/bpfmap.c
new file mode 100644
index 00000000..187590d1
--- /dev/null
+++ b/criu/bpfmap.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+
+#include "common/compiler.h"
+#include "imgset.h"
+#include "bpfmap.h"
+#include "fdinfo.h"
+#include "image.h"
+#include "util.h"
+#include "log.h"
+
+#include "protobuf.h"
+#include "bpfmap-file.pb-c.h"
+
+int is_bpfmap_link(char *link)
+{
+    printf("is_bpfmap_link: %s\n", link);
+	return is_anon_link_type(link, "bpf-map");
+}
+
+static void pr_info_bpfmap(char *action, BpfmapFileEntry *bpf)
+{
+	pr_info("%sbpfmap: id %#08x map_id %#08x map_type %d flags %#04x\n",
+		action, bpf->id, bpf->map_id, bpf->map_type, bpf->flags);
+}
+
+static int dump_one_bpfmap(int lfd, u32 id, const struct fd_parms *p)
+{
+	BpfmapFileEntry bpf = BPFMAP_FILE_ENTRY__INIT;
+	FileEntry fe = FILE_ENTRY__INIT;
+
+	if (parse_fdinfo(lfd, FD_TYPES__BPFMAP, &bpf))
+		return -1;
+
+	bpf.id = id;
+	bpf.flags = p->flags;
+	bpf.fown = (FownEntry *)&p->fown;
+
+	fe.type = FD_TYPES__BPFMAP;
+	fe.id = bpf.id;
+	fe.bpf = &bpf;
+
+	pr_info_bpfmap("Dumping ", &bpf);
+	return pb_write_one(img_from_set(glob_imgset, CR_FD_FILES), &fe, PB_FILE);
+}
+
+const struct fdtype_ops bpfmap_dump_ops = {
+	.type		= FD_TYPES__BPFMAP,
+	.dump		= dump_one_bpfmap,
+};
\ No newline at end of file
diff --git a/criu/files.c b/criu/files.c
index a1fd2676..e5c8ee0e 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -48,6 +48,7 @@
 #include "string.h"
 #include "kerndat.h"
 #include "fdstore.h"
+#include "bpfmap.h"
 
 #include "protobuf.h"
 #include "util.h"
@@ -539,6 +540,10 @@ static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
 			ops = &signalfd_dump_ops;
 		else if (is_timerfd_link(link))
 			ops = &timerfd_dump_ops;
+		else if(is_bpfmap_link(link)) {
+			printf("Link is of type bpf-map\n");
+			ops = &bpfmap_dump_ops;
+		}
 		else
 			return dump_unsupp_fd(&p, lfd, "anon", link, e);
 
diff --git a/criu/include/bpfmap.h b/criu/include/bpfmap.h
new file mode 100644
index 00000000..7ed6b940
--- /dev/null
+++ b/criu/include/bpfmap.h
@@ -0,0 +1,9 @@
+#ifndef __CR_BPFMAP_H__
+#define __CR_BPFMAP_H__
+
+#include "files.h"
+
+extern int is_bpfmap_link(char *link);
+extern const struct fdtype_ops bpfmap_dump_ops;
+
+#endif /* __CR_BPFMAP_H__ */
\ No newline at end of file
diff --git a/images/Makefile b/images/Makefile
index 4188e2ef..1c3a6c07 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -67,6 +67,7 @@ proto-obj-y	+= sit.o
 proto-obj-y	+= remote-image.o
 proto-obj-y	+= memfd.o
 proto-obj-y	+= timens.o
+proto-obj-y    += bpfmap-file.o
 
 CFLAGS		+= -iquote $(obj)/
 
diff --git a/images/bpfmap-file.proto b/images/bpfmap-file.proto
new file mode 100644
index 00000000..a21c032c
--- /dev/null
+++ b/images/bpfmap-file.proto
@@ -0,0 +1,23 @@
+syntax = "proto2";
+
+import "opts.proto";
+import "fown.proto";
+message bpfmap_file_entry {
+
+    required uint32		id	= 1;
+	required uint32		flags	= 2 [(criu).flags = "rfile.flags"];
+    required uint64		pos	= 3;
+    required fown_entry	fown	= 5;
+    required uint32     map_type    = 6;
+    required uint32     key_size    = 7;
+    required uint32     value_size  = 8;
+    required uint32     map_id  = 9;
+    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;
+
+
+}
\ No newline at end of file
diff --git a/images/fdinfo.proto b/images/fdinfo.proto
index d966d5bc..b97faf8a 100644
--- a/images/fdinfo.proto
+++ b/images/fdinfo.proto
@@ -17,6 +17,7 @@ import "fifo.proto";
 import "pipe.proto";
 import "tty.proto";
 import "memfd.proto";
+import "bpfmap-file.proto";
 
 enum fd_types {
 	UND		= 0;
@@ -38,6 +39,7 @@ enum fd_types {
 	EXT		= 16;
 	TIMERFD		= 17;
 	MEMFD		= 18;
+	BPFMAP		= 19;
 
 	/* Any number above the real used. Not stored to image */
 	CTL_TTY		= 65534;
@@ -73,4 +75,6 @@ message file_entry {
 	optional pipe_entry		pipe	= 18;
 	optional tty_file_entry		tty	= 19;
 	optional memfd_file_entry	memfd	= 20;
+	optional bpfmap_file_entry	bpf	= 21;
+
 }
-- 
2.17.1



More information about the CRIU mailing list