Deleted Added
full compact
ztest.c (236837) ztest.c (243674)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 93 unchanged lines hidden (view full) ---

102#include <sys/vdev_file.h>
103#include <sys/spa_impl.h>
104#include <sys/metaslab_impl.h>
105#include <sys/dsl_prop.h>
106#include <sys/dsl_dataset.h>
107#include <sys/dsl_scan.h>
108#include <sys/zio_checksum.h>
109#include <sys/refcount.h>
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 93 unchanged lines hidden (view full) ---

102#include <sys/vdev_file.h>
103#include <sys/spa_impl.h>
104#include <sys/metaslab_impl.h>
105#include <sys/dsl_prop.h>
106#include <sys/dsl_dataset.h>
107#include <sys/dsl_scan.h>
108#include <sys/zio_checksum.h>
109#include <sys/refcount.h>
110#include <sys/zfeature.h>
110#include <stdio.h>
111#include <stdio_ext.h>
112#include <stdlib.h>
113#include <unistd.h>
114#include <signal.h>
115#include <umem.h>
116#include <dlfcn.h>
117#include <ctype.h>

--- 206 unchanged lines hidden (view full) ---

324ztest_func_t ztest_scrub;
325ztest_func_t ztest_dsl_dataset_promote_busy;
326ztest_func_t ztest_vdev_attach_detach;
327ztest_func_t ztest_vdev_LUN_growth;
328ztest_func_t ztest_vdev_add_remove;
329ztest_func_t ztest_vdev_aux_add_remove;
330ztest_func_t ztest_split_pool;
331ztest_func_t ztest_reguid;
111#include <stdio.h>
112#include <stdio_ext.h>
113#include <stdlib.h>
114#include <unistd.h>
115#include <signal.h>
116#include <umem.h>
117#include <dlfcn.h>
118#include <ctype.h>

--- 206 unchanged lines hidden (view full) ---

325ztest_func_t ztest_scrub;
326ztest_func_t ztest_dsl_dataset_promote_busy;
327ztest_func_t ztest_vdev_attach_detach;
328ztest_func_t ztest_vdev_LUN_growth;
329ztest_func_t ztest_vdev_add_remove;
330ztest_func_t ztest_vdev_aux_add_remove;
331ztest_func_t ztest_split_pool;
332ztest_func_t ztest_reguid;
333ztest_func_t ztest_spa_upgrade;
332
333uint64_t zopt_always = 0ULL * NANOSEC; /* all the time */
334uint64_t zopt_incessant = 1ULL * NANOSEC / 10; /* every 1/10 second */
335uint64_t zopt_often = 1ULL * NANOSEC; /* every second */
336uint64_t zopt_sometimes = 10ULL * NANOSEC; /* every 10 seconds */
337uint64_t zopt_rarely = 60ULL * NANOSEC; /* every 60 seconds */
338
339ztest_info_t ztest_info[] = {

--- 17 unchanged lines hidden (view full) ---

357 { ztest_dmu_snapshot_create_destroy, 1, &zopt_sometimes },
358 { ztest_spa_create_destroy, 1, &zopt_sometimes },
359 { ztest_fault_inject, 1, &zopt_sometimes },
360 { ztest_ddt_repair, 1, &zopt_sometimes },
361 { ztest_dmu_snapshot_hold, 1, &zopt_sometimes },
362 { ztest_reguid, 1, &zopt_sometimes },
363 { ztest_spa_rename, 1, &zopt_rarely },
364 { ztest_scrub, 1, &zopt_rarely },
334
335uint64_t zopt_always = 0ULL * NANOSEC; /* all the time */
336uint64_t zopt_incessant = 1ULL * NANOSEC / 10; /* every 1/10 second */
337uint64_t zopt_often = 1ULL * NANOSEC; /* every second */
338uint64_t zopt_sometimes = 10ULL * NANOSEC; /* every 10 seconds */
339uint64_t zopt_rarely = 60ULL * NANOSEC; /* every 60 seconds */
340
341ztest_info_t ztest_info[] = {

--- 17 unchanged lines hidden (view full) ---

359 { ztest_dmu_snapshot_create_destroy, 1, &zopt_sometimes },
360 { ztest_spa_create_destroy, 1, &zopt_sometimes },
361 { ztest_fault_inject, 1, &zopt_sometimes },
362 { ztest_ddt_repair, 1, &zopt_sometimes },
363 { ztest_dmu_snapshot_hold, 1, &zopt_sometimes },
364 { ztest_reguid, 1, &zopt_sometimes },
365 { ztest_spa_rename, 1, &zopt_rarely },
366 { ztest_scrub, 1, &zopt_rarely },
367 { ztest_spa_upgrade, 1, &zopt_rarely },
365 { ztest_dsl_dataset_promote_busy, 1, &zopt_rarely },
368 { ztest_dsl_dataset_promote_busy, 1, &zopt_rarely },
366 { ztest_vdev_attach_detach, 1, &zopt_rarely },
369 { ztest_vdev_attach_detach, 1, &zopt_rarely },
367 { ztest_vdev_LUN_growth, 1, &zopt_rarely },
368 { ztest_vdev_add_remove, 1,
369 &ztest_opts.zo_vdevtime },
370 { ztest_vdev_aux_add_remove, 1,
371 &ztest_opts.zo_vdevtime },
372};
373
374#define ZTEST_FUNCS (sizeof (ztest_info) / sizeof (ztest_info_t))

--- 34 unchanged lines hidden (view full) ---

409static char ztest_dev_template[] = "%s/%s.%llua";
410static char ztest_aux_template[] = "%s/%s.%s.%llu";
411ztest_shared_t *ztest_shared;
412
413static spa_t *ztest_spa = NULL;
414static ztest_ds_t *ztest_ds;
415
416static mutex_t ztest_vdev_lock;
370 { ztest_vdev_LUN_growth, 1, &zopt_rarely },
371 { ztest_vdev_add_remove, 1,
372 &ztest_opts.zo_vdevtime },
373 { ztest_vdev_aux_add_remove, 1,
374 &ztest_opts.zo_vdevtime },
375};
376
377#define ZTEST_FUNCS (sizeof (ztest_info) / sizeof (ztest_info_t))

--- 34 unchanged lines hidden (view full) ---

412static char ztest_dev_template[] = "%s/%s.%llua";
413static char ztest_aux_template[] = "%s/%s.%s.%llu";
414ztest_shared_t *ztest_shared;
415
416static spa_t *ztest_spa = NULL;
417static ztest_ds_t *ztest_ds;
418
419static mutex_t ztest_vdev_lock;
420
421/*
422 * The ztest_name_lock protects the pool and dataset namespace used by
423 * the individual tests. To modify the namespace, consumers must grab
424 * this lock as writer. Grabbing the lock as reader will ensure that the
425 * namespace does not change while the lock is held.
426 */
417static rwlock_t ztest_name_lock;
418
419static boolean_t ztest_dump_core = B_TRUE;
420static boolean_t ztest_exiting;
421
422/* Global commit callback list */
423static ztest_cb_list_t zcl;
424

--- 351 unchanged lines hidden (view full) ---

776ztest_get_ashift(void)
777{
778 if (ztest_opts.zo_ashift == 0)
779 return (SPA_MINBLOCKSHIFT + ztest_random(3));
780 return (ztest_opts.zo_ashift);
781}
782
783static nvlist_t *
427static rwlock_t ztest_name_lock;
428
429static boolean_t ztest_dump_core = B_TRUE;
430static boolean_t ztest_exiting;
431
432/* Global commit callback list */
433static ztest_cb_list_t zcl;
434

--- 351 unchanged lines hidden (view full) ---

