Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions cmd/raidz_test/raidz_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,21 @@ cmp_data(raidz_test_opts_t *opts, raidz_map_t *rm)

static int
init_rand(void *data, size_t size, void *private)
{
size_t *offsetp = (size_t *)private;
size_t offset = *offsetp;

VERIFY3U(offset + size, <=, SPA_MAXBLOCKSIZE);
memcpy(data, (char *)rand_data + offset, size);
*offsetp = offset + size;
return (0);
}

static int
corrupt_rand_fill(void *data, size_t size, void *private)
{
(void) private;
memcpy(data, rand_data, size);
memset(data, 0xAA, size);
return (0);
}

Expand All @@ -279,15 +291,16 @@ corrupt_colums(raidz_map_t *rm, const int *tgts, const int cnt)
for (int i = 0; i < cnt; i++) {
raidz_col_t *col = &rr->rr_col[tgts[i]];
abd_iterate_func(col->rc_abd, 0, col->rc_size,
init_rand, NULL);
corrupt_rand_fill, NULL);
}
}
}

void
init_zio_abd(zio_t *zio)
{
abd_iterate_func(zio->io_abd, 0, zio->io_size, init_rand, NULL);
size_t offset = 0;
abd_iterate_func(zio->io_abd, 0, zio->io_size, init_rand, &offset);
}

static void
Expand Down Expand Up @@ -374,7 +387,7 @@ init_raidz_map(raidz_test_opts_t *opts, zio_t **zio, const int parity)

*zio = umem_zalloc(sizeof (zio_t), UMEM_NOFAIL);

(*zio)->io_offset = 0;
(*zio)->io_offset = opts->rto_offset;
(*zio)->io_size = alloc_dsize;
(*zio)->io_abd = raidz_alloc(alloc_dsize);
init_zio_abd(*zio);
Expand Down Expand Up @@ -835,6 +848,8 @@ main(int argc, char **argv)
err = run_test(NULL);
}

mprotect(rand_data, SPA_MAXBLOCKSIZE, PROT_READ | PROT_WRITE);
Copy link
Member

@robn robn Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right about using mprotect() on memory obtained from libc (technically, wherever umem_alloc() got it from, which is kinda worse maybe?). POSIX explicitly says calling it on a pointer you didn't get from mmap() is unspecified, so.

I don't care for this PR, since we were already doing and your change is an improvement, but if you like we could just use an anonymous mapping:

diff --git a/cmd/raidz_test/raidz_test.c b/cmd/raidz_test/raidz_test.c
index 4839e909e4..eb1d6a562a 100644
--- a/cmd/raidz_test/raidz_test.c
+++ b/cmd/raidz_test/raidz_test.c
@@ -820,7 +820,8 @@ main(int argc, char **argv)
 	kernel_init(SPA_MODE_READ);
 
 	/* setup random data because rand() is not reentrant */
-	rand_data = (int *)umem_alloc(SPA_MAXBLOCKSIZE, UMEM_NOFAIL);
+	rand_data = (int *)mmap(NULL, SPA_MAXBLOCKSIZE, PROT_READ|PROT_WRITE,
+	    MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
 	srand((unsigned)time(NULL) * getpid());
 	for (i = 0; i < SPA_MAXBLOCKSIZE / sizeof (int); i++)
 		rand_data[i] = rand();
@@ -835,7 +836,7 @@ main(int argc, char **argv)
 		err = run_test(NULL);
 	}
 
-	umem_free(rand_data, SPA_MAXBLOCKSIZE);
+	munmap(rand_data, SPA_MAXBLOCKSIZE);
 	kernel_fini();
 
 	return (err);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, assuming using an anonymous mapping works as hoped this does seems preferable. Still I don't think we need to hold up this PR on that. We can always follow up with this.


umem_free(rand_data, SPA_MAXBLOCKSIZE);
kernel_fini();

Expand Down
2 changes: 1 addition & 1 deletion cmd/raidz_test/raidz_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef struct raidz_test_opts {

static const raidz_test_opts_t rto_opts_defaults = {
.rto_ashift = 9,
.rto_offset = 1ULL << 0,
.rto_offset = 0,
.rto_dcols = 8,
.rto_dsize = 1<<19,
.rto_v = D_ALL,
Expand Down
2 changes: 1 addition & 1 deletion tests/zfs-tests/tests/functional/raidz/raidz_001_neg.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
# This option should make raidz_test to return non 0.
#

log_mustnot raidz_test -T
log_mustnot raidz_test -Tv

log_pass "raidz_test detects errors as expected."
Loading