From 2f7ef4a845b05164c211d30b3daf4c2a0178c4ad Mon Sep 17 00:00:00 2001
From: Jiri Palecek <jirka@debian.(none)>
Date: Sat, 8 Nov 2008 13:09:04 +0100
Subject: [PATCH] Enable AIO and listio for linux in tlibio

---
 include/tlibio.h                     |   25 ++++--
 lib/tlibio.c                         |  156 +++++++++++++++++++++++-----------
 testcases/commands/eject/Makefile    |    2 +-
 testcases/kernel/fs/doio/Makefile    |    2 +-
 testcases/kernel/ipc/pipeio/Makefile |    2 +-
 5 files changed, 127 insertions(+), 60 deletions(-)

diff --git a/include/tlibio.h b/include/tlibio.h
index 59333e7..10805f3 100644
--- a/include/tlibio.h
+++ b/include/tlibio.h
@@ -41,25 +41,33 @@
 #define LIO_IO_ATYPES           00077   /* all io types */
 #define LIO_IO_TYPES            00061   /* all io types, non-async */
 #endif /* sgi */
-#if defined(__linux__) || defined(__sun) || defined(__hpux) || defined(_AIX)
+#if defined(__linux__)
+#define LIO_IO_TYPES            00061   /* all io types */
+#define LIO_IO_ATYPES           00077   /* all io types */
+#endif
+#if defined(__sun) || defined(__hpux) || defined(_AIX)
 #define LIO_IO_TYPES            00021   /* all io types */
 #endif /* linux */
 #ifdef CRAY
 #define LIO_IO_TYPES            00017   /* all io types */
 #endif /* CRAY */
 
+#ifndef LIO_IO_ATYPES
+#define LIO_IO_ATYPES LIO_IO_TYPES
+#endif
+
 #define LIO_WAIT_NONE           00010000 /* return asap -- use with care */
 #define LIO_WAIT_ACTIVE         00020000 /* spin looking at iosw fields, or EINPROGRESS */
 #define LIO_WAIT_RECALL         00040000 /* call recall(2)/aio_suspend(3) */
 #define LIO_WAIT_SIGPAUSE       00100000 /* call pause */
 #define LIO_WAIT_SIGACTIVE      00200000 /* spin waiting for signal */
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
 #define LIO_WAIT_CBSUSPEND      00400000 /* aio_suspend waiting for callback */
 #define LIO_WAIT_SIGSUSPEND     01000000 /* aio_suspend waiting for signal */
 #define LIO_WAIT_ATYPES         01760000 /* all async wait types, except nowait */
 #define LIO_WAIT_TYPES          00020000 /* all sync wait types (sorta) */
 #endif /* sgi */
-#if defined(__linux__) || defined(__sun) || defined(__hpux) || defined(_AIX)
+#if defined(__sun) || defined(__hpux) || defined(_AIX)
 #define LIO_WAIT_TYPES          00300000 /* all wait types, except nowait */
 #endif /* linux */
 #ifdef CRAY
@@ -69,7 +77,7 @@
 /* meta wait io  */
 /*  00  000 0000 */
 
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
 /* all callback wait types */
 #define LIO_WAIT_CBTYPES	(LIO_WAIT_CBSUSPEND)
 /* all signal wait types */
@@ -77,7 +85,7 @@
 /* all aio_{read,write} or lio_listio */
 #define LIO_IO_ASYNC_TYPES	(LIO_IO_ASYNC|LIO_IO_SLISTIO|LIO_IO_ALISTIO)
 #endif /* sgi */
-#if defined(__linux__) || defined(__sun) || defined(__hpux) || defined(_AIX)
+#if defined(__sun) || defined(__hpux) || defined(_AIX)
 /* all signal wait types */
 #define LIO_WAIT_SIGTYPES	(LIO_WAIT_SIGPAUSE)
 #endif /* linux */
@@ -129,11 +137,16 @@ int  lio_random_methods(long mask);
 int  lio_wait4asyncio(int method, int fd, struct iosw **statptr);
 int  lio_check_asyncio(char *io_type, int size, struct iosw *status);
 #endif /* CRAY */
