All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: fstests@vger.kernel.org
Cc: dhowells@redhat.com, linux-afs@lists.infradead.org
Subject: [PATCH 9/9] Fix other posix_memalign() alignment issues
Date: Tue, 25 May 2021 14:34:49 +0100	[thread overview]
Message-ID: <162194968922.4011860.12953203511925579729.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <162194962878.4011860.5561077785368723619.stgit@warthog.procyon.org.uk>

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 --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;
 	}



      parent reply	other threads:[~2021-05-25 13:35 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-25 13:33 [PATCH 0/9] Add support for using xfstests to test AFS David Howells
2021-05-25 13:33 ` [PATCH 1/9] Add AFS support David Howells
2021-05-25 13:34 ` [PATCH 2/9] generic/294, afs: Allow for mknod subtest failing if mknod not supported David Howells
2021-05-25 16:09   ` Darrick J. Wong
2021-05-25 16:19   ` David Howells
2021-05-25 16:26     ` Darrick J. Wong
2021-05-30 12:49   ` Eryu Guan
2021-06-01 14:31   ` David Howells
2021-06-06 11:58     ` Eryu Guan
2021-05-25 13:34 ` [PATCH 3/9] generic/314, afs: Allow for a filesystem that doesn't honour SGID inheritance David Howells
2021-05-25 16:10   ` Darrick J. Wong
2021-05-25 13:34 ` [PATCH 4/9] generic/317, afs: Allow for a filesystem not to honour the local uid/gid David Howells
2021-05-25 16:17   ` Darrick J. Wong
2021-05-25 16:41   ` David Howells
2021-05-25 13:34 ` [PATCH 5/9] generic/123, generic/128, afs: Allow for an fs that does its own perm management David Howells
2021-05-25 16:19   ` Darrick J. Wong
2021-05-25 16:44   ` David Howells
2021-05-25 16:51     ` Darrick J. Wong
2021-05-25 13:34 ` [PATCH 6/9] Add the ability to require O_TMPFILE to be supported for a test David Howells
2021-05-25 16:19   ` Darrick J. Wong
2021-05-30 12:54   ` Eryu Guan
2021-05-25 13:34 ` [PATCH 7/9] afs: Indicate the minimum DIO alignment is 1 David Howells
2021-05-25 13:34 ` [PATCH 8/9] generic/465: Fix handling of DIO alignment < sizeof(long) David Howells
2021-05-25 16:25   ` Darrick J. Wong
2021-05-25 16:46   ` David Howells
2021-05-25 13:34 ` David Howells [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=162194968922.4011860.12953203511925579729.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=fstests@vger.kernel.org \
    --cc=linux-afs@lists.infradead.org \
    --subject='Re: [PATCH 9/9] Fix other posix_memalign() alignment issues' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.