ce88bd
From patchwork Mon Jul  9 06:28:26 2018
ce88bd
Content-Type: text/plain; charset="utf-8"
ce88bd
MIME-Version: 1.0
ce88bd
Content-Transfer-Encoding: 7bit
ce88bd
Subject: [1/2] Fix building with 4.18
ce88bd
From: Adrian Reber <adrian@lisas.de>
ce88bd
X-Patchwork-Id: 8849
ce88bd
Message-Id: <1531117707-8173-2-git-send-email-adrian@lisas.de>
ce88bd
To: <criu@openvz.org>, Andrei Vagin <avagin@virtuozzo.com>
ce88bd
Cc: Adrian Reber <areber@redhat.com>
ce88bd
Date: Mon, 9 Jul 2018 06:28:26 +0000
ce88bd
ce88bd
From: Adrian Reber <areber@redhat.com>
ce88bd
ce88bd
Building CRIU against 4.18 fails with multiple re-definition errors.
ce88bd
This has been reported upstream
ce88bd
 https://lore.kernel.org/lkml/20180704142116.GM17048@lisas.de/
ce88bd
but there has not been any answer yet. This tries to workaround those
ce88bd
compile errors by pulling the required aio defines directly into CRIU.
ce88bd
ce88bd
Signed-off-by: Adrian Reber <areber@redhat.com>
ce88bd
---
ce88bd
 criu/cr-check.c          |  2 +-
ce88bd
 criu/include/aio.h       | 73 ++++++++++++++++++++++++++++++++++++++++++++++-
ce88bd
 criu/pie/restorer.c      |  1 -
ce88bd
 test/zdtm/static/aio01.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++--
ce88bd
 4 files changed, 145 insertions(+), 5 deletions(-)
ce88bd
ce88bd
diff --git a/criu/cr-check.c b/criu/cr-check.c
ce88bd
index d3393c4..fc53afb 100644
ce88bd
--- a/criu/cr-check.c
ce88bd
+++ b/criu/cr-check.c
ce88bd
@@ -22,7 +22,6 @@
ce88bd
 #include <sys/prctl.h>
ce88bd
 #include <sched.h>
ce88bd
 #include <sys/mount.h>
ce88bd
-#include <linux/aio_abi.h>
ce88bd
 
ce88bd
 #include "../soccr/soccr.h"
ce88bd
 
ce88bd
@@ -51,6 +50,7 @@
ce88bd
 #include "net.h"
ce88bd
 #include "restorer.h"
ce88bd
 #include "uffd.h"
ce88bd
+#include "aio.h"
ce88bd
 
ce88bd
 static char *feature_name(int (*func)());
ce88bd
 
ce88bd
diff --git a/criu/include/aio.h b/criu/include/aio.h
ce88bd
index 9a58089..a749c47 100644
ce88bd
--- a/criu/include/aio.h
ce88bd
+++ b/criu/include/aio.h
ce88bd
@@ -1,7 +1,6 @@
ce88bd
 #ifndef __CR_AIO_H__
ce88bd
 #define __CR_AIO_H__
ce88bd
 
ce88bd
-#include <linux/aio_abi.h>
ce88bd
 #include "images/mm.pb-c.h"
ce88bd
 unsigned int aio_estimate_nr_reqs(unsigned int size);
ce88bd
 int dump_aio_ring(MmEntry *mme, struct vma_area *vma);
ce88bd
@@ -12,6 +11,78 @@ unsigned long aio_rings_args_size(struct vm_area_list *);
ce88bd
 struct task_restore_args;
ce88bd
 int prepare_aios(struct pstree_item *t, struct task_restore_args *ta);
ce88bd
 
