From b7dd5e63bf48c2af952d9acb0e440c91361ab942 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 8 Sep 2014 15:20:10 +0000 Subject: [PATCH] Use external libaio.h Stop using an outdated partial copy of libaio.h, switch back to external libaio.h from libaio. This partially reverts commit 2df03c494eb3c36c4178eba35c374831031d1a58. * aio.c: Drop a partial copy of libaio.h, include instead. (print_common_flags): Check for HAVE_STRUCT_IOCB_U_C_FLAGS. (sys_io_submit): Check for HAVE_DECL_IO_CMD_PWRITE and HAVE_DECL_IO_CMD_PWRITEV. * configure.ac: Check for libaio.h and declaration it provides. --- aio.c | 129 ++++++--------------------------------------------- configure.ac | 5 ++ 2 files changed, 18 insertions(+), 116 deletions(-) diff --git a/aio.c b/aio.c index 6bf8f828..18e53013 100644 --- a/aio.c +++ b/aio.c @@ -29,124 +29,10 @@ */ #include "defs.h" - -/* --- Copied from libaio-0.3.109/src/libaio.h --- - * Why keep a copy instead of using external libaio.h? - * Because we want to properly decode 32-bit aio calls - * by 64-bit strace. For that, we need more definitions than - * libaio.h provides. (TODO). - * Keeping our local 32-bit compat defs in sync with libaio.h - * _without seeing libaio structs_ is hard/more bug-prone. - * A smaller benefit is that we don't need libaio installed. - */ -#define HAVE_LIBAIO_H 1 -typedef enum io_iocb_cmd { - IO_CMD_PREAD = 0, - IO_CMD_PWRITE = 1, - - IO_CMD_FSYNC = 2, - IO_CMD_FDSYNC = 3, - - IO_CMD_POLL = 5, /* Never implemented in mainline, see io_prep_poll */ - IO_CMD_NOOP = 6, - IO_CMD_PREADV = 7, - IO_CMD_PWRITEV = 8, -} io_iocb_cmd_t; - -#if defined(__i386__) /* little endian, 32 bits */ -#define PADDED(x, y) x; unsigned y -#define PADDEDptr(x, y) x; unsigned y -#define PADDEDul(x, y) unsigned long x; unsigned y -#elif defined(__ia64__) || defined(__x86_64__) || defined(__alpha__) -#define PADDED(x, y) x, y -#define PADDEDptr(x, y) x -#define PADDEDul(x, y) unsigned long x -#elif defined(__powerpc64__) /* big endian, 64 bits */ -#define PADDED(x, y) unsigned y; x -#define PADDEDptr(x,y) x -#define PADDEDul(x, y) unsigned long x -#elif defined(__PPC__) /* big endian, 32 bits */ -#define PADDED(x, y) unsigned y; x -#define PADDEDptr(x, y) unsigned y; x -#define PADDEDul(x, y) unsigned y; unsigned long x -#elif defined(__s390x__) /* big endian, 64 bits */ -#define PADDED(x, y) unsigned y; x -#define PADDEDptr(x,y) x -#define PADDEDul(x, y) unsigned long x -#elif defined(__s390__) /* big endian, 32 bits */ -#define PADDED(x, y) unsigned y; x -#define PADDEDptr(x, y) unsigned y; x -#define PADDEDul(x, y) unsigned y; unsigned long x -#elif defined(__arm__) -# if defined (__ARMEB__) /* big endian, 32 bits */ -#define PADDED(x, y) unsigned y; x -#define PADDEDptr(x, y) unsigned y; x -#define PADDEDul(x, y) unsigned y; unsigned long x -# else /* little endian, 32 bits */ -#define PADDED(x, y) x; unsigned y -#define PADDEDptr(x, y) x; unsigned y -#define PADDEDul(x, y) unsigned long x; unsigned y -# endif -#else -# warning No AIO definitions for this architecture => no io_submit decoding -# undef HAVE_LIBAIO_H -#endif - #ifdef HAVE_LIBAIO_H -struct io_iocb_poll { - PADDED(int events, __pad1); -}; /* result code is the set of result flags or -'ve errno */ - -struct io_iocb_sockaddr { - struct sockaddr *addr; - int len; -}; /* result code is the length of the sockaddr, or -'ve errno */ - -struct io_iocb_common { - PADDEDptr(void *buf, __pad1); - PADDEDul(nbytes, __pad2); - long long offset; - long long __pad3; - unsigned flags; - unsigned resfd; -}; /* result code is the amount read or -'ve errno */ - -struct io_iocb_vector { - const struct iovec *vec; - int nr; - long long offset; -}; /* result code is the amount read or -'ve errno */ - -struct iocb { - PADDEDptr(void *data, __pad1); /* Return in the io completion event */ - PADDED(unsigned key, __pad2); /* For use in identifying io requests */ - - short aio_lio_opcode; - short aio_reqprio; - int aio_fildes; - - union { - struct io_iocb_common c; - struct io_iocb_vector v; - struct io_iocb_poll poll; - struct io_iocb_sockaddr saddr; - } u; -}; - -struct io_event { - PADDEDptr(void *data, __pad1); - PADDEDptr(struct iocb *obj, __pad2); - PADDEDul(res, __pad3); - PADDEDul(res2, __pad4); -}; - -#undef PADDED -#undef PADDEDptr -#undef PADDEDul - -#endif /* HAVE_LIBAIO_H */ +# include +#endif -/* --- End of a chunk of libaio.h --- */ /* Not defined in libaio.h */ #ifndef IOCB_RESFD # define IOCB_RESFD (1 << 0) @@ -214,10 +100,14 @@ tprint_lio_opcode(unsigned cmd) static void print_common_flags(struct iocb *iocb) { +#if HAVE_STRUCT_IOCB_U_C_FLAGS if (iocb->u.c.flags & IOCB_RESFD) tprintf(", resfd=%d", iocb->u.c.resfd); if (iocb->u.c.flags & ~IOCB_RESFD) tprintf(", flags=%x", iocb->u.c.flags); +#else +# warning "libaio.h is too old => limited io_submit decoding" +#endif } #endif /* HAVE_LIBAIO_H */ @@ -263,11 +153,13 @@ sys_io_submit(struct tcb *tcp) tprintf(", filedes:%d", iocb.aio_fildes); switch (sub) { case SUB_COMMON: +#if HAVE_DECL_IO_CMD_PWRITE if (iocb.aio_lio_opcode == IO_CMD_PWRITE) { tprints(", str:"); printstr(tcp, (unsigned long)iocb.u.c.buf, iocb.u.c.nbytes); } else +#endif tprintf(", buf:%p", iocb.u.c.buf); tprintf(", nbytes:%lu, offset:%lld", iocb.u.c.nbytes, @@ -280,7 +172,11 @@ sys_io_submit(struct tcb *tcp) tprints(", "); tprint_iov(tcp, iocb.u.v.nr, (unsigned long)iocb.u.v.vec, +#if HAVE_DECL_IO_CMD_PWRITEV iocb.aio_lio_opcode == IO_CMD_PWRITEV +#else + 0 +#endif ); break; case SUB_POLL: @@ -294,6 +190,7 @@ sys_io_submit(struct tcb *tcp) } tprints("}"); #else +# warning "libaio.h is not available => no io_submit decoding" tprintf("%lu, %ld, %#lx", tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]); #endif } diff --git a/configure.ac b/configure.ac index 054f85be..52c1ecf6 100644 --- a/configure.ac +++ b/configure.ac @@ -273,6 +273,11 @@ AC_CHECK_MEMBERS([struct sigevent._sigev_un._pad, AC_CHECK_TYPES([struct flock64],,, [#include ]) +AC_CHECK_HEADERS([libaio.h], [ + AC_CHECK_MEMBERS([struct iocb.u.c.flags],,, [#include ]) + AC_CHECK_DECLS([IO_CMD_PWRITE, IO_CMD_PWRITEV],,, [#include ]) +]) + AC_CHECK_DECLS([sys_errlist]) AC_CHECK_DECLS(m4_normalize([ PTRACE_EVENT_CLONE, -- 2.40.0