-#ifdef sgi
+#if defined (sgi)
 #include <aio.h>
 int  lio_wait4asyncio(int method, int fd, aiocb_t *aiocbp);
 int  lio_check_asyncio(char *io_type, int size, aiocb_t *aiocbp, int method);
 #endif /* sgi */
+#if defined(__linux__)
+#include <aio.h>
+int  lio_wait4asyncio(int method, int fd, struct aiocb *aiocbp);
+int  lio_check_asyncio(char *io_type, int size, struct aiocb *aiocbp, int method);
+#endif
 
 /*
  * Define the structure that contains the infomation that is used
diff --git a/lib/tlibio.c b/lib/tlibio.c
index 6edbdbb..79d806b 100644
--- a/lib/tlibio.c
+++ b/lib/tlibio.c
@@ -78,6 +78,10 @@
  *
  */
 
+#ifdef __linux__
+#define _GNU_SOURCE
+#define _LARGEFILE64_SOURCE
+#endif
 #include <stdio.h>
 #include <ctype.h>
 #include <fcntl.h>
@@ -121,9 +125,7 @@
 #endif
 
 
-#ifndef __linux__
 static void lio_async_signal_handler();
-#endif
 #ifdef sgi
 static void lio_async_callback_handler();
 #endif
@@ -136,7 +138,7 @@ struct lio_info_type  Lio_info1[] = {
     { "p", LIO_IO_ASYNC|LIO_WAIT_SIGACTIVE, "async i/o using a loop to wait for a signal" },
     { "b", LIO_IO_ASYNC|LIO_WAIT_SIGPAUSE, "async i/o using pause" },
     { "a", LIO_IO_ASYNC|LIO_WAIT_RECALL, "async i/o using recall/aio_suspend" },
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
     { "r", 
 	LIO_RANDOM|LIO_IO_TYPES|LIO_WAIT_TYPES, "random sync i/o types and wait methods" },
     { "R", 
@@ -180,7 +182,7 @@ char Lio_SysCall[PATH_MAX];	/* string containing last i/o system call */
 
 static volatile int Received_signal = 0;	/* number of signals received */
 static volatile int Rec_signal;
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
 static volatile int Received_callback = 0;	/* number of callbacks received */
 static volatile int Rec_callback;
 #endif
@@ -412,7 +414,6 @@ lio_help2(char *prefix)
     return;
 }
 
-#ifndef __linux__
 /***********************************************************************
  * This is an internal signal handler.
  * If the handler is called, it will increment the Received_signal
@@ -429,9 +430,8 @@ lio_async_signal_handler(int sig)
 
 	return;
 }
-#endif
 
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
 /***********************************************************************
  * This is an internal callback handler.
  * If the handler is called, it will increment the Received_callback
@@ -442,7 +442,7 @@ lio_async_callback_handler(sigval_t sigval)
 {
 	if ( Debug_level )
 	    printf("DEBUG %s/%d: received callback, nbytes=%ld, a callback called %d times\n",
-		__FILE__, __LINE__, sigval.sival_int, Received_callback+1);
+		__FILE__, __LINE__, (long)sigval.sival_int, Received_callback+1);
 
 	Received_callback++;
 
@@ -534,10 +534,8 @@ long wrd;	/* to allow future features, use zero for now */
 {
     int ret = 0;	/* syscall return or used to get random method */
     char *io_type;		/* Holds string of type of io */
-#ifndef __linux__
     int omethod = method;
     int listio_cmd;		/* Holds the listio/lio_listio cmd */
-#endif
 #ifdef  CRAY
     struct listreq request;	/* Used when a listio is wanted */
     struct iosw status, *statptr[1];  
@@ -545,12 +543,16 @@ long wrd;	/* to allow future features, use zero for now */
     /* for linux or sgi */
     struct iovec iov;	/* iovec for writev(2) */
 #endif
-#ifdef sgi
+#if defined (sgi)
     aiocb_t aiocbp;	/* POSIX aio control block */
     aiocb_t *aiolist[1]; /* list of aio control blocks for lio_listio */
     off64_t poffset;	/* pwrite(2) offset */
 #endif
-
+#if defined (__linux__)
+	struct aiocb aiocbp;	/* POSIX aio control block */
+	struct aiocb *aiolist[1]; /* list of aio control blocks for lio_listio */
+	off64_t poffset;	/* pwrite(2) offset */
+#endif
     /*
      * If LIO_RANDOM bit specified, get new method randomly.
      */
@@ -566,7 +568,7 @@ long wrd;	/* to allow future features, use zero for now */
 	*errmsg = Errormsg;
 
     Rec_signal=Received_signal;	/* get the current number of signals received */
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
     Rec_callback=Received_callback;	/* get the current number of callbacks received */
 #endif
 
@@ -580,16 +582,25 @@ long wrd;	/* to allow future features, use zero for now */
     iov.iov_base = buffer;
     iov.iov_len = size;
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
+#if defined(sgi)
     memset(&aiocbp, 0x00, sizeof(aiocb_t));
+#else
+	memset(&aiocbp, 0x00, sizeof(struct aiocb));
+#endif
     aiocbp.aio_fildes = fd;
     aiocbp.aio_nbytes = size;
     aiocbp.aio_buf = buffer;
 /*    aiocbp.aio_offset = lseek( fd, 0, SEEK_CUR ); -- set below */
     aiocbp.aio_sigevent.sigev_notify = SIGEV_NONE;
     aiocbp.aio_sigevent.sigev_signo = 0;
+#ifdef sgi
     aiocbp.aio_sigevent.sigev_func = NULL;
     aiocbp.aio_sigevent.sigev_value.sival_int = 0;
+#elif defined(__linux__)
+	aiocbp.aio_sigevent.sigev_notify_function = NULL;
+	aiocbp.aio_sigevent.sigev_notify_attributes = 0;
+#endif
     aiolist[0] = &aiocbp;
 
     if( (ret = lseek( fd, 0, SEEK_CUR )) == -1 ){
@@ -620,7 +631,9 @@ long wrd;	/* to allow future features, use zero for now */
 		return -errno;
 	}
     }
+#if defined(sgi) || defined(__linux__)
     poffset = (off64_t)ret;
+#endif
     aiocbp.aio_offset = ret;
 
 #endif
@@ -637,7 +650,7 @@ long wrd;	/* to allow future features, use zero for now */
 	sig=0;	/* ignore signal parameter */
     }
 
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
     if ( sig && (method & LIO_WAIT_CBTYPES) )
 	sig=0; /* ignore signal parameter */
 #endif
