src/Makefile | 5 ++--
src/diskio.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/main.c | 2 +
3 files changed, 69 insertions(+), 3 deletions(-)
New commits:
commit 0096325c6f7fa1d32bc11d2a8608d747f87f8312
Author: David Teigland <teigland(a)redhat.com>
Date: Tue May 10 15:06:53 2011 -0500
sanlock: use native linux aio
instead of posix aio
diff --git a/src/Makefile b/src/Makefile
index b3c3ade..cade592 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -63,9 +63,10 @@ CFLAGS += -D_GNU_SOURCE -g \
-Wp,-D_FORTIFY_SOURCE=2 \
-fexceptions \
-fasynchronous-unwind-tables \
- -fdiagnostics-show-option
+ -fdiagnostics-show-option \
+ -DLINUX_AIO
-CMD_LDFLAGS = -lpthread -lrt -lblkid -lsanlock -lwdmd
+CMD_LDFLAGS = -lpthread -laio -lblkid -lsanlock -lwdmd
all: $(SHLIB_TARGET) $(CMD_TARGET) $(SHLIB2_TARGET)
diff --git a/src/diskio.c b/src/diskio.c
index fe55a6b..9ca4abd 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -21,9 +21,14 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
-#include <aio.h>
#include <blkid/blkid.h>
+#ifdef LINUX_AIO
+#include <libaio.h>
+#else /* POSIX_AIO */
+#include <aio.h>
+#endif
+
#include "sanlock_internal.h"
#include "diskio.h"
#include "log.h"
@@ -209,6 +214,63 @@ static int do_read(int fd, uint64_t offset, char *buf, int len)
return 0;
}
+#ifdef LINUX_AIO
+static int do_linux_aio(int fd, uint64_t offset, char *buf, int len,
+ int io_timeout_seconds, int cmd)
+{
+ io_context_t ctx;
+ struct io_event event;
+ struct timespec ts;
+ struct iocb cb;
+ struct iocb *p_cb;
+ int rv;
+
+ memset(&ctx, 0, sizeof(ctx));
+ rv = io_setup(1, &ctx);
+ if (rv < 0)
+ return rv;
+
+ memset(&cb, 0, sizeof(cb));
+ p_cb = &cb;
+
+ cb.aio_fildes = fd;
+ cb.aio_lio_opcode = cmd;
+ cb.u.c.buf = buf;
+ cb.u.c.nbytes = len;
+ cb.u.c.offset = offset;
+
+ rv = io_submit(ctx, 1, &p_cb);
+ if (rv < 0)
+ goto out;
+
+ memset(&event, 0, sizeof(event));
+
+ memset(&ts, 0, sizeof(struct timespec));
+ ts.tv_sec = io_timeout_seconds;
+
+ rv = io_getevents(ctx, 1, 1, &event, &ts);
+ if (rv == 1) {
+ rv = 0;
+ goto out;
+ }
+ rv = -EIO;
+ out:
+ io_destroy(ctx);
+ return rv;
+}
+
+static int do_write_aio(int fd, uint64_t offset, char *buf, int len,
+ int io_timeout_seconds)
+{
+ return do_linux_aio(fd, offset, buf, len, io_timeout_seconds, IO_CMD_PWRITE);
+}
+static int do_read_aio(int fd, uint64_t offset, char *buf, int len,
+ int io_timeout_seconds)
+{
+ return do_linux_aio(fd, offset, buf, len, io_timeout_seconds, IO_CMD_PREAD);
+}
+
+#else
static int do_write_aio(int fd, uint64_t offset, char *buf, int len,
int io_timeout_seconds)
{
@@ -306,6 +368,7 @@ static int do_read_aio(int fd, uint64_t offset, char *buf, int len,
int io_timeo
/* undefined error condition */
return -1;
}
+#endif
/* write aligned io buffer */
diff --git a/src/main.c b/src/main.c
index 911379a..b6cd451 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2564,6 +2564,8 @@ static int read_command_line(int argc, char *argv[])
/* the only action that has an option without dash-letter prefix */
if (com.action == ACT_DUMP) {
+ if (argc < 4)
+ exit(EXIT_FAILURE);
optionarg = argv[i++];
com.dump_path = strdup(optionarg);
}