]> git.proxmox.com Git - mirror_zfs-debian.git/commitdiff
Fix mmap() usage in ztest.
authorChristopher Siden <chris.siden@delphix.com>
Mon, 21 May 2012 19:11:39 +0000 (12:11 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 4 Oct 2012 20:19:09 +0000 (13:19 -0700)
illumos/illumos-gate@ad135b5d644628e791c3188a6ecbd9c257961ef8
Illumos changeset: 13700:2889e2596bd6

Note that this is only a partial port of the aforementioned Illumos
changeset.

Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <gwilson@delphix.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: Dan Kruchinin <dan.kruchinin@gmail.com>
Approved by: Eric Schrock <Eric.Schrock@delphix.com>

Ported to zfsonlinux by: Etienne Dechamps <etienne.dechamps@ovh.net>

cmd/ztest/ztest.c

index 8655b237cd996d92a96b456bfa50ec3b0c4885b8..9da15a1859adea90f6fff70b5bee760d74238e73 100644 (file)
@@ -5822,7 +5822,6 @@ setup_fds(void)
        char *tmp = tempnam(NULL, NULL);
        fd = open(tmp, O_RDWR | O_CREAT, 0700);
        ASSERT3S(fd, >=, 0);
-       VERIFY3S(ftruncate(fd, sizeof (ztest_shared_hdr_t)), ==, 0);
        if (fd != ZTEST_FD_DATA) {
                VERIFY3S(dup2(fd, ZTEST_FD_DATA), ==, ZTEST_FD_DATA);
                close(fd);
@@ -5838,15 +5837,32 @@ setup_fds(void)
        }
 }
 
+static int
+shared_data_size(ztest_shared_hdr_t *hdr)
+{
+       int size;
+
+       size = hdr->zh_hdr_size;
+       size += hdr->zh_opts_size;
+       size += hdr->zh_size;
+       size += hdr->zh_stats_size * hdr->zh_stats_count;
+       size += hdr->zh_ds_size * hdr->zh_ds_count;
+
+       return (size);
+}
+
 static void
 setup_hdr(void)
 {
+       int size;
        ztest_shared_hdr_t *hdr;
 
        hdr = (void *)mmap(0, P2ROUNDUP(sizeof (*hdr), getpagesize()),
            PROT_READ | PROT_WRITE, MAP_SHARED, ZTEST_FD_DATA, 0);
        ASSERT(hdr != MAP_FAILED);
 
+       VERIFY3U(0, ==, ftruncate(ZTEST_FD_DATA, sizeof (ztest_shared_hdr_t)));
+
        hdr->zh_hdr_size = sizeof (ztest_shared_hdr_t);
        hdr->zh_opts_size = sizeof (ztest_shared_opts_t);
        hdr->zh_size = sizeof (ztest_shared_t);
@@ -5855,6 +5871,9 @@ setup_hdr(void)
        hdr->zh_ds_size = sizeof (ztest_shared_ds_t);
        hdr->zh_ds_count = ztest_opts.zo_datasets;
 
+       size = shared_data_size(hdr);
+       VERIFY3U(0, ==, ftruncate(ZTEST_FD_DATA, size));
+
        (void) munmap((caddr_t)hdr, P2ROUNDUP(sizeof (*hdr), getpagesize()));
 }
 
@@ -5869,11 +5888,7 @@ setup_data(void)
            PROT_READ, MAP_SHARED, ZTEST_FD_DATA, 0);
        ASSERT(hdr != MAP_FAILED);
 
-       size = hdr->zh_hdr_size;
-       size += hdr->zh_opts_size;
-       size += hdr->zh_size;
-       size += hdr->zh_stats_size * hdr->zh_stats_count;
-       size += hdr->zh_ds_size * hdr->zh_ds_count;
+       size = shared_data_size(hdr);
 
        (void) munmap((caddr_t)hdr, P2ROUNDUP(sizeof (*hdr), getpagesize()));
        hdr = ztest_shared_hdr = (void *)mmap(0, P2ROUNDUP(size, getpagesize()),