@@ -654,13 +667,13 @@ long wrd;	/* to allow future features, use zero for now */
 #ifdef CRAY
         sigctl(SCTL_REG, sig, lio_async_signal_handler);
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
         aiocbp.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
 	aiocbp.aio_sigevent.sigev_signo = sig;
         sigset(sig, lio_async_signal_handler);
 #endif /* sgi */
     }
-#ifdef sgi
+#if defined(sgi)
     else if( method & LIO_WAIT_CBTYPES ){
 	/* sival_int just has to be something that I can use
 	 * to identify the callback, and "size" happens to be handy...
@@ -670,7 +683,16 @@ long wrd;	/* to allow future features, use zero for now */
 	aiocbp.aio_sigevent.sigev_value.sival_int = size;
     }
 #endif
-
+#if defined(__linux__)
+	else if( method & LIO_WAIT_CBTYPES ){
+		/* sival_int just has to be something that I can use
+		 * to identify the callback, and "size" happens to be handy...
+		 */
+		aiocbp.aio_sigevent.sigev_notify = SIGEV_THREAD;
+		aiocbp.aio_sigevent.sigev_notify_function = lio_async_callback_handler;
+		aiocbp.aio_sigevent.sigev_notify_attributes = (void*)size;
+	}
+#endif
     /*
      * Determine the system call that will be called and produce
      * the string of the system call and place it in Lio_SysCall.
@@ -680,7 +702,7 @@ long wrd;	/* to allow future features, use zero for now */
      * bytes written/read.
      */
      