786ztest_get_ashift(void)
787{
788 if (ztest_opts.zo_ashift == 0)
789 return (SPA_MINBLOCKSHIFT + ztest_random(3));
790 return (ztest_opts.zo_ashift);
791}
792
793static nvlist_t *
784make_vdev_file(char *path, char *aux, size_t size, uint64_t ashift)
794make_vdev_file(char *path, char *aux, char *pool, size_t size, uint64_t ashift)
785{
786 char pathbuf[MAXPATHLEN];
787 uint64_t vdev;
788 nvlist_t *file;
789
790 if (ashift == 0)
791 ashift = ztest_get_ashift();
792
793 if (path == NULL) {
794 path = pathbuf;
795
796 if (aux != NULL) {
797 vdev = ztest_shared->zs_vdev_aux;
798 (void) snprintf(path, sizeof (pathbuf),
799 ztest_aux_template, ztest_opts.zo_dir,
795{
796 char pathbuf[MAXPATHLEN];
797 uint64_t vdev;
798 nvlist_t *file;
799
800 if (ashift == 0)
801 ashift = ztest_get_ashift();
802
803 if (path == NULL) {
804 path = pathbuf;
805
806 if (aux != NULL) {
807 vdev = ztest_shared->zs_vdev_aux;
808 (void) snprintf(path, sizeof (pathbuf),
809 ztest_aux_template, ztest_opts.zo_dir,
800 ztest_opts.zo_pool, aux, vdev);
810 pool == NULL ? ztest_opts.zo_pool : pool,
811 aux, vdev);
801 } else {
802 vdev = ztest_shared->zs_vdev_next_leaf++;
803 (void) snprintf(path, sizeof (pathbuf),
804 ztest_dev_template, ztest_opts.zo_dir,
812 } else {
813 vdev = ztest_shared->zs_vdev_next_leaf++;
814 (void) snprintf(path, sizeof (pathbuf),
815 ztest_dev_template, ztest_opts.zo_dir,
805 ztest_opts.zo_pool, vdev);
816 pool == NULL ? ztest_opts.zo_pool : pool, vdev);
806 }
807 }
808
809 if (size != 0) {
810 int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666);
811 if (fd == -1)
812 fatal(1, "can't open %s", path);
813 if (ftruncate(fd, size) != 0)

--- 5 unchanged lines hidden (view full) ---

819 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, VDEV_TYPE_FILE) == 0);
820 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_PATH, path) == 0);
821 VERIFY(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift) == 0);
822
823 return (file);
824}
825
826static nvlist_t *
817 }
818 }
819
820 if (size != 0) {
821 int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666);
822 if (fd == -1)
823 fatal(1, "can't open %s", path);
824 if (ftruncate(fd, size) != 0)

--- 5 unchanged lines hidden (view full) ---

830 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, VDEV_TYPE_FILE) == 0);
831 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_PATH, path) == 0);
832 VERIFY(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift) == 0);
833
834 return (file);
835}
836
837static nvlist_t *
827make_vdev_raidz(char *path, char *aux, size_t size, uint64_t ashift, int r)
838make_vdev_raidz(char *path, char *aux, char *pool, size_t size,
839 uint64_t ashift, int r)
828{
829 nvlist_t *raidz, **child;
830 int c;
831
832 if (r < 2)
840{
841 nvlist_t *raidz, **child;
842 int c;
843
844 if (r < 2)
833 return (make_vdev_file(path, aux, size, ashift));
845 return (make_vdev_file(path, aux, pool, size, ashift));
834 child = umem_alloc(r * sizeof (nvlist_t *), UMEM_NOFAIL);
835
836 for (c = 0; c < r; c++)
846 child = umem_alloc(r * sizeof (nvlist_t *), UMEM_NOFAIL);
847
848 for (c = 0; c < r; c++)
837 child[c] = make_vdev_file(path, aux, size, ashift);
849 child[c] = make_vdev_file(path, aux, pool, size, ashift);
838
839 VERIFY(nvlist_alloc(&raidz, NV_UNIQUE_NAME, 0) == 0);
840 VERIFY(nvlist_add_string(raidz, ZPOOL_CONFIG_TYPE,
841 VDEV_TYPE_RAIDZ) == 0);
842 VERIFY(nvlist_add_uint64(raidz, ZPOOL_CONFIG_NPARITY,
843 ztest_opts.zo_raidz_parity) == 0);
844 VERIFY(nvlist_add_nvlist_array(raidz, ZPOOL_CONFIG_CHILDREN,
845 child, r) == 0);
846
847 for (c = 0; c < r; c++)
848 nvlist_free(child[c]);
849
850 umem_free(child, r * sizeof (nvlist_t *));
851
852 return (raidz);
853}
854
855static nvlist_t *
850
851 VERIFY(nvlist_alloc(&raidz, NV_UNIQUE_NAME, 0) == 0);
852 VERIFY(nvlist_add_string(raidz, ZPOOL_CONFIG_TYPE,
853 VDEV_TYPE_RAIDZ) == 0);
854 VERIFY(nvlist_add_uint64(raidz, ZPOOL_CONFIG_NPARITY,
855 ztest_opts.zo_raidz_parity) == 0);
856 VERIFY(nvlist_add_nvlist_array(raidz, ZPOOL_CONFIG_CHILDREN,
857 child, r) == 0);
858
859 for (c = 0; c < r; c++)
860 nvlist_free(child[c]);
861
862 umem_free(child, r * sizeof (nvlist_t *));
863
864 return (raidz);
865}
866
867static nvlist_t *
856make_vdev_mirror(char *path, char *aux, size_t size, uint64_t ashift,
857 int r, int m)
868make_vdev_mirror(char *path, char *aux, char *pool, size_t size,
869 uint64_t ashift, int r, int m)
858{
859 nvlist_t *mirror, **child;
860 int c;
861
862 if (m < 1)
870{
871 nvlist_t *mirror, **child;
872 int c;
873
874 if (m < 1)
863 return (make_vdev_raidz(path, aux, size, ashift, r));
875 return (make_vdev_raidz(path, aux, pool, size, ashift, r));
864
865 child = umem_alloc(m * sizeof (nvlist_t *), UMEM_NOFAIL);
866
867 for (c = 0; c < m; c++)
876
877 child = umem_alloc(m * sizeof (nvlist_t *), UMEM_NOFAIL);
878
879 for (c = 0; c < m; c++)
868 child[c] = make_vdev_raidz(path, aux, size, ashift, r);
880 child[c] = make_vdev_raidz(path, aux, pool, size, ashift, r);
869
870 VERIFY(nvlist_alloc(&mirror, NV_UNIQUE_NAME, 0) == 0);
871 VERIFY(nvlist_add_string(mirror, ZPOOL_CONFIG_TYPE,
872 VDEV_TYPE_MIRROR) == 0);
873 VERIFY(nvlist_add_nvlist_array(mirror, ZPOOL_CONFIG_CHILDREN,
874 child, m) == 0);
875
876 for (c = 0; c < m; c++)
877 nvlist_free(child[c]);
878
879 umem_free(child, m * sizeof (nvlist_t *));
880
881 return (mirror);
882}
883
884static nvlist_t *
881
882 VERIFY(nvlist_alloc(&mirror, NV_UNIQUE_NAME, 0) == 0);
883 VERIFY(nvlist_add_string(mirror, ZPOOL_CONFIG_TYPE,
884 VDEV_TYPE_MIRROR) == 0);
885 VERIFY(nvlist_add_nvlist_array(mirror, ZPOOL_CONFIG_CHILDREN,
886 child, m) == 0);
887
888 for (c = 0; c < m; c++)
889 nvlist_free(child[c]);
890
891 umem_free(child, m * sizeof (nvlist_t *));
892
893 return (mirror);
894}
895
896static nvlist_t *
885make_vdev_root(char *path, char *aux, size_t size, uint64_t ashift,
886 int log, int r, int m, int t)
897make_vdev_root(char *path, char *aux, char *pool, size_t size, uint64_t ashift,
898 int log, int r, int m, int t)
887{
888 nvlist_t *root, **child;
889 int c;
890
891 ASSERT(t > 0);
892
893 child = umem_alloc(t * sizeof (nvlist_t *), UMEM_NOFAIL);
894
895 for (c = 0; c < t; c++) {
899{
900 nvlist_t *root, **child;
901 int c;
902
903 ASSERT(t > 0);
904
905 child = umem_alloc(t * sizeof (nvlist_t *), UMEM_NOFAIL);
906
907 for (c = 0; c < t; c++) {
896 child[c] = make_vdev_mirror(path, aux, size, ashift, r, m);
908 child[c] = make_vdev_mirror(path, aux, pool, size, ashift,
909 r, m);
897 VERIFY(nvlist_add_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
898 log) == 0);
899 }
900
901 VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0);
902 VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0);
903 VERIFY(nvlist_add_nvlist_array(root, aux ? aux : ZPOOL_CONFIG_CHILDREN,
904 child, t) == 0);
905
906 for (c = 0; c < t; c++)
907 nvlist_free(child[c]);
908
909 umem_free(child, t * sizeof (nvlist_t *));
910
911 return (root);
912}
913
910 VERIFY(nvlist_add_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
911 log) == 0);
912 }
913
914 VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0);
915 VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0);
916 VERIFY(nvlist_add_nvlist_array(root, aux ? aux : ZPOOL_CONFIG_CHILDREN,
917 child, t) == 0);
918
919 for (c = 0; c < t; c++)
920 nvlist_free(child[c]);
921
922 umem_free(child, t * sizeof (nvlist_t *));
923
924 return (root);
925}
926
927/*
928 * Find a random spa version. Returns back a random spa version in the
929 * range [initial_version, SPA_VERSION_FEATURES].
930 */
931static uint64_t
932ztest_random_spa_version(uint64_t initial_version)
933{
934 uint64_t version = initial_version;
935
936 if (version <= SPA_VERSION_BEFORE_FEATURES) {
937 version = version +
938 ztest_random(SPA_VERSION_BEFORE_FEATURES - version + 1);
939 }
940
941 if (version > SPA_VERSION_BEFORE_FEATURES)
942 version = SPA_VERSION_FEATURES;
943
944 ASSERT(SPA_VERSION_IS_SUPPORTED(version));
945 return (version);
946}
947
914static int
915ztest_random_blocksize(void)
916{
917 return (1 << (SPA_MINBLOCKSHIFT +
918 ztest_random(SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)));
919}
920
921static int

