diff mbox series

[9/9] Fix other posix_memalign() alignment issues

Message ID 162194968922.4011860.12953203511925579729.stgit@warthog.procyon.org.uk (mailing list archive)
State New, archived
Headers show
Series Add support for using xfstests to test AFS | expand

Commit Message

David Howells May 25, 2021, 1:34 p.m. UTC
Fix the passing of an alignment that's less than sizeof(long) to
posix_memalign() in some other places by making sure the minimum is used
(AFS has a DIO alignment of 1).

Note that I haven't altered randholes.c as that has an explicit check for a
small alignment and gives an error in such a case.  Possibly this should
just round it up to sizeof(long) instead.

Another alternative is that rather than using posix_memalign() is to
allocate a buffer big enough that the base pointer we're going to actually
use can be cranked forward to the appropriate alignment.

Signed-off-by: David Howells <dhowells@redhat.com>
---

 src/aio-dio-regress/aiocp.c          |    2 ++
 src/aio-dio-regress/aiodio_sparse2.c |    3 ++-
 src/dio-interleaved.c                |    5 ++++-
 3 files changed, 8 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/aio-dio-regress/aiocp.c b/src/aio-dio-regress/aiocp.c
index 7e71cc5c..880c49d2 100644
--- a/src/aio-dio-regress/aiocp.c
+++ b/src/aio-dio-regress/aiocp.c
@@ -81,6 +81,8 @@  int init_iocb(int n, int iosize)
 	for (i = 0; i < n; i++) {
 		if (!(iocb_free[i] = (struct iocb *) malloc(sizeof(struct iocb))))
 			return -1;
+		if (alignment < sizeof(long))
+			alignment = sizeof(long);
 		if (posix_memalign(&buf, alignment, iosize))
 			return -1;
 		if (debug > 1) {
diff --git a/src/aio-dio-regress/aiodio_sparse2.c b/src/aio-dio-regress/aiodio_sparse2.c
index 51ede5bb..57350e22 100644
--- a/src/aio-dio-regress/aiodio_sparse2.c
+++ b/src/aio-dio-regress/aiodio_sparse2.c
@@ -115,9 +115,10 @@  void aiodio_sparse(char *filename, int align, int writesize, int startoffset, in
 	 */
 	offset = startoffset;
 	for (i = 0; i < num_aio; i++) {
+		unsigned int mem_align = (align >= sizeof(long) ? align : sizeof(long));
 		void *bufptr;
 
-		w = posix_memalign(&bufptr, align, writesize);
+		w = posix_memalign(&bufptr, mem_align, writesize);
 		if (w) {
 			fprintf(stderr, "cannot malloc aligned memory: %s\n",
 				strerror(w));
diff --git a/src/dio-interleaved.c b/src/dio-interleaved.c
index 6b04c993..0fa74d3e 100644
--- a/src/dio-interleaved.c
+++ b/src/dio-interleaved.c
@@ -24,11 +24,14 @@  struct dio_thread_data {
 static void *dio_thread(void *arg)
 {
 	struct dio_thread_data *data = arg;
+	unsigned long mem_align;
 	off_t off;
 	ssize_t ret;
 	void *buf;
 
-	if ((errno = posix_memalign(&buf, extent_size / 2, extent_size / 2))) {
+	mem_align = extent_size / 2;
+	mem_align = (mem_align >= sizeof(long) ? mem_align : sizeof(long));
+	if ((errno = posix_memalign(&buf, mem_align, extent_size / 2))) {
 		perror("malloc");
 		return NULL;
 	}