-    if ( (method & LIO_IO_SYNC) || (method & LIO_IO_TYPES) == 0 ){
+	if ( (method & LIO_IO_SYNC) || (method & (LIO_IO_TYPES | LIO_IO_ATYPES)) == 0 ){
 	/*
 	 * write(2) is used if LIO_IO_SYNC bit is set or not none
          * of the LIO_IO_TYPES bits are set (default).
@@ -735,7 +757,7 @@ long wrd;	/* to allow future features, use zero for now */
 	    return -errno;
 	}
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
 	sprintf(Lio_SysCall,
 	    "aio_write(fildes=%d, buf, nbytes=%d, signo=%d)", fd, size, sig);
 	io_type="aio_write";
@@ -798,7 +820,7 @@ long wrd;	/* to allow future features, use zero for now */
 	return ret;
 
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
 
 	aiocbp.aio_lio_opcode = LIO_WRITE;
 	listio_cmd=LIO_WAIT;
@@ -864,7 +886,7 @@ long wrd;	/* to allow future features, use zero for now */
             return -errno;
         }
 #endif
-#ifdef sgi
+#if defined (sgi) || defined(__linux__)
 	aiocbp.aio_lio_opcode = LIO_WRITE;
 	listio_cmd=LIO_NOWAIT;
 	io_type="lio_listio(3) async write";
@@ -921,12 +943,12 @@ long wrd;	/* to allow future features, use zero for now */
     } /* LIO_IO_SYNCV */
 #endif
 
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
     else if ( method & LIO_IO_SYNCP ) {
 	io_type="pwrite(2)";
 
 	sprintf(Lio_SysCall, 
-		"pwrite(%d, buf, %d, %lld)", fd, size, poffset);
+						"pwrite(%d, buf, %d, %lld)", fd, size, (long long)poffset);
 
         if ( Debug_level ) {
 	    printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
@@ -934,7 +956,7 @@ long wrd;	/* to allow future features, use zero for now */
 	if ((ret = pwrite(fd, buffer, size, poffset)) == -1) {
 	    sprintf(Errormsg, "%s/%d pwrite(%d, buf, %d, %lld) ret:-1, errno=%d %s",
 		    __FILE__, __LINE__,
-		fd, size, poffset, errno, strerror(errno));
+							fd, size, (long long)poffset, errno, strerror(errno));
 	    return -errno;
 	}
 