ce88bd
+/* copied from linux/fs.h */
ce88bd
+typedef int __bitwise __kernel_rwf_t;
ce88bd
+
ce88bd
+/* copied from linux/aio_abi.h */
ce88bd
+#ifndef COMPEL_SYSCALL_TYPES_H__
ce88bd
+/* The ifndef is needed to avoid a clang compiler error */
ce88bd
+typedef __kernel_ulong_t aio_context_t;
ce88bd
+#endif
ce88bd
+
ce88bd
+enum {
ce88bd
+	IOCB_CMD_PREAD = 0,
ce88bd
+	IOCB_CMD_PWRITE = 1,
ce88bd
+	IOCB_CMD_FSYNC = 2,
ce88bd
+	IOCB_CMD_FDSYNC = 3,
ce88bd
+	/* These two are experimental.
ce88bd
+	 * IOCB_CMD_PREADX = 4,
ce88bd
+	 * IOCB_CMD_POLL = 5,
ce88bd
+	 */
ce88bd
+	IOCB_CMD_NOOP = 6,
ce88bd
+	IOCB_CMD_PREADV = 7,
ce88bd
+	IOCB_CMD_PWRITEV = 8,
ce88bd
+};
ce88bd
+/* read() from /dev/aio returns these structures. */
ce88bd
+struct io_event {
ce88bd
+	__u64		data;		/* the data field from the iocb */
ce88bd
+	__u64		obj;		/* what iocb this event came from */
ce88bd
+	__s64		res;		/* result code for this event */
ce88bd
+	__s64		res2;		/* secondary result */
ce88bd
+};
ce88bd
+
ce88bd
+/*
ce88bd
+ * we always use a 64bit off_t when communicating
ce88bd
+ * with userland.  its up to libraries to do the
ce88bd
+ * proper padding and aio_error abstraction
ce88bd
+ */
ce88bd
+
ce88bd
+struct iocb {
ce88bd
+	/* these are internal to the kernel/libc. */
ce88bd
+	__u64	aio_data;	/* data to be returned in event's data */
ce88bd
+
ce88bd
+#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
ce88bd
+	__u32	aio_key;	/* the kernel sets aio_key to the req # */
ce88bd
+	__kernel_rwf_t aio_rw_flags;	/* RWF_* flags */
ce88bd
+#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
ce88bd
+	__kernel_rwf_t aio_rw_flags;	/* RWF_* flags */
ce88bd
+	__u32	aio_key;	/* the kernel sets aio_key to the req # */
ce88bd
+#else
ce88bd
+#error edit for your odd byteorder.
ce88bd
+#endif
ce88bd
+
ce88bd
+	/* common fields */
ce88bd
+	__u16	aio_lio_opcode;	/* see IOCB_CMD_ above */
ce88bd
+	__s16	aio_reqprio;
ce88bd
+	__u32	aio_fildes;
ce88bd
+
ce88bd
+	__u64	aio_buf;
ce88bd
+	__u64	aio_nbytes;
ce88bd
+	__s64	aio_offset;
ce88bd
+
ce88bd
+	/* extra parameters */
ce88bd
+	__u64	aio_reserved2;	/* TODO: use this for a (struct sigevent *) */
ce88bd
+
ce88bd
+	/* flags for the "struct iocb" */
ce88bd
+	__u32	aio_flags;
ce88bd
+
ce88bd
+	/*
ce88bd
+	 * if the IOCB_FLAG_RESFD flag of "aio_flags" is set, this is an
ce88bd
+	 * eventfd to signal AIO readiness to
ce88bd
+	 */
ce88bd
+	__u32	aio_resfd;
ce88bd
+}; /* 64 bytes */
ce88bd
+
ce88bd
 struct aio_ring {
ce88bd
 	unsigned        id;     /* kernel internal index number */
ce88bd
 	unsigned        nr;     /* number of io_events */
ce88bd
diff --git a/criu/pie/restorer.c b/criu/pie/restorer.c
ce88bd
index 9b7f6dd..f100213 100644
ce88bd
--- a/criu/pie/restorer.c
ce88bd
+++ b/criu/pie/restorer.c
ce88bd
@@ -3,7 +3,6 @@
ce88bd
 
ce88bd
 #include <linux/securebits.h>
ce88bd
 #include <linux/capability.h>
ce88bd
-#include <linux/aio_abi.h>
ce88bd
 #include <sys/types.h>
ce88bd
 #include <sys/mman.h>
ce88bd
 #include <sys/file.h>
ce88bd
diff --git a/test/zdtm/static/aio01.c b/test/zdtm/static/aio01.c
ce88bd
index f84fd35..4ad29a7 100644
ce88bd
--- a/test/zdtm/static/aio01.c
ce88bd
+++ b/test/zdtm/static/aio01.c
ce88bd
@@ -1,6 +1,5 @@
ce88bd
-#include <linux/aio_abi.h>
ce88bd
+#include <linux/types.h>
ce88bd
 #include <sys/syscall.h>
ce88bd
-#include <sys/types.h>
ce88bd
 #include <sys/stat.h>
ce88bd
 #include <string.h>
ce88bd
 #include <stdlib.h>
ce88bd
@@ -13,6 +12,77 @@
ce88bd
 const char *test_doc	= "Check head and tail restore correct";
ce88bd
 const char *test_author	= "Kirill Tkhai <ktkhai@virtuozzo.com>";
ce88bd
 
ce88bd
+/* copied from linux/fs.h */
ce88bd
+typedef int __bitwise __kernel_rwf_t;
ce88bd
+
ce88bd
+/* copied from linux/aio_abi.h */
ce88bd
+#ifndef COMPEL_SYSCALL_TYPES_H__
ce88bd
+typedef __kernel_ulong_t aio_context_t;
ce88bd
+#endif
ce88bd
+
ce88bd
+enum {
ce88bd
+	IOCB_CMD_PREAD = 0,
ce88bd
+	IOCB_CMD_PWRITE = 1,
ce88bd
+	IOCB_CMD_FSYNC = 2,
ce88bd
+	IOCB_CMD_FDSYNC = 3,
ce88bd
+	/* These two are experimental.
ce88bd
+	 * IOCB_CMD_PREADX = 4,
ce88bd
+	 * IOCB_CMD_POLL = 5,
ce88bd
+	 */
ce88bd
+	IOCB_CMD_NOOP = 6,
ce88bd
+	IOCB_CMD_PREADV = 7,
ce88bd
+	IOCB_CMD_PWRITEV = 8,
ce88bd
+};
ce88bd
+/* read() from /dev/aio returns these structures. */
ce88bd
+struct io_event {
ce88bd
+	__u64		data;		/* the data field from the iocb */
ce88bd
+	__u64		obj;		/* what iocb this event came from */
ce88bd
+	__s64		res;		/* result code for this event */
ce88bd
+	__s64		res2;		/* secondary result */
ce88bd
+};
ce88bd
+
ce88bd
+/*
ce88bd
+ * we always use a 64bit off_t when communicating
ce88bd
+ * with userland.  its up to libraries to do the
ce88bd
+ * proper padding and aio_error abstraction
ce88bd
+ */
ce88bd
+
ce88bd
+struct iocb {
ce88bd
+	/* these are internal to the kernel/libc. */
ce88bd
+	__u64	aio_data;	/* data to be returned in event's data */
ce88bd
+
ce88bd
+#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
ce88bd
+	__u32	aio_key;	/* the kernel sets aio_key to the req # */
ce88bd
+	__kernel_rwf_t aio_rw_flags;	/* RWF_* flags */
ce88bd
+#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
ce88bd
+	__kernel_rwf_t aio_rw_flags;	/* RWF_* flags */
ce88bd
+	__u32	aio_key;	/* the kernel sets aio_key to the req # */
ce88bd
+#else
ce88bd
+#error edit for your odd byteorder.
ce88bd
+#endif
ce88bd
+
ce88bd
+	/* common fields */
ce88bd
+	__u16	aio_lio_opcode;	/* see IOCB_CMD_ above */
ce88bd
+	__s16	aio_reqprio;
ce88bd
+	__u32	aio_fildes;
ce88bd
+
ce88bd
+	__u64	aio_buf;
ce88bd
+	__u64	aio_nbytes;
ce88bd
+	__s64	aio_offset;
ce88bd
+
ce88bd
+	/* extra parameters */
ce88bd
+	__u64	aio_reserved2;	/* TODO: use this for a (struct sigevent *) */
ce88bd
+
ce88bd
+	/* flags for the "struct iocb" */
ce88bd
+	__u32	aio_flags;
ce88bd
+
ce88bd
+	/*
ce88bd
+	 * if the IOCB_FLAG_RESFD flag of "aio_flags" is set, this is an
ce88bd
+	 * eventfd to signal AIO readiness to
ce88bd
+	 */
ce88bd
+	__u32	aio_resfd;
ce88bd
+}; /* 64 bytes */
ce88bd
+
ce88bd
 struct aio_ring {
ce88bd
 	unsigned	id;     /* kernel internal index number */
ce88bd
 	unsigned	nr;     /* number of io_events */