[PATCH] Update to libaio?

Rusty Russell rusty at rustcorp.com.au
Thu Jan 3 08:09:38 UTC 2008


I recently tried to use libaio (0.3.106), and discovered it didn't have
eventfd support.  Or preadv/pwritev support.  And the testsuite didn't
compile.  Or work.

Anyway, it's shipped by the distros, so I figure it's worth patching.
I'm cc'ing Ben in the hope he's still maintaining it.  If not I'll
find a home somewhere for it.

Cheers,
Rusty.

diff -ur libaio-0.3.106/ChangeLog libaio-0.3.106-aio_abi/ChangeLog
--- libaio-0.3.106/ChangeLog	2002-10-01 08:09:56.000000000 +1000
+++ libaio-0.3.106-aio_abi/ChangeLog	2008-01-03 17:48:48.000000000 +1100
@@ -1,3 +1,14 @@
+rusty-v1
+	- Make tests compile again on modern systems (warnings + -Werror)
+	- Add 'make partcheck' and don't require manual setup for testing.
+	- Change test harness to compile against this dir, not global install
+	- Fix 5.t for archs where PROT_WRITE mappings are readable.
+	- Allow sending of SIGXFSZ on aio over limits
+	- Explicitly specify bash for runtests.sh
+	- Remove (never-merged?) io_prep_poll
+	- Add io_prep_preadv and io_prep_pwritev
+	- Add eventfd support (io_set_eventfd).
+
 0.4.0
 	- remove libredhat-kernel
 	- add rough outline for man pages
diff -ur libaio-0.3.106/harness/cases/5.t libaio-0.3.106-aio_abi/harness/cases/5.t
--- libaio-0.3.106/harness/cases/5.t	2002-04-20 10:26:22.000000000 +1000
+++ libaio-0.3.106-aio_abi/harness/cases/5.t	2008-01-03 16:29:37.000000000 +1100
@@ -3,6 +3,7 @@
 */
 #include "aio_setup.h"
 #include <sys/mman.h>
+#include <errno.h>
 
 int test_main(void)
 {
@@ -40,7 +41,13 @@
 	assert(buf != (char *)-1);
 
 	status |= attempt_rw(rwfd, buf, SIZE,  0,  READ, SIZE);
-	status |= attempt_rw(rwfd, buf, SIZE,  0, WRITE, -EFAULT);
+
+	/* Whether PROT_WRITE is readable is arch-dependent.  So compare
+	 * against pread result. */
+	res = write(rwfd, buf, SIZE);
+	if (res < 0)
+		res = -errno;
+	status |= attempt_rw(rwfd, buf, SIZE,  0, WRITE, res);
 
 	return status;
 }
diff -ur libaio-0.3.106/harness/cases/7.t libaio-0.3.106-aio_abi/harness/cases/7.t
--- libaio-0.3.106/harness/cases/7.t	2002-04-20 10:26:22.000000000 +1000
+++ libaio-0.3.106-aio_abi/harness/cases/7.t	2008-01-03 17:46:11.000000000 +1100
@@ -9,12 +9,15 @@
 */
 
 #include <sys/resource.h>