@@ -942,7 +964,7 @@ long wrd;	/* to allow future features, use zero for now */
             sprintf(Errormsg,
 		"%s/%d pwrite(%d, buf, %d, %lld) returned=%d",
 		    __FILE__, __LINE__,
-		    fd, size, poffset, ret);
+							fd, size, (long long)poffset, ret);
         }
         else if ( Debug_level > 1 )
             printf("DEBUG %s/%d: pwrite completed without error (ret %d)\n",
@@ -963,7 +985,7 @@ long wrd;	/* to allow future features, use zero for now */
 #ifdef CRAY
     ret=lio_wait4asyncio(method, fd, statptr);
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
     ret=lio_wait4asyncio(method, fd, &aiocbp);
 #endif
 
@@ -994,7 +1016,7 @@ long wrd;	/* to allow future features, use zero for now */
 #ifdef CRAY
     ret=lio_check_asyncio(io_type, size, &status);
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
     ret=lio_check_asyncio(io_type, size, &aiocbp, method);
 #endif
 
@@ -1053,10 +1075,8 @@ long wrd;	/* to allow future features, use zero for now */
 {
     int ret = 0;	/* syscall return or used to get random method */
     char *io_type;		/* Holds string of type of io */
-#ifndef __linux__
     int listio_cmd;		/* Holds the listio/lio_listio cmd */
     int omethod = method;
-#endif
 #ifdef  CRAY
     struct listreq request;	/* Used when a listio is wanted */
     struct iosw status, *statptr[1];  
@@ -1069,6 +1089,11 @@ long wrd;	/* to allow future features, use zero for now */
     aiocb_t *aiolist[1]; /* list of aio control blocks for lio_listio */
     off64_t poffset;	/* pread(2) offset */
 #endif
+#ifdef __linux__
+	struct aiocb aiocbp;	/* POSIX aio control block */
+	struct aiocb *aiolist[1]; /* list of aio control blocks for lio_listio */
+	off64_t poffset;	/* pread(2) offset */
+#endif
 
     /*
      * If LIO_RANDOM bit specified, get new method randomly.
@@ -1085,7 +1110,7 @@ long wrd;	/* to allow future features, use zero for now */
 	*errmsg = Errormsg;
 
     Rec_signal=Received_signal;	/* get the current number of signals received */
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
     Rec_callback=Received_callback;	/* get the current number of callbacks received */
 #endif
 
@@ -1099,16 +1124,25 @@ long wrd;	/* to allow future features, use zero for now */
     iov.iov_base = buffer;
     iov.iov_len = size;
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
+#if defined(sgi)
     memset(&aiocbp, 0x00, sizeof(aiocb_t));
+#else
+	memset(&aiocbp, 0x00, sizeof(struct aiocb));
+#endif
     aiocbp.aio_fildes = fd;
     aiocbp.aio_nbytes = size;
     aiocbp.aio_buf = buffer;
 /*    aiocbp.aio_offset = lseek( fd, 0, SEEK_CUR ); -- set below */
     aiocbp.aio_sigevent.sigev_notify = SIGEV_NONE;
     aiocbp.aio_sigevent.sigev_signo = 0;
+#ifdef sgi
     aiocbp.aio_sigevent.sigev_func = NULL;
     aiocbp.aio_sigevent.sigev_value.sival_int = 0;
+#elif defined(__linux__)
+	aiocbp.aio_sigevent.sigev_notify_function = NULL;
+	aiocbp.aio_sigevent.sigev_notify_attributes = 0;
+#endif
     aiolist[0] = &aiocbp;
 
     if( (ret = lseek( fd, 0, SEEK_CUR )) == -1 ){
@@ -1139,7 +1173,9 @@ long wrd;	/* to allow future features, use zero for now */
 		return -errno;
 	}
     }
+#if defined(sgi) || defined(__linux__)
     poffset = (off64_t)ret;
+#endif
     aiocbp.aio_offset = ret;
 
 #endif
@@ -1156,7 +1192,7 @@ long wrd;	/* to allow future features, use zero for now */
         sig=0;  /* ignore signal parameter */
     }
 
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
     if ( sig && (method & LIO_WAIT_CBTYPES) )
 	sig=0; /* ignore signal parameter */
 #endif
@@ -1173,13 +1209,13 @@ long wrd;	/* to allow future features, use zero for now */
 #ifdef CRAY
 	    sigctl(SCTL_REG, sig, lio_async_signal_handler);
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
 	    aiocbp.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
 	    aiocbp.aio_sigevent.sigev_signo = sig;
 	    sigset(sig, lio_async_signal_handler);
 #endif /* CRAY */
     }
-#ifdef sgi
+#if defined(sgi)
     else if( method & LIO_WAIT_CBTYPES ){
 	    aiocbp.aio_sigevent.sigev_notify = SIGEV_CALLBACK;
 	    aiocbp.aio_sigevent.sigev_func = lio_async_callback_handler;
@@ -1189,6 +1225,16 @@ long wrd;	/* to allow future features, use zero for now */
 	    aiocbp.aio_sigevent.sigev_value.sival_int = size;
     }
 #endif
