Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Aug 2022 15:03:13 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 187084dddd3e - main - makefs: Align the block buffer used in ZFS mode
Message-ID:  <202208161503.27GF3DsC046676@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=187084dddd3ebbd5853d6abd72aa1ab51b74d826

commit 187084dddd3ebbd5853d6abd72aa1ab51b74d826
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-08-16 14:02:09 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-08-16 15:02:51 +0000

    makefs: Align the block buffer used in ZFS mode
    
    For some dnode types, particularly ZAPs, we want the buffer to have
    uint64_t alignment.
    
    Sponsored by:   The FreeBSD Foundation
---
 usr.sbin/makefs/zfs.c     |  9 ++++++++-
 usr.sbin/makefs/zfs/zfs.h | 10 +++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/usr.sbin/makefs/zfs.c b/usr.sbin/makefs/zfs.c
index 08689a558870..ab6011046b22 100644
--- a/usr.sbin/makefs/zfs.c
+++ b/usr.sbin/makefs/zfs.c
@@ -34,6 +34,7 @@
 
 #include <assert.h>
 #include <fcntl.h>
+#include <stdalign.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdlib.h>
@@ -69,7 +70,13 @@ struct dnode_cursor {
 void
 zfs_prep_opts(fsinfo_t *fsopts)
 {
-	zfs_opt_t *zfs = ecalloc(1, sizeof(*zfs));
+	size_t align;
+
+	align = alignof(uint64_t);
+	zfs_opt_t *zfs = aligned_alloc(align, roundup2(sizeof(*zfs), align));
+	if (zfs == NULL)
+		err(1, "aligned_alloc");
+	memset(zfs, 0, sizeof(*zfs));
 
 	const option_t zfs_options[] = {
 		{ '\0', "bootfs", &zfs->bootfs, OPT_STRPTR,
diff --git a/usr.sbin/makefs/zfs/zfs.h b/usr.sbin/makefs/zfs/zfs.h
index b92e2c035669..7ad3151dd8a2 100644
--- a/usr.sbin/makefs/zfs/zfs.h
+++ b/usr.sbin/makefs/zfs/zfs.h
@@ -35,6 +35,7 @@
 #include <sys/queue.h>
 
 #include <bitstring.h>
+#include <stdalign.h>
 #include <stdbool.h>
 
 #include "makefs.h"
@@ -65,10 +66,13 @@ struct dataset_desc {
 };
 
 typedef struct {
-	bool		nowarn;
+	/*
+	 * Block buffer, needs to be aligned for various on-disk structures,
+	 * ZAPs, etc..
+	 */
+	char		filebuf[MAXBLOCKSIZE] __aligned(alignof(uint64_t));
 
-	/* I/O buffer, just for convenience. */
-	char		filebuf[MAXBLOCKSIZE];
+	bool		nowarn;
 
 	/* Pool parameters. */
 	const char	*poolname;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202208161503.27GF3DsC046676>