+#include <signal.h>
 
 void SET_RLIMIT(long long limit)
 {
 	struct rlimit rlim;
 	int res;
 
+	/* Seems that we do send SIGXFSZ, but hard to fix... */
+	signal(SIGXFSZ, SIG_IGN);
 	rlim.rlim_cur = limit;			assert(rlim.rlim_cur == limit);
 	rlim.rlim_max = limit;			assert(rlim.rlim_max == limit);
 
diff -ur libaio-0.3.106/harness/cases/8.t libaio-0.3.106-aio_abi/harness/cases/8.t
--- libaio-0.3.106/harness/cases/8.t	2008-01-03 15:13:05.000000000 +1100
+++ libaio-0.3.106-aio_abi/harness/cases/8.t	2008-01-03 18:47:23.000000000 +1100
@@ -2,44 +2,23 @@
 - Ditto for the above three tests at the offset maximum (largest
   possible ext2/3 file size.) (8.t)
  */
-#include <sys/vfs.h>
-
-#define EXT2_OLD_SUPER_MAGIC	0xEF51
-#define EXT2_SUPER_MAGIC	0xEF53
+#include <sys/types.h>
+#include <unistd.h>
 
 long long get_fs_limit(int fd)
 {
-	struct statfs s;
-	int res;
-	long long lim = 0;
-
-	res = fstatfs(fd, &s);		assert(res == 0);
+	long long min = 0, max = 100000000000000ULL;
+	char c = 0;
 
-	switch(s.f_type) {
-	case EXT2_OLD_SUPER_MAGIC:
-	case EXT2_SUPER_MAGIC:
-#if 0
-	{
-		long long tmp;
-		tmp = s.f_bsize / 4;
-		/* 12 direct + indirect block + dind + tind */
-		lim = 12 + tmp + tmp * tmp + tmp * tmp * tmp;
-		lim *= s.f_bsize;
-		printf("limit(%ld) = %Ld\n", (long)s.f_bsize, lim);
-	}
-#endif
-		switch(s.f_bsize) {
-		case 4096: lim = 2199023251456ULL; break;
-		default:
-			printf("unknown ext2 blocksize %ld\n", (long)s.f_bsize);
-			exit(3);
+	while (max - min > 1) {
+		if (pwrite64(fd, &c, 1, (min + max) / 2) == -1)
+			max = (min + max) / 2;
+		else {
+			ftruncate(fd, 0);
+			min = (min + max) / 2;
 		}
-		break;
-	default:
-		printf("unknown filesystem 0x%08lx\n", (long)s.f_type);
-		exit(3);
 	}
-	return lim;
+	return max;
 }
 
 #define SET_RLIMIT(x)	do ; while (0)
diff -ur libaio-0.3.106/harness/cases/common-7-8.h libaio-0.3.106-aio_abi/harness/cases/common-7-8.h
--- libaio-0.3.106/harness/cases/common-7-8.h	2002-04-20 10:26:22.000000000 +1000
+++ libaio-0.3.106-aio_abi/harness/cases/common-7-8.h	2008-01-03 18:36:02.000000000 +1100
@@ -2,6 +2,8 @@
 */
 #include "aio_setup.h"
 
+#define _XOPEN_SOURCE 500
+#include <errno.h>
 #include <unistd.h>
 
 #define SIZE	512
@@ -13,7 +15,7 @@
 	int status = 0, res;
 	long long limit;
 
-	rwfd = open(FILENAME, O_RDWR);		assert(rwfd != -1);
+	rwfd = open(FILENAME, O_RDWR|O_CREAT, 0600);	assert(rwfd != -1);
 	res = ftruncate(rwfd, 0);			assert(res == 0);
 	buf = malloc(SIZE);				assert(buf != NULL);
 	memset(buf, 0, SIZE);
diff -ur libaio-0.3.106/harness/main.c libaio-0.3.106-aio_abi/harness/main.c
--- libaio-0.3.106/harness/main.c	2002-09-14 03:41:10.000000000 +1000
+++ libaio-0.3.106-aio_abi/harness/main.c	2008-01-03 18:40:38.000000000 +1100
@@ -1,3 +1,4 @@
+#define _LARGEFILE64_SOURCE
 #include <stdio.h>
 #include <errno.h>
 #include <assert.h>
diff -ur libaio-0.3.106/harness/Makefile libaio-0.3.106-aio_abi/harness/Makefile
--- libaio-0.3.106/harness/Makefile	2008-01-03 15:13:28.000000000 +1100
+++ libaio-0.3.106-aio_abi/harness/Makefile	2008-01-03 18:17:05.000000000 +1100
@@ -1,38 +1,56 @@
 # foo.
 TEST_SRCS:=$(shell find cases/ -name \*.t | sort -n -t/ -k2)
-PROGS:=$(patsubst %.t,%.p,$(TEST_SRCS))
+EXTRAPROGS:=cases/8.p cases/10.p
+PARTPROGS:=$(filter-out $(EXTRAPROGS), $(patsubst %.t,%.p,$(TEST_SRCS)))
+PROGS:=$(PARTPROGS) $(EXTRAPROGS)
 HARNESS_SRCS:=main.c
 # io_queue.c
 
-#CFLAGS=-Wall -Werror -g -O -laio
-CFLAGS=-Wall -g -O -laio
+CFLAGS=-Wall -I../src -g -O
 #-lpthread -lrt
 
 all: $(PROGS)
 
 $(PROGS): %.p: %.t $(HARNESS_SRCS)
-	$(CC) $(CFLAGS) -DTEST_NAME=\"$<\" -o $@ main.c
+	$(CC) $(CFLAGS) -DTEST_NAME=\"$<\" -o $@ main.c ../src/libaio.a
 
 clean:
 	rm -f $(PROGS) *.o runtests.out rofile wofile rwfile
 
 .PHONY:
 
-testdir/rofile: .PHONY
+testdir/rofile: testdir .PHONY
 	rm -f $@
 	echo "test" >$@
 	chmod 400 $@
 
-testdir/wofile: .PHONY
+testdir/wofile: testdir .PHONY
 	rm -f $@
 	echo "test" >$@
 	chmod 200 $@
 
-testdir/rwfile: .PHONY
+testdir/rwfile: testdir .PHONY
 	rm -f $@
 	echo "test" >$@
 	chmod 600 $@
 
-check: $(PROGS) testdir/rofile testdir/rwfile testdir/wofile
-	./runtests.sh $(PROGS)
+testdir testdir.enospc testdir.ext2:
+	mkdir $@
 
+root: .PHONY
+	@if [ `id -u` -ne 0 ]; then echo Need root for check, try partcheck >&2; exit 1; fi
+
+partcheck: $(PARTPROGS) testdir/rofile testdir/rwfile testdir/wofile
+	./runtests.sh $(PARTPROGS)
+
+ext2.img:
+	dd if=/dev/zero bs=1M count=10 of=$@
+	mke2fs -F -b 4096 $@
+
+extracheck: $(EXTRAPROGS) root testdir.ext2 testdir.enospc ext2.img
+	mount -o loop -t ext2 ext2-enospc.img testdir.enospc
+	./runtests.sh cases/10.p; ret=$$?; umount testdir.enospc; exit $$ret
+	mount -o loop -t ext2 ext2.img testdir.ext2
+	./runtests.sh cases/8.p; ret=$$?; umount testdir.ext2; exit $$ret
+
+check: partcheck extracheck 
diff -ur libaio-0.3.106/harness/runtests.sh libaio-0.3.106-aio_abi/harness/runtests.sh
--- libaio-0.3.106/harness/runtests.sh	2002-04-20 10:26:22.000000000 +1000
+++ libaio-0.3.106-aio_abi/harness/runtests.sh	2008-01-03 15:06:36.000000000 +1100
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 passes=0
 fails=0
diff -ur libaio-0.3.106/Makefile libaio-0.3.106-aio_abi/Makefile
--- libaio-0.3.106/Makefile	2004-02-27 02:25:10.000000000 +1100
+++ libaio-0.3.106-aio_abi/Makefile	2008-01-03 16:17:13.000000000 +1100
@@ -17,6 +17,11 @@
 install:
 	@$(MAKE) -C src install prefix=$(prefix) includedir=$(includedir) libdir=$(libdir)
 
+check:
+	@$(MAKE) -C harness check
+
+partcheck: all
+	@$(MAKE) -C harness partcheck
 
 clean:
 	@$(MAKE) -C src clean
diff -ur libaio-0.3.106/src/libaio.h libaio-0.3.106-aio_abi/src/libaio.h
--- libaio-0.3.106/src/libaio.h	2005-04-02 06:31:32.000000000 +1000
+++ libaio-0.3.106-aio_abi/src/libaio.h	2008-01-03 16:14:59.000000000 +1100
@@ -33,7 +33,6 @@
 struct timespec;
 struct sockaddr;
 struct iovec;
-struct iocb;
 
 typedef struct io_context *io_context_t;
 
@@ -44,8 +43,9 @@
 	IO_CMD_FSYNC = 2,
 	IO_CMD_FDSYNC = 3,
 
-	IO_CMD_POLL = 5,
 	IO_CMD_NOOP = 6,
+	IO_CMD_PREADV = 7,
+	IO_CMD_PWRITEV = 8,
 } io_iocb_cmd_t;
 
 #if defined(__i386__) /* little endian, 32 bits */
@@ -89,7 +89,9 @@
 	PADDEDptr(void	*buf, __pad1);
 	PADDEDul(nbytes, __pad2);
 	long long	offset;
-	long long	__pad3, __pad4;
+	long long	__pad3;
+	unsigned	flags;
+	unsigned	resfd;
 };	/* result code is the amount read or -'ve errno */
 
 struct io_iocb_vector {
@@ -169,20 +171,26 @@
 	iocb->u.c.offset = offset;
 }
 
-static inline void io_prep_poll(struct iocb *iocb, int fd, int events)
+static inline void io_prep_preadv(struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt, long long offset)
 {
 	memset(iocb, 0, sizeof(*iocb));
 	iocb->aio_fildes = fd;
-	iocb->aio_lio_opcode = IO_CMD_POLL;
+	iocb->aio_lio_opcode = IO_CMD_PREADV;
 	iocb->aio_reqprio = 0;
-	iocb->u.poll.events = events;
+	iocb->u.c.buf = (void *)iov;
+	iocb->u.c.nbytes = iovcnt;
+	iocb->u.c.offset = offset;
 }
 
-static inline int io_poll(io_context_t ctx, struct iocb *iocb, io_callback_t cb, int fd, int events)
+static inline void io_prep_pwritev(struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt, long long offset)
 {
-	io_prep_poll(iocb, fd, events);
-	io_set_callback(iocb, cb);
-	return io_submit(ctx, 1, &iocb);
+	memset(iocb, 0, sizeof(*iocb));
+	iocb->aio_fildes = fd;
+	iocb->aio_lio_opcode = IO_CMD_PWRITEV;
+	iocb->aio_reqprio = 0;
+	iocb->u.c.buf = (void *)iov;
+	iocb->u.c.nbytes = iovcnt;
+	iocb->u.c.offset = offset;
 }
 
 static inline void io_prep_fsync(struct iocb *iocb, int fd)
@@ -215,6 +223,12 @@
 	return io_submit(ctx, 1, &iocb);
 }
 
+static inline void io_set_eventfd(struct iocb *iocb, int eventfd)
+{
+	iocb->u.c.flags |= (1 << 0) /* IOCB_FLAG_RESFD */;
+	iocb->u.c.resfd = eventfd;
+}
+
 #ifdef __cplusplus
 }
 #endif




More information about the Ubuntu-devel-discuss mailing list