+#if defined(__linux__)
+	else if( method & LIO_WAIT_CBTYPES ){
+		aiocbp.aio_sigevent.sigev_notify = SIGEV_THREAD;
+		aiocbp.aio_sigevent.sigev_notify_function = lio_async_callback_handler;
+		/* sival_int just has to be something that I can use
+		 * to identify the callback, and "size" happens to be handy...
+		 */
+		aiocbp.aio_sigevent.sigev_notify_attributes = (void*)size;
+	}
+#endif
 
     /*
      * Determine the system call that will be called and produce
@@ -1199,7 +1245,7 @@ long wrd;	/* to allow future features, use zero for now */
      * bytes written/read.
      */
      
-    if ( (method & LIO_IO_SYNC) || (method & LIO_IO_TYPES) == 0 ){
+	if ( (method & LIO_IO_SYNC) || (method & (LIO_IO_TYPES | LIO_IO_ATYPES)) == 0 ){
 	/*
 	 * read(2) is used if LIO_IO_SYNC bit is set or not none
          * of the LIO_IO_TYPES bits are set (default).
@@ -1254,7 +1300,7 @@ long wrd;	/* to allow future features, use zero for now */
 	    return -errno;
 	}
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
 	sprintf(Lio_SysCall,
 	    "aio_read(fildes=%d, buf, nbytes=%d, signo=%d)", fd, size, sig);
 	io_type="aio_read";
@@ -1316,7 +1362,7 @@ long wrd;	/* to allow future features, use zero for now */
 	ret=lio_check_asyncio(io_type, size,  &status);
 	return ret;
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
 	aiocbp.aio_lio_opcode = LIO_READ;
 	listio_cmd=LIO_WAIT;
 	io_type="lio_listio(3) sync read";
@@ -1381,7 +1427,7 @@ long wrd;	/* to allow future features, use zero for now */
             return -errno;
         }
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
 	aiocbp.aio_lio_opcode = LIO_READ;
 	listio_cmd=LIO_NOWAIT;
 	io_type="lio_listio(3) async read";
@@ -1438,12 +1484,12 @@ long wrd;	/* to allow future features, use zero for now */
     } /* LIO_IO_SYNCV */
 #endif
 
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
     else if ( method & LIO_IO_SYNCP ) {
 	io_type="pread(2)";
 
 	sprintf(Lio_SysCall, 
-		"pread(%d, buf, %d, %lld)", fd, size, poffset);
+						"pread(%d, buf, %d, %lld)", fd, size, (long long)poffset);
 
         if ( Debug_level ) {
 	    printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__, Lio_SysCall);
@@ -1451,7 +1497,7 @@ long wrd;	/* to allow future features, use zero for now */
 	if ((ret = pread(fd, buffer, size, poffset)) == -1) {
 	    sprintf(Errormsg, "%s/%d pread(%d, buf, %d, %lld) ret:-1, errno=%d %s",
 		    __FILE__, __LINE__,
-		fd, size, poffset, errno, strerror(errno));
+							fd, size, (long long)poffset, errno, strerror(errno));
 	    return -errno;
 	}
 
@@ -1459,7 +1505,7 @@ long wrd;	/* to allow future features, use zero for now */
             sprintf(Errormsg,
 		"%s/%d pread(%d, buf, %d, %lld) returned=%d",
 		    __FILE__, __LINE__,
-		    fd, size, poffset, ret);
+							fd, size, (long long)poffset, ret);
         }
         else if ( Debug_level > 1 )
             printf("DEBUG %s/%d: pread completed without error (ret %d)\n",
@@ -1481,7 +1527,7 @@ long wrd;	/* to allow future features, use zero for now */
 #ifdef CRAY
     ret=lio_wait4asyncio(method, fd, statptr);
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
     ret=lio_wait4asyncio(method, fd, &aiocbp);
 #endif
 
@@ -1512,7 +1558,7 @@ long wrd;	/* to allow future features, use zero for now */
 #ifdef CRAY
     ret=lio_check_asyncio(io_type, size, &status);
 #endif
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
     ret=lio_check_asyncio(io_type, size, &aiocbp, method);
 #endif
 
@@ -1520,7 +1566,7 @@ long wrd;	/* to allow future features, use zero for now */
 }	/* end of lio_read_buffer */
 
 
