[PATCH 3/5] aio-dio-append-write-read-race: abort if we encounter syscall errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Darrick J. Wong <darrick.wong@xxxxxxxxxx>

If any of the library calls return error codes, just print out a message
and abort the test.  Whoever wrote the write test did not check for
write failures, which means that if we ENOSPC without writing anything
then the reader thread will loop forever trying to read.

Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx>
---
 .../aio-dio-append-write-read-race.c               |   41 +++++++++++---------
 1 file changed, 23 insertions(+), 18 deletions(-)


diff --git a/src/aio-dio-regress/aio-dio-append-write-read-race.c b/src/aio-dio-regress/aio-dio-append-write-read-race.c
index 1a78009..b3fbe61 100644
--- a/src/aio-dio-regress/aio-dio-append-write-read-race.c
+++ b/src/aio-dio-regress/aio-dio-append-write-read-race.c
@@ -70,6 +70,11 @@ static void *reader(void *arg)
 	return NULL;
 }
 
+#define fail(fmt , args...) do {	\
+	fprintf(stderr, fmt , ##args);	\
+	exit(1);			\
+} while (0)
+
 static void *writer(struct io_data *data)
 {
 	int ret;
@@ -84,28 +89,28 @@ static void *writer(struct io_data *data)
 		struct iocb *iocbs[] = { &iocb };
 
 		ret = io_setup(1, &ctx);
-		if (ret) {
-			fprintf(stderr, "error %s during io_setup\n",
+		if (ret)
+			fail("error %s during io_setup\n",
 				strerror(ret));
-			return NULL;
-		}
 		io_prep_pwrite(&iocb, data->fd, data->buf, data->blksize, data->offset);
 		ret = io_submit(ctx, 1, iocbs);
-		if (ret != 1) {
-			fprintf(stderr, "error %s during io_submit\n",
+		if (ret != 1)
+			fail("error %s during io_submit\n",
 				strerror(ret));
-			return NULL;
-		}
 		ret = io_getevents(ctx, 1, 1, evs, NULL);
-		if (ret != 1) {
-			fprintf(stderr, "error %s during io_getevents\n",
+		if (ret != 1)
+			fail("error %s during io_getevents\n",
 				strerror(ret));
-			return NULL;
-		}
+		if ((signed)evs[0].res < 0)
+			fail("error %s during write\n",
+				strerror(-evs[0].res));
+		if ((signed)evs[0].res2 < 0)
+			fail("secondary error %s during write\n",
+				strerror(-evs[0].res2));
 	} else {
 		ret = pwrite(data->fd, data->buf, data->blksize, data->offset);
 		if (ret < 0)
-			perror("write file failed");
+			fail("write file failed: %s", strerror(errno));
 	}
 
 	return NULL;
@@ -161,14 +166,14 @@ int main(int argc, char *argv[])
 
 	ret = posix_memalign((void **)&wbuf, io_align, blksize);
 	if (ret) {
-		fprintf(stderr, "failed to alloc memory: %s\n", strerror(ret));
+		fail("failed to alloc memory: %s\n", strerror(ret));
 		ret = 1;
 		goto err;
 	}
 
 	ret = posix_memalign((void **)&rbuf, io_align, blksize);
 	if (ret) {
-		fprintf(stderr, "failed to alloc memory: %s\n", strerror(ret));
+		fail("failed to alloc memory: %s\n", strerror(ret));
 		ret = 1;
 		goto err;
 	}
@@ -189,7 +194,7 @@ int main(int argc, char *argv[])
 		reader_ready = 0;
 		ret = pthread_create(&tid, NULL, reader, &rdata);
 		if (ret) {
-			fprintf(stderr, "create reader thread failed: %s\n",
+			fail("create reader thread failed: %s\n",
 				strerror(ret));
 			ret = 1;
 			goto err;
@@ -199,7 +204,7 @@ int main(int argc, char *argv[])
 
 		ret = pthread_join(tid, NULL);
 		if (ret) {
-			fprintf(stderr, "pthread join reader failed: %s\n",
+			fail("pthread join reader failed: %s\n",
 				strerror(ret));
 			ret = 1;
 			goto err;
@@ -207,7 +212,7 @@ int main(int argc, char *argv[])
 
 		for (j = 0; j < blksize; j++) {
 			if (rdata.buf[j] != 'a') {
-				fprintf(stderr, "encounter an error: "
+				fail("encounter an error: "
 					"block %d offset %d, content %x\n",
 					i, j, rbuf[j]);
 				ret = 1;

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux