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
This commit is contained in:
Mark Johnston 2022-08-16 10:02:09 -04:00
parent e3917bb256
commit 187084dddd
2 changed files with 15 additions and 4 deletions

View File

@ -34,6 +34,7 @@
#include <assert.h> #include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdalign.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
@ -69,7 +70,13 @@ struct dnode_cursor {
void void
zfs_prep_opts(fsinfo_t *fsopts) 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[] = { const option_t zfs_options[] = {
{ '\0', "bootfs", &zfs->bootfs, OPT_STRPTR, { '\0', "bootfs", &zfs->bootfs, OPT_STRPTR,

View File

@ -35,6 +35,7 @@
#include <sys/queue.h> #include <sys/queue.h>
#include <bitstring.h> #include <bitstring.h>
#include <stdalign.h>
#include <stdbool.h> #include <stdbool.h>
#include "makefs.h" #include "makefs.h"
@ -65,10 +66,13 @@ struct dataset_desc {
}; };
typedef struct { 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. */ bool nowarn;
char filebuf[MAXBLOCKSIZE];
/* Pool parameters. */ /* Pool parameters. */
const char *poolname; const char *poolname;