public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfstests: posix_memalign and io_submit do not set errno
@ 2013-11-07 17:00 Christoph Hellwig
  2013-11-07 17:53 ` Mark Tinguely
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christoph Hellwig @ 2013-11-07 17:00 UTC (permalink / raw)
  To: xfs

posix_memalign and io_submit do not set errno, but rather return the
error respectively the negated error directly.

Found this out while figuring out why 240 reported an impossible error
from io_submit when run on NFS.


Signed-off-by: Christoph Hellwig <hch@lst.de>

diff --git a/src/aio-dio-regress/aiodio_sparse2.c b/src/aio-dio-regress/aiodio_sparse2.c
index 79aa924..51ede5b 100644
--- a/src/aio-dio-regress/aiodio_sparse2.c
+++ b/src/aio-dio-regress/aiodio_sparse2.c
@@ -117,8 +117,10 @@ void aiodio_sparse(char *filename, int align, int writesize, int startoffset, in
 	for (i = 0; i < num_aio; i++) {
 		void *bufptr;
 
-		if (posix_memalign(&bufptr, align, writesize)) {
-			perror("cannot malloc aligned memory");
+		w = posix_memalign(&bufptr, align, writesize);
+		if (w) {
+			fprintf(stderr, "cannot malloc aligned memory: %s\n",
+				strerror(w));
 			close(fd);
 			unlink(filename);
 			return;
@@ -131,8 +133,10 @@ void aiodio_sparse(char *filename, int align, int writesize, int startoffset, in
 	/*
 	 * start the 1st num_aio write requests
 	 */
-	if ((w = io_submit(myctx, num_aio, iocbs)) < 0) {
-		perror("io_submit failed");
+	w = io_submit(myctx, num_aio, iocbs);
+	if (w < 0) {
+		fprintf(stderr, "io_submit failed: %s\n",
+			strerror(-w));
 		close(fd);
 		unlink(filename);
 		return;
@@ -182,10 +186,11 @@ void aiodio_sparse(char *filename, int align, int writesize, int startoffset, in
 		/* start next write */
 		io_prep_pwrite(iocbp, fd, iocbp->u.c.buf, writesize, offset);
 		offset += step;
-		if ((w = io_submit(myctx, 1, &iocbp)) < 0) {
-			fprintf(stderr, "io_submit failed at offset %lld\n",
-				(long long)offset);
-			perror("");
+		w = io_submit(myctx, 1, &iocbp);
+		if (w < 0) {
+			fprintf(stderr, "io_submit failed at offset %lld: %s\n",
+				(long long)offset,
+				strerror(-w));
 			break;
 		}
 		if (debug)
@@ -200,8 +205,10 @@ void aiodio_sparse(char *filename, int align, int writesize, int startoffset, in
 		int n;
 		struct iocb *iocbp;
 
-		if ((n = io_getevents(myctx, 1, 1, &event, 0)) != 1) {
-			perror("io_getevents failed");
+		n = io_getevents(myctx, 1, 1, &event, 0);
+		if (n != 1) {
+			fprintf(stderr, "io_getevents failed: %s\n",
+				 strerror(-n));
 			break;
 		}
 		aio_inflight--;
diff --git a/src/fsync-tester.c b/src/fsync-tester.c
index 1c03ed0..657e00f 100644
--- a/src/fsync-tester.c
+++ b/src/fsync-tester.c
@@ -437,15 +437,16 @@ int main(int argc, char **argv)
 	if (direct_io) {
 		flags |= O_DIRECT;
 		ret = posix_memalign((void **)&buf, getpagesize(), 4096);
-		if (ret)
-			buf = NULL;
+		if (ret) {
+			fprintf(stderr, "Error allocating buf: %d\n", ret);
+			return 1;
+		}
 	} else {
 		buf = malloc(4096);
-	}
-
-	if (!buf) {
-		fprintf(stderr, "Error allocating buf: %d\n", errno);
-		return 1;
+		if (!buf) {
+			fprintf(stderr, "Error allocating buf: %d\n", errno);
+			return 1;
+		}
 	}
 
 	test_fd = open(fname, flags, 0644);
diff --git a/src/randholes.c b/src/randholes.c
index 545ee8e..5ad602e 100644
--- a/src/randholes.c
+++ b/src/randholes.c
@@ -193,11 +193,13 @@ writeblks(char *fname, int fd, size_t alignment)
 	__uint64_t offset;
 	char *buffer = NULL;
 	int block;
+	int ret;
 	struct flock64 fl;
 
 	if (!test) {
-		if (posix_memalign((void **) &buffer, alignment, blocksize)) {
-			perror("malloc");
+		ret = posix_memalign((void **) &buffer, alignment, blocksize);
+		if (ret) {
+			fprintf(stderr, "posix_memalign: %s\n", strerror(ret));
 			exit(1);
 		}
 		memset(buffer, 0, blocksize);
@@ -279,8 +281,9 @@ readblks(int fd, size_t alignment)
 	if (alloconly)
 		return 0;
 	xfer = READ_XFER*blocksize;
-	if (posix_memalign((void **) &buffer, alignment, xfer)) {
-		perror("malloc");
+	err = posix_memalign((void **) &buffer, alignment, xfer);
+	if (err) {
+		fprintf(stderr, "posix_memalign: %s\n", strerror(err));
 		exit(1);
 	}
 	memset(buffer, 0, xfer);
diff --git a/src/trunc.c b/src/trunc.c
index 38fb21f..c609852 100644
--- a/src/trunc.c
+++ b/src/trunc.c
@@ -69,10 +69,12 @@ while((c=getopt(argc,argv,"f:"))!=EOF) {
 	}
 
 	err = posix_memalign((void **)&buf, ALIGNMENT, BUFSIZE);
-	if (err < 0) perror("posix_memalign failed");
+	if (err)
+		fprintf(stderr, "posix_memalign failed: %s\n", strerror(err));
 
 	err = posix_memalign((void **)&goodbuf, ALIGNMENT, BUFSIZE);
-	if (err < 0) perror("posix_memalign failed");
+	if (err)
+		fprintf(stderr, "posix_memalign failed: %s\n", strerror(err));
 
 	err = unlink(filename);
 /*	if (err < 0) perror("unlink failed");*/

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] xfstests: posix_memalign and io_submit do not set errno
  2013-11-07 17:00 [PATCH] xfstests: posix_memalign and io_submit do not set errno Christoph Hellwig
@ 2013-11-07 17:53 ` Mark Tinguely
  2013-11-07 18:13 ` Carlos Maiolino
  2013-11-10  1:07 ` Rich Johnston
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Tinguely @ 2013-11-07 17:53 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: xfs