--- 46 unchanged lines hidden (view full) ---

968 error = dsl_prop_set(osname, propname,
969 (inherit ? ZPROP_SRC_NONE : ZPROP_SRC_LOCAL),
970 sizeof (value), 1, &value);
971
972 if (error == ENOSPC) {
973 ztest_record_enospc(FTAG);
974 return (error);
975 }
948static int
949ztest_random_blocksize(void)
950{
951 return (1 << (SPA_MINBLOCKSHIFT +
952 ztest_random(SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)));
953}
954
955static int

--- 46 unchanged lines hidden (view full) ---

1002 error = dsl_prop_set(osname, propname,
1003 (inherit ? ZPROP_SRC_NONE : ZPROP_SRC_LOCAL),
1004 sizeof (value), 1, &value);
1005
1006 if (error == ENOSPC) {
1007 ztest_record_enospc(FTAG);
1008 return (error);
1009 }
976 ASSERT3U(error, ==, 0);
1010 ASSERT0(error);
977
978 VERIFY3U(dsl_prop_get(osname, propname, sizeof (curval),
979 1, &curval, setpoint), ==, 0);
980
981 if (ztest_opts.zo_verbose >= 6) {
982 VERIFY(zfs_prop_index_to_string(prop, curval, &valname) == 0);
983 (void) printf("%s %s = %s at '%s'\n",
984 osname, propname, valname, setpoint);

--- 15 unchanged lines hidden (view full) ---

1000 error = spa_prop_set(spa, props);
1001
1002 nvlist_free(props);
1003
1004 if (error == ENOSPC) {
1005 ztest_record_enospc(FTAG);
1006 return (error);
1007 }
1011
1012 VERIFY3U(dsl_prop_get(osname, propname, sizeof (curval),
1013 1, &curval, setpoint), ==, 0);
1014
1015 if (ztest_opts.zo_verbose >= 6) {
1016 VERIFY(zfs_prop_index_to_string(prop, curval, &valname) == 0);
1017 (void) printf("%s %s = %s at '%s'\n",
1018 osname, propname, valname, setpoint);

--- 15 unchanged lines hidden (view full) ---

1034 error = spa_prop_set(spa, props);
1035
1036 nvlist_free(props);
1037
1038 if (error == ENOSPC) {
1039 ztest_record_enospc(FTAG);
1040 return (error);
1041 }
1008 ASSERT3U(error, ==, 0);
1042 ASSERT0(error);
1009
1010 return (error);
1011}
1012
1013static void
1014ztest_rll_init(rll_t *rll)
1015{
1016 rll->rll_writer = NULL;

--- 680 unchanged lines hidden (view full) ---

1697 */
1698 ztest_bt_verify(bbt, os, lr->lr_foid, -1ULL, lr->lr_mode,
1699 MAX(txg, lrtxg), crtxg);
1700
1701 dmu_buf_will_dirty(db, tx);
1702
1703 ASSERT3U(lr->lr_size, >=, sizeof (*bbt));
1704 ASSERT3U(lr->lr_size, <=, db->db_size);
1043
1044 return (error);
1045}
1046
1047static void
1048ztest_rll_init(rll_t *rll)
1049{
1050 rll->rll_writer = NULL;

--- 680 unchanged lines hidden (view full) ---

1731 */
1732 ztest_bt_verify(bbt, os, lr->lr_foid, -1ULL, lr->lr_mode,
1733 MAX(txg, lrtxg), crtxg);
1734
1735 dmu_buf_will_dirty(db, tx);
1736
1737 ASSERT3U(lr->lr_size, >=, sizeof (*bbt));
1738 ASSERT3U(lr->lr_size, <=, db->db_size);
1705 VERIFY3U(dmu_set_bonus(db, lr->lr_size, tx), ==, 0);
1739 VERIFY0(dmu_set_bonus(db, lr->lr_size, tx));
1706 bbt = ztest_bt_bonus(db);
1707
1708 ztest_bt_generate(bbt, os, lr->lr_foid, -1ULL, lr->lr_mode, txg, crtxg);
1709
1710 dmu_buf_rele(db, FTAG);
1711
1712 (void) ztest_log_setattr(zd, tx, lr);
1713

--- 505 unchanged lines hidden (view full) ---

2219 * attempt to expose any implicit assumptions about ZIL management.
2220 */
2221/* ARGSUSED */
2222void
2223ztest_zil_remount(ztest_ds_t *zd, uint64_t id)
2224{
2225 objset_t *os = zd->zd_os;
2226
1740 bbt = ztest_bt_bonus(db);
1741
1742 ztest_bt_generate(bbt, os, lr->lr_foid, -1ULL, lr->lr_mode, txg, crtxg);
1743
1744 dmu_buf_rele(db, FTAG);
1745
1746 (void) ztest_log_setattr(zd, tx, lr);
1747

--- 505 unchanged lines hidden (view full) ---

2253 * attempt to expose any implicit assumptions about ZIL management.
2254 */
2255/* ARGSUSED */
2256void
2257ztest_zil_remount(ztest_ds_t *zd, uint64_t id)
2258{
2259 objset_t *os = zd->zd_os;
2260
2261 VERIFY(mutex_lock(&zd->zd_dirobj_lock) == 0);
2227 (void) rw_wrlock(&zd->zd_zilog_lock);
2228
2229 /* zfsvfs_teardown() */
2230 zil_close(zd->zd_zilog);
2231
2232 /* zfsvfs_setup() */
2233 VERIFY(zil_open(os, ztest_get_data) == zd->zd_zilog);
2234 zil_replay(os, zd, ztest_replay_vector);
2235
2236 (void) rw_unlock(&zd->zd_zilog_lock);
2262 (void) rw_wrlock(&zd->zd_zilog_lock);
2263
2264 /* zfsvfs_teardown() */
2265 zil_close(zd->zd_zilog);
2266
2267 /* zfsvfs_setup() */
2268 VERIFY(zil_open(os, ztest_get_data) == zd->zd_zilog);
2269 zil_replay(os, zd, ztest_replay_vector);
2270
2271 (void) rw_unlock(&zd->zd_zilog_lock);
2272 VERIFY(mutex_unlock(&zd->zd_dirobj_lock) == 0);
2237}
2238
2239/*
2240 * Verify that we can't destroy an active pool, create an existing pool,
2241 * or create a pool with a bad vdev spec.
2242 */
2243/* ARGSUSED */
2244void
2245ztest_spa_create_destroy(ztest_ds_t *zd, uint64_t id)
2246{
2247 ztest_shared_opts_t *zo = &ztest_opts;
2248 spa_t *spa;
2249 nvlist_t *nvroot;
2250
2251 /*
2252 * Attempt to create using a bad file.
2253 */
2273}
2274
2275/*
2276 * Verify that we can't destroy an active pool, create an existing pool,
2277 * or create a pool with a bad vdev spec.
2278 */
2279/* ARGSUSED */
2280void
2281ztest_spa_create_destroy(ztest_ds_t *zd, uint64_t id)
2282{
2283 ztest_shared_opts_t *zo = &ztest_opts;
2284 spa_t *spa;
2285 nvlist_t *nvroot;
2286
2287 /*
2288 * Attempt to create using a bad file.
2289 */
2254 nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 0, 1);
2290 nvroot = make_vdev_root("/dev/bogus", NULL, NULL, 0, 0, 0, 0, 0, 1);
2255 VERIFY3U(ENOENT, ==,
2256 spa_create("ztest_bad_file", nvroot, NULL, NULL, NULL));
2257 nvlist_free(nvroot);
2258
2259 /*
2260 * Attempt to create using a bad mirror.
2261 */
2291 VERIFY3U(ENOENT, ==,
2292 spa_create("ztest_bad_file", nvroot, NULL, NULL, NULL));
2293 nvlist_free(nvroot);
2294
2295 /*
2296 * Attempt to create using a bad mirror.
2297 */
2262 nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 2, 1);
2298 nvroot = make_vdev_root("/dev/bogus", NULL, NULL, 0, 0, 0, 0, 2, 1);
2263 VERIFY3U(ENOENT, ==,
2264 spa_create("ztest_bad_mirror", nvroot, NULL, NULL, NULL));
2265 nvlist_free(nvroot);
2266
2267 /*
2268 * Attempt to create an existing pool. It shouldn't matter
2269 * what's in the nvroot; we should fail with EEXIST.
2270 */
2271 (void) rw_rdlock(&ztest_name_lock);
2299 VERIFY3U(ENOENT, ==,
2300 spa_create("ztest_bad_mirror", nvroot, NULL, NULL, NULL));
2301 nvlist_free(nvroot);
2302
2303 /*
2304 * Attempt to create an existing pool. It shouldn't matter
2305 * what's in the nvroot; we should fail with EEXIST.
2306 */
2307 (void) rw_rdlock(&ztest_name_lock);
2272 nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 0, 1);
2308 nvroot = make_vdev_root("/dev/bogus", NULL, NULL, 0, 0, 0, 0, 0, 1);
2273 VERIFY3U(EEXIST, ==, spa_create(zo->zo_pool, nvroot, NULL, NULL, NULL));
2274 nvlist_free(nvroot);
2275 VERIFY3U(0, ==, spa_open(zo->zo_pool, &spa, FTAG));
2276 VERIFY3U(EBUSY, ==, spa_destroy(zo->zo_pool));
2277 spa_close(spa, FTAG);
2278
2279 (void) rw_unlock(&ztest_name_lock);
2280}
2281
2309 VERIFY3U(EEXIST, ==, spa_create(zo->zo_pool, nvroot, NULL, NULL, NULL));
2310 nvlist_free(nvroot);
2311 VERIFY3U(0, ==, spa_open(zo->zo_pool, &spa, FTAG));
2312 VERIFY3U(EBUSY, ==, spa_destroy(zo->zo_pool));
2313 spa_close(spa, FTAG);
2314
2315 (void) rw_unlock(&ztest_name_lock);
2316}
2317
2318/* ARGSUSED */
2319void
2320ztest_spa_upgrade(ztest_ds_t *zd, uint64_t id)
2321{
2322 spa_t *spa;
2323 uint64_t initial_version = SPA_VERSION_INITIAL;
2324 uint64_t version, newversion;
2325 nvlist_t *nvroot, *props;
2326 char *name;
2327
2328 VERIFY0(mutex_lock(&ztest_vdev_lock));
2329 name = kmem_asprintf("%s_upgrade", ztest_opts.zo_pool);
2330
2331 /*
2332 * Clean up from previous runs.
2333 */
2334 (void) spa_destroy(name);
2335
2336 nvroot = make_vdev_root(NULL, NULL, name, ztest_opts.zo_vdev_size, 0,
2337 0, ztest_opts.zo_raidz, ztest_opts.zo_mirrors, 1);
2338
2339 /*
2340 * If we're configuring a RAIDZ device then make sure that the
2341 * the initial version is capable of supporting that feature.
2342 */
2343 switch (ztest_opts.zo_raidz_parity) {
2344 case 0:
2345 case 1:
2346 initial_version = SPA_VERSION_INITIAL;
2347 break;
2348 case 2:
2349 initial_version = SPA_VERSION_RAIDZ2;
2350 break;
2351 case 3:
2352 initial_version = SPA_VERSION_RAIDZ3;
2353 break;
2354 }
2355
2356 /*
2357 * Create a pool with a spa version that can be upgraded. Pick
2358 * a value between initial_version and SPA_VERSION_BEFORE_FEATURES.
2359 */
2360 do {
2361 version = ztest_random_spa_version(initial_version);
2362 } while (version > SPA_VERSION_BEFORE_FEATURES);
2363
2364 props = fnvlist_alloc();
2365 fnvlist_add_uint64(props,
2366 zpool_prop_to_name(ZPOOL_PROP_VERSION), version);
2367 VERIFY0(spa_create(name, nvroot, props, NULL, NULL));
2368 fnvlist_free(nvroot);
2369 fnvlist_free(props);
2370
2371 VERIFY0(spa_open(name, &spa, FTAG));
2372 VERIFY3U(spa_version(spa), ==, version);
2373 newversion = ztest_random_spa_version(version + 1);
2374
2375 if (ztest_opts.zo_verbose >= 4) {
2376 (void) printf("upgrading spa version from %llu to %llu\n",
2377 (u_longlong_t)version, (u_longlong_t)newversion);
2378 }
2379
2380 spa_upgrade(spa, newversion);
2381 VERIFY3U(spa_version(spa), >, version);
2382 VERIFY3U(spa_version(spa), ==, fnvlist_lookup_uint64(spa->spa_config,
2383 zpool_prop_to_name(ZPOOL_PROP_VERSION)));
2384 spa_close(spa, FTAG);
2385
2386 strfree(name);
2387 VERIFY0(mutex_unlock(&ztest_vdev_lock));
2388}
2389
2282static vdev_t *
2283vdev_lookup_by_path(vdev_t *vd, const char *path)
2284{
2285 vdev_t *mvd;
2286
2287 if (vd->vdev_path != NULL && strcmp(path, vd->vdev_path) == 0)
2288 return (vd);
2289

--- 73 unchanged lines hidden (view full) ---

2363 if (error && error != EEXIST)
2364 fatal(0, "spa_vdev_remove() = %d", error);
2365 } else {
2366 spa_config_exit(spa, SCL_VDEV, FTAG);
2367
2368 /*
2369 * Make 1/4 of the devices be log devices.
2370 */
2390static vdev_t *
2391vdev_lookup_by_path(vdev_t *vd, const char *path)
2392{
2393 vdev_t *mvd;
2394
2395 if (vd->vdev_path != NULL && strcmp(path, vd->vdev_path) == 0)
2396 return (vd);
2397

--- 73 unchanged lines hidden (view full) ---

2471 if (error && error != EEXIST)
2472 fatal(0, "spa_vdev_remove() = %d", error);
2473 } else {
2474 spa_config_exit(spa, SCL_VDEV, FTAG);
2475
2476 /*
2477 * Make 1/4 of the devices be log devices.
2478 */
2371 nvroot = make_vdev_root(NULL, NULL,
2479 nvroot = make_vdev_root(NULL, NULL, NULL,
2372 ztest_opts.zo_vdev_size, 0,
2373 ztest_random(4) == 0, ztest_opts.zo_raidz,
2374 zs->zs_mirrors, 1);
2375
2376 error = spa_vdev_add(spa, nvroot);
2377 nvlist_free(nvroot);
2378
2379 if (error == ENOSPC)

--- 60 unchanged lines hidden (view full) ---

2440 }
2441
2442 spa_config_exit(spa, SCL_VDEV, FTAG);
2443
2444 if (guid == 0) {
2445 /*
2446 * Add a new device.
2447 */
2480 ztest_opts.zo_vdev_size, 0,
2481 ztest_random(4) == 0, ztest_opts.zo_raidz,
2482 zs->zs_mirrors, 1);
2483
2484 error = spa_vdev_add(spa, nvroot);
2485 nvlist_free(nvroot);
2486
2487 if (error == ENOSPC)

--- 60 unchanged lines hidden (view full) ---

2548 }
2549
2550 spa_config_exit(spa, SCL_VDEV, FTAG);
2551
2552 if (guid == 0) {
2553 /*
2554 * Add a new device.
2555 */
2448 nvlist_t *nvroot = make_vdev_root(NULL, aux,
2556 nvlist_t *nvroot = make_vdev_root(NULL, aux, NULL,
2449 (ztest_opts.zo_vdev_size * 5) / 4, 0, 0, 0, 0, 1);
2450 error = spa_vdev_add(spa, nvroot);
2451 if (error != 0)
2452 fatal(0, "spa_vdev_add(%p) = %d", nvroot, error);
2453 nvlist_free(nvroot);
2454 } else {
2455 /*
2456 * Remove an existing device. Sometimes, dirty its

--- 252 unchanged lines hidden (view full) ---

2709 else
2710 expected_error = 0;
2711
2712 spa_config_exit(spa, SCL_VDEV, FTAG);
2713
2714 /*
2715 * Build the nvlist describing newpath.
2716 */
2557 (ztest_opts.zo_vdev_size * 5) / 4, 0, 0, 0, 0, 1);
2558 error = spa_vdev_add(spa, nvroot);
2559 if (error != 0)
2560 fatal(0, "spa_vdev_add(%p) = %d", nvroot, error);
2561 nvlist_free(nvroot);
2562 } else {
2563 /*
2564 * Remove an existing device. Sometimes, dirty its

--- 252 unchanged lines hidden (view full) ---

2817 else
2818 expected_error = 0;
2819
2820 spa_config_exit(spa, SCL_VDEV, FTAG);
2821
2822 /*
2823 * Build the nvlist describing newpath.
2824 */
2717 root = make_vdev_root(newpath, NULL, newvd == NULL ? newsize : 0,
2825 root = make_vdev_root(newpath, NULL, NULL, newvd == NULL ? newsize : 0,
2718 ashift, 0, 0, 0, 1);
2719
2720 error = spa_vdev_attach(spa, oldguid, root, replacing);
2721
2722 nvlist_free(root);
2723
2724 /*
2725 * If our parent was the replacing vdev, but the replace completed,

--- 304 unchanged lines hidden (view full) ---

3030
3031 /*
3032 * Verify that the dataset contains a directory object.
3033 */
3034 VERIFY3U(0, ==, dmu_objset_hold(name, FTAG, &os));
3035 error = dmu_object_info(os, ZTEST_DIROBJ, &doi);
3036 if (error != ENOENT) {
3037 /* We could have crashed in the middle of destroying it */
2826 ashift, 0, 0, 0, 1);
2827
2828 error = spa_vdev_attach(spa, oldguid, root, replacing);
2829
2830 nvlist_free(root);
2831
2832 /*
2833 * If our parent was the replacing vdev, but the replace completed,

--- 304 unchanged lines hidden (view full) ---

3138
3139 /*
3140 * Verify that the dataset contains a directory object.
3141 */
3142 VERIFY3U(0, ==, dmu_objset_hold(name, FTAG, &os));
3143 error = dmu_object_info(os, ZTEST_DIROBJ, &doi);
3144 if (error != ENOENT) {
3145 /* We could have crashed in the middle of destroying it */
3038 ASSERT3U(error, ==, 0);
3146 ASSERT0(error);
3039 ASSERT3U(doi.doi_type, ==, DMU_OT_ZAP_OTHER);
3040 ASSERT3S(doi.doi_physical_blocks_512, >=, 0);
3041 }
3042 dmu_objset_rele(os, FTAG);
3043
3044 /*
3045 * Destroy the dataset.
3046 */

--- 396 unchanged lines hidden (view full) ---

3443 */
3444 freeit = (ztest_random(100) < free_percent);
3445
3446 /*
3447 * Read the current contents of our objects.
3448 */
3449 error = dmu_read(os, packobj, packoff, packsize, packbuf,
3450 DMU_READ_PREFETCH);
3147 ASSERT3U(doi.doi_type, ==, DMU_OT_ZAP_OTHER);
3148 ASSERT3S(doi.doi_physical_blocks_512, >=, 0);
3149 }
3150 dmu_objset_rele(os, FTAG);
3151
3152 /*
3153 * Destroy the dataset.
3154 */

--- 396 unchanged lines hidden (view full) ---

3551 */
3552 freeit = (ztest_random(100) < free_percent);
3553
3554 /*
3555 * Read the current contents of our objects.
3556 */
3557 error = dmu_read(os, packobj, packoff, packsize, packbuf,
3558 DMU_READ_PREFETCH);
3451 ASSERT3U(error, ==, 0);
3559 ASSERT0(error);
3452 error = dmu_read(os, bigobj, bigoff, bigsize, bigbuf,
3453 DMU_READ_PREFETCH);
3560 error = dmu_read(os, bigobj, bigoff, bigsize, bigbuf,
3561 DMU_READ_PREFETCH);
3454 ASSERT3U(error, ==, 0);
3562 ASSERT0(error);
3455
3456 /*
3457 * Get a tx for the mods to both packobj and bigobj.
3458 */
3459 tx = dmu_tx_create(os);
3460
3461 dmu_tx_hold_write(tx, packobj, packoff, packsize);
3462

--- 293 unchanged lines hidden (view full) ---

3756 /*
3757 * 50% of the time don't read objects in the 1st iteration to
3758 * test dmu_assign_arcbuf() for the case when there're no
3759 * existing dbufs for the specified offsets.
3760 */
3761 if (i != 0 || ztest_random(2) != 0) {
3762 error = dmu_read(os, packobj, packoff,
3763 packsize, packbuf, DMU_READ_PREFETCH);
3563
3564 /*
3565 * Get a tx for the mods to both packobj and bigobj.
3566 */
3567 tx = dmu_tx_create(os);
3568
3569 dmu_tx_hold_write(tx, packobj, packoff, packsize);
3570

--- 293 unchanged lines hidden (view full) ---

3864 /*
3865 * 50% of the time don't read objects in the 1st iteration to
3866 * test dmu_assign_arcbuf() for the case when there're no
3867 * existing dbufs for the specified offsets.
3868 */
3869 if (i != 0 || ztest_random(2) != 0) {
3870 error = dmu_read(os, packobj, packoff,
3871 packsize, packbuf, DMU_READ_PREFETCH);
3764 ASSERT3U(error, ==, 0);
3872 ASSERT0(error);
3765 error = dmu_read(os, bigobj, bigoff, bigsize,
3766 bigbuf, DMU_READ_PREFETCH);
3873 error = dmu_read(os, bigobj, bigoff, bigsize,
3874 bigbuf, DMU_READ_PREFETCH);
3767 ASSERT3U(error, ==, 0);
3875 ASSERT0(error);
3768 }
3769 compare_and_update_pbbufs(s, packbuf, bigbuf, bigsize,
3770 n, chunksize, txg);
3771
3772 /*
3773 * We've verified all the old bufwads, and made new ones.
3774 * Now write them out.
3775 */

--- 254 unchanged lines hidden (view full) ---

4030 (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop);
4031 (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop);
4032
4033 error = zap_length(os, object, txgname, &zl_intsize, &zl_ints);
4034
4035 if (error == ENOENT)
4036 return;
4037
3876 }
3877 compare_and_update_pbbufs(s, packbuf, bigbuf, bigsize,
3878 n, chunksize, txg);
3879
3880 /*
3881 * We've verified all the old bufwads, and made new ones.
3882 * Now write them out.
3883 */

--- 254 unchanged lines hidden (view full) ---

4138 (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop);
4139 (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop);
4140
4141 error = zap_length(os, object, txgname, &zl_intsize, &zl_ints);
4142
4143 if (error == ENOENT)
4144 return;
4145
4038 ASSERT3U(error, ==, 0);
4146 ASSERT0(error);
4039
4040 tx = dmu_tx_create(os);
4041 dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
4042 txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
4043 if (txg == 0)
4044 return;
4045 VERIFY3U(0, ==, zap_remove(os, object, txgname, tx));
4046 VERIFY3U(0, ==, zap_remove(os, object, propname, tx));

--- 179 unchanged lines hidden (view full) ---

4226 if (data->zcd_txg > synced_txg)
4227 fatal(0, "commit callback of txg %" PRIu64 " called prematurely"
4228 ", last synced txg = %" PRIu64 "\n", data->zcd_txg,
4229 synced_txg);
4230
4231 data->zcd_called = B_TRUE;
4232
4233 if (error == ECANCELED) {
4147
4148 tx = dmu_tx_create(os);
4149 dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
4150 txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
4151 if (txg == 0)
4152 return;
4153 VERIFY3U(0, ==, zap_remove(os, object, txgname, tx));
4154 VERIFY3U(0, ==, zap_remove(os, object, propname, tx));

--- 179 unchanged lines hidden (view full) ---

4334 if (data->zcd_txg > synced_txg)
4335 fatal(0, "commit callback of txg %" PRIu64 " called prematurely"
4336 ", last synced txg = %" PRIu64 "\n", data->zcd_txg,
4337 synced_txg);
4338
4339 data->zcd_called = B_TRUE;
4340
4341 if (error == ECANCELED) {
4234 ASSERT3U(data->zcd_txg, ==, 0);
4342 ASSERT0(data->zcd_txg);
4235 ASSERT(!data->zcd_added);
4236
4237 /*
4238 * The private callback data should be destroyed here, but
4239 * since we are going to check the zcd_called field after
4240 * dmu_tx_abort(), we will destroy it there.
4241 */
4242 return;

--- 188 unchanged lines hidden (view full) ---

4431{
4432 nvlist_t *props = NULL;
4433
4434 (void) rw_rdlock(&ztest_name_lock);
4435
4436 (void) ztest_spa_prop_set_uint64(ZPOOL_PROP_DEDUPDITTO,
4437 ZIO_DEDUPDITTO_MIN + ztest_random(ZIO_DEDUPDITTO_MIN));
4438
4343 ASSERT(!data->zcd_added);
4344
4345 /*
4346 * The private callback data should be destroyed here, but
4347 * since we are going to check the zcd_called field after
4348 * dmu_tx_abort(), we will destroy it there.
4349 */
4350 return;

--- 188 unchanged lines hidden (view full) ---

4539{
4540 nvlist_t *props = NULL;
4541
4542 (void) rw_rdlock(&ztest_name_lock);
4543
4544 (void) ztest_spa_prop_set_uint64(ZPOOL_PROP_DEDUPDITTO,
4545 ZIO_DEDUPDITTO_MIN + ztest_random(ZIO_DEDUPDITTO_MIN));
4546
4439 VERIFY3U(spa_prop_get(ztest_spa, &props), ==, 0);
4547 VERIFY0(spa_prop_get(ztest_spa, &props));
4440
4441 if (ztest_opts.zo_verbose >= 6)
4442 dump_nvlist(props, 4);
4443
4444 nvlist_free(props);
4445
4446 (void) rw_unlock(&ztest_name_lock);
4447}

--- 406 unchanged lines hidden (view full) ---

4854 * Change the guid for the pool.
4855 */
4856/* ARGSUSED */
4857void
4858ztest_reguid(ztest_ds_t *zd, uint64_t id)
4859{
4860 spa_t *spa = ztest_spa;
4861 uint64_t orig, load;
4548
4549 if (ztest_opts.zo_verbose >= 6)
4550 dump_nvlist(props, 4);
4551
4552 nvlist_free(props);
4553
4554 (void) rw_unlock(&ztest_name_lock);
4555}

--- 406 unchanged lines hidden (view full) ---

4962 * Change the guid for the pool.
4963 */
4964/* ARGSUSED */
4965void
4966ztest_reguid(ztest_ds_t *zd, uint64_t id)
4967{
4968 spa_t *spa = ztest_spa;
4969 uint64_t orig, load;
4970 int error;
4862
4863 orig = spa_guid(spa);
4864 load = spa_load_guid(spa);
4971
4972 orig = spa_guid(spa);
4973 load = spa_load_guid(spa);
4865 if (spa_change_guid(spa) != 0)
4974
4975 (void) rw_wrlock(&ztest_name_lock);
4976 error = spa_change_guid(spa);
4977 (void) rw_unlock(&ztest_name_lock);
4978
4979 if (error != 0)
4866 return;
4867
4980 return;
4981
4868 if (ztest_opts.zo_verbose >= 3) {
4982 if (ztest_opts.zo_verbose >= 4) {
4869 (void) printf("Changed guid old %llu -> %llu\n",
4870 (u_longlong_t)orig, (u_longlong_t)spa_guid(spa));
4871 }
4872
4873 VERIFY3U(orig, !=, spa_guid(spa));
4874 VERIFY3U(load, ==, spa_load_guid(spa));
4875}
4876

--- 373 unchanged lines hidden (view full) ---

5250 error = ztest_dataset_create(name);
5251 if (error == ENOSPC) {
5252 (void) rw_unlock(&ztest_name_lock);
5253 ztest_record_enospc(FTAG);
5254 return (error);
5255 }
5256 ASSERT(error == 0 || error == EEXIST);
5257
4983 (void) printf("Changed guid old %llu -> %llu\n",
4984 (u_longlong_t)orig, (u_longlong_t)spa_guid(spa));
4985 }
4986
4987 VERIFY3U(orig, !=, spa_guid(spa));
4988 VERIFY3U(load, ==, spa_load_guid(spa));
4989}
4990

--- 373 unchanged lines hidden (view full) ---

5364 error = ztest_dataset_create(name);
5365 if (error == ENOSPC) {
5366 (void) rw_unlock(&ztest_name_lock);
5367 ztest_record_enospc(FTAG);
5368 return (error);
5369 }
5370 ASSERT(error == 0 || error == EEXIST);
5371
5258 VERIFY3U(dmu_objset_hold(name, zd, &os), ==, 0);
5372 VERIFY0(dmu_objset_hold(name, zd, &os));
5259 (void) rw_unlock(&ztest_name_lock);
5260
5261 ztest_zd_init(zd, ZTEST_GET_SHARED_DS(d), os);
5262
5263 zilog = zd->zd_zilog;
5264
5265 if (zilog->zl_header->zh_claim_lr_seq != 0 &&
5266 zilog->zl_header->zh_claim_lr_seq < committed_seq)

--- 267 unchanged lines hidden (view full) ---

5534 spa_close(spa, FTAG);
5535 kernel_fini();
5536
5537 /*
5538 * Open and close the pool and dataset to induce log replay.
5539 */
5540 kernel_init(FREAD | FWRITE);
5541 VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
5373 (void) rw_unlock(&ztest_name_lock);
5374
5375 ztest_zd_init(zd, ZTEST_GET_SHARED_DS(d), os);
5376
5377 zilog = zd->zd_zilog;
5378
5379 if (zilog->zl_header->zh_claim_lr_seq != 0 &&
5380 zilog->zl_header->zh_claim_lr_seq < committed_seq)

--- 267 unchanged lines hidden (view full) ---

5648 spa_close(spa, FTAG);
5649 kernel_fini();
5650
5651 /*
5652 * Open and close the pool and dataset to induce log replay.
5653 */
5654 kernel_init(FREAD | FWRITE);
5655 VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
5656 ASSERT(spa_freeze_txg(spa) == UINT64_MAX);
5542 VERIFY3U(0, ==, ztest_dataset_open(0));
5543 ztest_dataset_close(0);
5657 VERIFY3U(0, ==, ztest_dataset_open(0));
5658 ztest_dataset_close(0);
5659
5660 spa->spa_debug = B_TRUE;
5661 ztest_spa = spa;
5662 txg_wait_synced(spa_get_dsl(spa), 0);
5663 ztest_reguid(NULL, 0);
5664
5544 spa_close(spa, FTAG);
5545 kernel_fini();
5546}
5547
5548void
5549print_time(hrtime_t t, char *timebuf)
5550{
5551 hrtime_t s = t / NANOSEC;

--- 18 unchanged lines hidden (view full) ---

5570 (void) sprintf(timebuf, "%llus", s);
5571}
5572
5573static nvlist_t *
5574make_random_props()
5575{
5576 nvlist_t *props;
5577
5665 spa_close(spa, FTAG);
5666 kernel_fini();
5667}
5668
5669void
5670print_time(hrtime_t t, char *timebuf)
5671{
5672 hrtime_t s = t / NANOSEC;

--- 18 unchanged lines hidden (view full) ---

5691 (void) sprintf(timebuf, "%llus", s);
5692}
5693
5694static nvlist_t *
5695make_random_props()
5696{
5697 nvlist_t *props;
5698
5578 if (ztest_random(2) == 0)
5579 return (NULL);
5580
5581 VERIFY(nvlist_alloc(&props, NV_UNIQUE_NAME, 0) == 0);
5699 VERIFY(nvlist_alloc(&props, NV_UNIQUE_NAME, 0) == 0);
5700 if (ztest_random(2) == 0)
5701 return (props);
5582 VERIFY(nvlist_add_uint64(props, "autoreplace", 1) == 0);
5583
5584 return (props);
5585}
5586
5587/*
5588 * Create a storage pool with the given name and initial vdev size.
5589 * Then test spa_freeze() functionality.

--- 11 unchanged lines hidden (view full) ---

5601
5602 /*
5603 * Create the storage pool.
5604 */
5605 (void) spa_destroy(ztest_opts.zo_pool);
5606 ztest_shared->zs_vdev_next_leaf = 0;
5607 zs->zs_splits = 0;
5608 zs->zs_mirrors = ztest_opts.zo_mirrors;
5702 VERIFY(nvlist_add_uint64(props, "autoreplace", 1) == 0);
5703
5704 return (props);
5705}
5706
5707/*
5708 * Create a storage pool with the given name and initial vdev size.
5709 * Then test spa_freeze() functionality.

--- 11 unchanged lines hidden (view full) ---

5721
5722 /*
5723 * Create the storage pool.
5724 */
5725 (void) spa_destroy(ztest_opts.zo_pool);
5726 ztest_shared->zs_vdev_next_leaf = 0;
5727 zs->zs_splits = 0;
5728 zs->zs_mirrors = ztest_opts.zo_mirrors;
5609 nvroot = make_vdev_root(NULL, NULL, ztest_opts.zo_vdev_size, 0,
5729 nvroot = make_vdev_root(NULL, NULL, NULL, ztest_opts.zo_vdev_size, 0,
5610 0, ztest_opts.zo_raidz, zs->zs_mirrors, 1);
5611 props = make_random_props();
5730 0, ztest_opts.zo_raidz, zs->zs_mirrors, 1);
5731 props = make_random_props();
5732 for (int i = 0; i < SPA_FEATURES; i++) {
5733 char buf[1024];
5734 (void) snprintf(buf, sizeof (buf), "feature@%s",
5735 spa_feature_table[i].fi_uname);
5736 VERIFY3U(0, ==, nvlist_add_uint64(props, buf, 0));
5737 }
5612 VERIFY3U(0, ==, spa_create(ztest_opts.zo_pool, nvroot, props,
5613 NULL, NULL));
5614 nvlist_free(nvroot);
5615
5616 VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
5617 zs->zs_metaslab_sz =
5618 1ULL << spa->spa_root_vdev->vdev_child[0]->vdev_ms_shift;
5738 VERIFY3U(0, ==, spa_create(ztest_opts.zo_pool, nvroot, props,
5739 NULL, NULL));
5740 nvlist_free(nvroot);
5741
5742 VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
5743 zs->zs_metaslab_sz =
5744 1ULL << spa->spa_root_vdev->vdev_child[0]->vdev_ms_shift;
5745
5619 spa_close(spa, FTAG);
5620
5621 kernel_fini();
5622
5623 ztest_run_zdb(ztest_opts.zo_pool);
5624
5625 ztest_freeze();
5626

--- 22 unchanged lines hidden (view full) ---

5649 fd = mkstemp(tmp);
5650 ASSERT3U(fd, ==, ZTEST_FD_DATA);
5651#endif
5652
5653 fd = open("/dev/urandom", O_RDONLY);
5654 ASSERT3U(fd, ==, ZTEST_FD_RAND);
5655}
5656
5746 spa_close(spa, FTAG);
5747
5748 kernel_fini();
5749
5750 ztest_run_zdb(ztest_opts.zo_pool);
5751
5752 ztest_freeze();
5753

--- 22 unchanged lines hidden (view full) ---

5776 fd = mkstemp(tmp);
5777 ASSERT3U(fd, ==, ZTEST_FD_DATA);
5778#endif
5779
5780 fd = open("/dev/urandom", O_RDONLY);
5781 ASSERT3U(fd, ==, ZTEST_FD_RAND);
5782}
5783
5784static int
5785shared_data_size(ztest_shared_hdr_t *hdr)
5786{
5787 int size;
5788
5789 size = hdr->zh_hdr_size;
5790 size += hdr->zh_opts_size;
5791 size += hdr->zh_size;
5792 size += hdr->zh_stats_size * hdr->zh_stats_count;
5793 size += hdr->zh_ds_size * hdr->zh_ds_count;
5794
5795 return (size);
5796}
5797
5657static void
5658setup_hdr(void)
5659{
5798static void
5799setup_hdr(void)
5800{
5801 int size;
5660 ztest_shared_hdr_t *hdr;
5661
5662#ifndef illumos
5663 pwrite(ZTEST_FD_DATA, "", 1, 0);
5664#endif
5665
5666 hdr = (void *)mmap(0, P2ROUNDUP(sizeof (*hdr), getpagesize()),
5667 PROT_READ | PROT_WRITE, MAP_SHARED, ZTEST_FD_DATA, 0);
5668 ASSERT(hdr != MAP_FAILED);
5669
5802 ztest_shared_hdr_t *hdr;
5803
5804#ifndef illumos
5805 pwrite(ZTEST_FD_DATA, "", 1, 0);
5806#endif
5807
5808 hdr = (void *)mmap(0, P2ROUNDUP(sizeof (*hdr), getpagesize()),
5809 PROT_READ | PROT_WRITE, MAP_SHARED, ZTEST_FD_DATA, 0);
5810 ASSERT(hdr != MAP_FAILED);
5811
5812 VERIFY3U(0, ==, ftruncate(ZTEST_FD_DATA, sizeof (ztest_shared_hdr_t)));
5813
5670 hdr->zh_hdr_size = sizeof (ztest_shared_hdr_t);
5671 hdr->zh_opts_size = sizeof (ztest_shared_opts_t);
5672 hdr->zh_size = sizeof (ztest_shared_t);
5673 hdr->zh_stats_size = sizeof (ztest_shared_callstate_t);
5674 hdr->zh_stats_count = ZTEST_FUNCS;
5675 hdr->zh_ds_size = sizeof (ztest_shared_ds_t);
5676 hdr->zh_ds_count = ztest_opts.zo_datasets;
5677
5814 hdr->zh_hdr_size = sizeof (ztest_shared_hdr_t);
5815 hdr->zh_opts_size = sizeof (ztest_shared_opts_t);
5816 hdr->zh_size = sizeof (ztest_shared_t);
5817 hdr->zh_stats_size = sizeof (ztest_shared_callstate_t);
5818 hdr->zh_stats_count = ZTEST_FUNCS;
5819 hdr->zh_ds_size = sizeof (ztest_shared_ds_t);
5820 hdr->zh_ds_count = ztest_opts.zo_datasets;
5821
5822 size = shared_data_size(hdr);
5823 VERIFY3U(0, ==, ftruncate(ZTEST_FD_DATA, size));
5824
5678 (void) munmap((caddr_t)hdr, P2ROUNDUP(sizeof (*hdr), getpagesize()));
5679}
5680
5681static void
5682setup_data(void)
5683{
5684 int size, offset;
5685 ztest_shared_hdr_t *hdr;
5686 uint8_t *buf;
5687
5688 hdr = (void *)mmap(0, P2ROUNDUP(sizeof (*hdr), getpagesize()),
5689 PROT_READ, MAP_SHARED, ZTEST_FD_DATA, 0);
5690 ASSERT(hdr != MAP_FAILED);
5691
5825 (void) munmap((caddr_t)hdr, P2ROUNDUP(sizeof (*hdr), getpagesize()));
5826}
5827
5828static void
5829setup_data(void)
5830{
5831 int size, offset;
5832 ztest_shared_hdr_t *hdr;
5833 uint8_t *buf;
5834
5835 hdr = (void *)mmap(0, P2ROUNDUP(sizeof (*hdr), getpagesize()),
5836 PROT_READ, MAP_SHARED, ZTEST_FD_DATA, 0);
5837 ASSERT(hdr != MAP_FAILED);
5838
5692 size = hdr->zh_hdr_size;
5693 size += hdr->zh_opts_size;
5694 size += hdr->zh_size;
5695 size += hdr->zh_stats_size * hdr->zh_stats_count;
5696 size += hdr->zh_ds_size * hdr->zh_ds_count;
5839 size = shared_data_size(hdr);
5697
5698 (void) munmap((caddr_t)hdr, P2ROUNDUP(sizeof (*hdr), getpagesize()));
5699 hdr = ztest_shared_hdr = (void *)mmap(0, P2ROUNDUP(size, getpagesize()),
5700 PROT_READ | PROT_WRITE, MAP_SHARED, ZTEST_FD_DATA, 0);
5701 ASSERT(hdr != MAP_FAILED);
5702 buf = (uint8_t *)hdr;
5703
5704 offset = hdr->zh_hdr_size;

--- 107 unchanged lines hidden (view full) ---

5812 char cmd[MAXNAMELEN];
5813 boolean_t hasalt;
5814
5815 boolean_t ischild = (0 == lseek(ZTEST_FD_DATA, 0, SEEK_CUR));
5816 ASSERT(ischild || errno == EBADF);
5817
5818 (void) setvbuf(stdout, NULL, _IOLBF, 0);
5819
5840
5841 (void) munmap((caddr_t)hdr, P2ROUNDUP(sizeof (*hdr), getpagesize()));
5842 hdr = ztest_shared_hdr = (void *)mmap(0, P2ROUNDUP(size, getpagesize()),
5843 PROT_READ | PROT_WRITE, MAP_SHARED, ZTEST_FD_DATA, 0);
5844 ASSERT(hdr != MAP_FAILED);
5845 buf = (uint8_t *)hdr;
5846
5847 offset = hdr->zh_hdr_size;

--- 107 unchanged lines hidden (view full) ---

5955 char cmd[MAXNAMELEN];
5956 boolean_t hasalt;
5957
5958 boolean_t ischild = (0 == lseek(ZTEST_FD_DATA, 0, SEEK_CUR));
5959 ASSERT(ischild || errno == EBADF);
5960
5961 (void) setvbuf(stdout, NULL, _IOLBF, 0);
5962
5963 dprintf_setup(&argc, argv);
5964
5820 if (!ischild) {
5821 process_options(argc, argv);
5822
5823 setup_fds();
5824 setup_hdr();
5825 setup_data();
5826 bcopy(&ztest_opts, ztest_shared_opts,
5827 sizeof (*ztest_shared_opts));

--- 180 unchanged lines hidden ---
5965 if (!ischild) {
5966 process_options(argc, argv);
5967
5968 setup_fds();
5969 setup_hdr();
5970 setup_data();
5971 bcopy(&ztest_opts, ztest_shared_opts,
5972 sizeof (*ztest_shared_opts));

--- 180 unchanged lines hidden ---