-#if !defined(__linux__) && !defined(__sun) && !defined(__hpux) && !defined(_AIX)
+#if !defined(__sun) && !defined(__hpux) && !defined(_AIX)
 /***********************************************************************
  * This function will check that async io was successful.
  * It can also be used to check sync listio since it uses the
@@ -1535,8 +1581,10 @@ long wrd;	/* to allow future features, use zero for now */
 int
 #ifdef CRAY
 lio_check_asyncio(char *io_type, int size, struct iosw *status)
-#else
-lio_check_asyncio(char *io_type, int size, aiocb_t *aiocbp, int method)
+#elif defined(sgi)
+	lio_check_asyncio(char *io_type, int size, aiocb_t *aiocbp, int method)
+#elif defined(__linux__)
+	lio_check_asyncio(char *io_type, int size, struct aiocb *aiocbp, int method)
 #endif
 {
     int ret;
@@ -1653,8 +1701,10 @@ lio_check_asyncio(char *io_type, int size, aiocb_t *aiocbp, int method)
 int
 #ifdef CRAY
 lio_wait4asyncio(int method, int fd, struct iosw **statptr)
-#else
-lio_wait4asyncio(int method, int fd, aiocb_t *aiocbp)
+#elif defined(sgi)
+	lio_wait4asyncio(int method, int fd, aiocb_t *aiocbp)
+#elif defined(__linux__)
+	lio_wait4asyncio(int method, int fd, struct aiocb *aiocbp)
 #endif
 {
     int cnt;
@@ -1662,9 +1712,13 @@ lio_wait4asyncio(int method, int fd, aiocb_t *aiocbp)
     int ret;
     const aiocb_t *aioary[1]; 
 #endif
+#ifdef __linux__
+	int ret;
+	const struct aiocb *aioary[1];
+#endif
 
     if ( (method & LIO_WAIT_RECALL)
-#ifdef sgi
+#if defined(sgi) || defined(__linux__)
 	|| (method & LIO_WAIT_CBSUSPEND) 
 	|| (method & LIO_WAIT_SIGSUSPEND) 
 #endif
diff --git a/testcases/commands/eject/Makefile b/testcases/commands/eject/Makefile
index af7b0af..1125c67 100644
--- a/testcases/commands/eject/Makefile
+++ b/testcases/commands/eject/Makefile
@@ -1,5 +1,5 @@
 CFLAGS+=    -I../../../include -Wall
-LOADLIBES+= -L../../../lib -lltp
+LOADLIBES+= -L../../../lib
 
 SRCS=$(wildcard *.c)
 TARGETS=$(patsubst %.c,%,$(SRCS))
diff --git a/testcases/kernel/fs/doio/Makefile b/testcases/kernel/fs/doio/Makefile
index 0e56337..c067fff 100644
--- a/testcases/kernel/fs/doio/Makefile
+++ b/testcases/kernel/fs/doio/Makefile
@@ -1,6 +1,6 @@
 
 CFLAGS+= -Wall -I../../../../include -D_LARGEFILE64_SOURCE
-LDLIBS+= -L../../../../lib -lltp
+LDLIBS+= -L../../../../lib -lltp -laio -lrt
 
 TARGETS=doio growfiles rwtest iogen
 SRCS=$(wildcard *.c)
diff --git a/testcases/kernel/ipc/pipeio/Makefile b/testcases/kernel/ipc/pipeio/Makefile
index 2140438..2bc6d92 100644
--- a/testcases/kernel/ipc/pipeio/Makefile
+++ b/testcases/kernel/ipc/pipeio/Makefile
@@ -22,7 +22,7 @@
 ###########################################################################
 CFLAGS   += -Wall
 CPPFLAGS += -I../../../../include
-LDLIBS   += -L../../../../lib -lltp
+LDLIBS   += -L../../../../lib -lltp -lrt -laio
 
 SRCS=$(wildcard *.c)
 TARGETS=$(patsubst %.c,%,$(SRCS))
-- 
1.6.0.2

Signed-off-by: Jiri Palecek <jpalecek@web.de>