On 11/07/13 11:00, Christoph Hellwig wrote:
> posix_memalign and io_submit do not set errno, but rather return the
> error respectively the negated error directly.
>
> Found this out while figuring out why 240 reported an impossible error
> from io_submit when run on NFS.
>
>
> Signed-off-by: Christoph Hellwig<hch@lst.de>
>


Looks like that took care of all the non-conforming posix_memalign and 
io_[submit | cancel | destroy | getevents | setup] calls in xfstests 
sources.

Reviewed-by: Mark Tinguely <tinguely@sgi.com>

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xfstests: posix_memalign and io_submit do not set errno
  2013-11-07 17:00 [PATCH] xfstests: posix_memalign and io_submit do not set errno Christoph Hellwig
  2013-11-07 17:53 ` Mark Tinguely
@ 2013-11-07 18:13 ` Carlos Maiolino
  2013-11-10  1:07 ` Rich Johnston
  2 siblings, 0 replies; 4+ messages in thread
From: Carlos Maiolino @ 2013-11-07 18:13 UTC (permalink / raw)
  To: xfs

Looks good to me, consider it
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>


On Thu, Nov 07, 2013 at 09:00:45AM -0800, Christoph Hellwig wrote:
> posix_memalign and io_submit do not set errno, but rather return the
> error respectively the negated error directly.
> 
> Found this out while figuring out why 240 reported an impossible error
> from io_submit when run on NFS.
> 
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> 

-- 
Carlos

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xfstests: posix_memalign and io_submit do not set errno
  2013-11-07 17:00 [PATCH] xfstests: posix_memalign and io_submit do not set errno Christoph Hellwig
  2013-11-07 17:53 ` Mark Tinguely
  2013-11-07 18:13 ` Carlos Maiolino
@ 2013-11-10  1:07 ` Rich Johnston
  2 siblings, 0 replies; 4+ messages in thread
From: Rich Johnston @ 2013-11-10  1:07 UTC (permalink / raw)
  To: Christoph Hellwig, xfs

This has been committed.

Thanks
--Rich

commit a16f0cfe3ad2f02109f31333703ca6f78ed6127d
Author: Christoph Hellwig <hch@infradead.org>
Date:   Thu Nov 7 17:00:45 2013 +0000

     xfstests: posix_memalign and io_submit do not set errno

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-11-10  1:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-07 17:00 [PATCH] xfstests: posix_memalign and io_submit do not set errno Christoph Hellwig
2013-11-07 17:53 ` Mark Tinguely
2013-11-07 18:13 ` Carlos Maiolino
2013-11-10  1:07 ` Rich Johnston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox