Deleted Added
full compact
ztest.c (208047) ztest.c (209962)
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

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

71 * This can be useful when you're trying to distinguish temporal incursions
72 * from plain old race conditions.
73 */
74
75#include <sys/zfs_context.h>
76#include <sys/spa.h>
77#include <sys/dmu.h>
78#include <sys/txg.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

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

71 * This can be useful when you're trying to distinguish temporal incursions
72 * from plain old race conditions.
73 */
74
75#include <sys/zfs_context.h>
76#include <sys/spa.h>
77#include <sys/dmu.h>
78#include <sys/txg.h>
79#include <sys/dbuf.h>
79#include <sys/zap.h>
80#include <sys/dmu_objset.h>
81#include <sys/poll.h>
82#include <sys/stat.h>
83#include <sys/time.h>
84#include <sys/wait.h>
85#include <sys/mman.h>
86#include <sys/resource.h>

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

160} ztest_args_t;
161
162typedef void ztest_func_t(ztest_args_t *);
163
164/*
165 * Note: these aren't static because we want dladdr() to work.
166 */
167ztest_func_t ztest_dmu_read_write;
80#include <sys/zap.h>
81#include <sys/dmu_objset.h>
82#include <sys/poll.h>
83#include <sys/stat.h>
84#include <sys/time.h>
85#include <sys/wait.h>
86#include <sys/mman.h>
87#include <sys/resource.h>

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

161} ztest_args_t;
162
163typedef void ztest_func_t(ztest_args_t *);
164
165/*
166 * Note: these aren't static because we want dladdr() to work.
167 */
168ztest_func_t ztest_dmu_read_write;
169ztest_func_t ztest_dmu_read_write_zcopy;
168ztest_func_t ztest_dmu_write_parallel;
169ztest_func_t ztest_dmu_object_alloc_free;
170ztest_func_t ztest_zap;
170ztest_func_t ztest_dmu_write_parallel;
171ztest_func_t ztest_dmu_object_alloc_free;
172ztest_func_t ztest_zap;
173ztest_func_t ztest_fzap;
171ztest_func_t ztest_zap_parallel;
172ztest_func_t ztest_traverse;
173ztest_func_t ztest_dsl_prop_get_set;
174ztest_func_t ztest_dmu_objset_create_destroy;
175ztest_func_t ztest_dmu_snapshot_create_destroy;
176ztest_func_t ztest_dsl_dataset_promote_busy;
177ztest_func_t ztest_spa_create_destroy;
178ztest_func_t ztest_fault_inject;

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

195
196uint64_t zopt_always = 0; /* all the time */
197uint64_t zopt_often = 1; /* every second */
198uint64_t zopt_sometimes = 10; /* every 10 seconds */
199uint64_t zopt_rarely = 60; /* every 60 seconds */
200
201ztest_info_t ztest_info[] = {
202 { ztest_dmu_read_write, 1, &zopt_always },
174ztest_func_t ztest_zap_parallel;
175ztest_func_t ztest_traverse;
176ztest_func_t ztest_dsl_prop_get_set;
177ztest_func_t ztest_dmu_objset_create_destroy;
178ztest_func_t ztest_dmu_snapshot_create_destroy;
179ztest_func_t ztest_dsl_dataset_promote_busy;
180ztest_func_t ztest_spa_create_destroy;
181ztest_func_t ztest_fault_inject;

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

198
199uint64_t zopt_always = 0; /* all the time */
200uint64_t zopt_often = 1; /* every second */
201uint64_t zopt_sometimes = 10; /* every 10 seconds */
202uint64_t zopt_rarely = 60; /* every 60 seconds */
203
204ztest_info_t ztest_info[] = {
205 { ztest_dmu_read_write, 1, &zopt_always },
206 { ztest_dmu_read_write_zcopy, 1, &zopt_always },
203 { ztest_dmu_write_parallel, 30, &zopt_always },
204 { ztest_dmu_object_alloc_free, 1, &zopt_always },
205 { ztest_zap, 30, &zopt_always },
207 { ztest_dmu_write_parallel, 30, &zopt_always },
208 { ztest_dmu_object_alloc_free, 1, &zopt_always },
209 { ztest_zap, 30, &zopt_always },
210 { ztest_fzap, 30, &zopt_always },
206 { ztest_zap_parallel, 100, &zopt_always },
207 { ztest_dsl_prop_get_set, 1, &zopt_sometimes },
208 { ztest_dmu_objset_create_destroy, 1, &zopt_sometimes },
209 { ztest_dmu_snapshot_create_destroy, 1, &zopt_sometimes },
211 { ztest_zap_parallel, 100, &zopt_always },
212 { ztest_dsl_prop_get_set, 1, &zopt_sometimes },
213 { ztest_dmu_objset_create_destroy, 1, &zopt_sometimes },
214 { ztest_dmu_snapshot_create_destroy, 1, &zopt_sometimes },
210 { ztest_dsl_dataset_promote_busy, 1, &zopt_sometimes },
211 { ztest_spa_create_destroy, 1, &zopt_sometimes },
212 { ztest_fault_inject, 1, &zopt_sometimes },
213 { ztest_spa_rename, 1, &zopt_rarely },
214 { ztest_vdev_attach_detach, 1, &zopt_rarely },
215 { ztest_vdev_LUN_growth, 1, &zopt_rarely },
215 { ztest_spa_create_destroy, 1, &zopt_sometimes },
216 { ztest_fault_inject, 1, &zopt_sometimes },
217 { ztest_spa_rename, 1, &zopt_rarely },
218 { ztest_vdev_attach_detach, 1, &zopt_rarely },
219 { ztest_vdev_LUN_growth, 1, &zopt_rarely },
220 { ztest_dsl_dataset_promote_busy, 1, &zopt_rarely },
216 { ztest_vdev_add_remove, 1, &zopt_vdevtime },
217 { ztest_vdev_aux_add_remove, 1, &zopt_vdevtime },
218 { ztest_scrub, 1, &zopt_vdevtime },
219};
220
221#define ZTEST_FUNCS (sizeof (ztest_info) / sizeof (ztest_info_t))
222
223#define ZTEST_SYNC_LOCKS 16

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

242
243static char ztest_dev_template[] = "%s/%s.%llua";
244static char ztest_aux_template[] = "%s/%s.%s.%llu";
245static ztest_shared_t *ztest_shared;
246
247static int ztest_random_fd;
248static int ztest_dump_core = 1;
249
221 { ztest_vdev_add_remove, 1, &zopt_vdevtime },
222 { ztest_vdev_aux_add_remove, 1, &zopt_vdevtime },
223 { ztest_scrub, 1, &zopt_vdevtime },
224};
225
226#define ZTEST_FUNCS (sizeof (ztest_info) / sizeof (ztest_info_t))
227
228#define ZTEST_SYNC_LOCKS 16

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

247
248static char ztest_dev_template[] = "%s/%s.%llua";
249static char ztest_aux_template[] = "%s/%s.%s.%llu";
250static ztest_shared_t *ztest_shared;
251
252static int ztest_random_fd;
253static int ztest_dump_core = 1;
254
255static uint64_t metaslab_sz;
250static boolean_t ztest_exiting;
251
252extern uint64_t metaslab_gang_bang;
256static boolean_t ztest_exiting;
257
258extern uint64_t metaslab_gang_bang;
259extern uint64_t metaslab_df_alloc_threshold;
253
254#define ZTEST_DIROBJ 1
255#define ZTEST_MICROZAP_OBJ 2
256#define ZTEST_FATZAP_OBJ 3
257
258#define ZTEST_DIROBJ_BLOCKSIZE (1 << 10)
259#define ZTEST_DIRSIZE 256
260

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

419 return (0);
420
421 if (read(ztest_random_fd, &r, sizeof (r)) != sizeof (r))
422 fatal(1, "short read from /dev/urandom");
423
424 return (r % range);
425}
426
260
261#define ZTEST_DIROBJ 1
262#define ZTEST_MICROZAP_OBJ 2
263#define ZTEST_FATZAP_OBJ 3
264
265#define ZTEST_DIROBJ_BLOCKSIZE (1 << 10)
266#define ZTEST_DIRSIZE 256
267

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

426 return (0);
427
428 if (read(ztest_random_fd, &r, sizeof (r)) != sizeof (r))
429 fatal(1, "short read from /dev/urandom");
430
431 return (r % range);
432}
433
434/* ARGSUSED */
427static void
428ztest_record_enospc(char *s)
429{
435static void
436ztest_record_enospc(char *s)
437{
430 dprintf("ENOSPC doing: %s\n", s ? s : "<unknown>");
431 ztest_shared->zs_enospc_count++;
432}
433
434static void
435process_options(int argc, char **argv)
436{
437 int opt;
438 uint64_t value;

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

701}
702
703static uint8_t
704ztest_random_compress(void)
705{
706 return ((uint8_t)ztest_random(ZIO_COMPRESS_FUNCTIONS));
707}
708
438 ztest_shared->zs_enospc_count++;
439}
440
441static void
442process_options(int argc, char **argv)
443{
444 int opt;
445 uint64_t value;

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

708}
709
710static uint8_t
711ztest_random_compress(void)
712{
713 return ((uint8_t)ztest_random(ZIO_COMPRESS_FUNCTIONS));
714}
715
709typedef struct ztest_replay {
710 objset_t *zr_os;
711 uint64_t zr_assign;
712} ztest_replay_t;
713
714static int
716static int
715ztest_replay_create(ztest_replay_t *zr, lr_create_t *lr, boolean_t byteswap)
717ztest_replay_create(objset_t *os, lr_create_t *lr, boolean_t byteswap)
716{
718{
717 objset_t *os = zr->zr_os;
718 dmu_tx_t *tx;
719 int error;
720
721 if (byteswap)
722 byteswap_uint64_array(lr, sizeof (*lr));
723
724 tx = dmu_tx_create(os);
725 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
719 dmu_tx_t *tx;
720 int error;
721
722 if (byteswap)
723 byteswap_uint64_array(lr, sizeof (*lr));
724
725 tx = dmu_tx_create(os);
726 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
726 error = dmu_tx_assign(tx, zr->zr_assign);
727 error = dmu_tx_assign(tx, TXG_WAIT);
727 if (error) {
728 dmu_tx_abort(tx);
729 return (error);
730 }
731
732 error = dmu_object_claim(os, lr->lr_doid, lr->lr_mode, 0,
733 DMU_OT_NONE, 0, tx);
734 ASSERT3U(error, ==, 0);
735 dmu_tx_commit(tx);
736
737 if (zopt_verbose >= 5) {
738 char osname[MAXNAMELEN];
739 dmu_objset_name(os, osname);
740 (void) printf("replay create of %s object %llu"
741 " in txg %llu = %d\n",
742 osname, (u_longlong_t)lr->lr_doid,
728 if (error) {
729 dmu_tx_abort(tx);
730 return (error);
731 }
732
733 error = dmu_object_claim(os, lr->lr_doid, lr->lr_mode, 0,
734 DMU_OT_NONE, 0, tx);
735 ASSERT3U(error, ==, 0);
736 dmu_tx_commit(tx);
737
738 if (zopt_verbose >= 5) {
739 char osname[MAXNAMELEN];
740 dmu_objset_name(os, osname);
741 (void) printf("replay create of %s object %llu"
742 " in txg %llu = %d\n",
743 osname, (u_longlong_t)lr->lr_doid,
743 (u_longlong_t)zr->zr_assign, error);
744 (u_longlong_t)dmu_tx_get_txg(tx), error);
744 }
745
746 return (error);
747}
748
749static int
745 }
746
747 return (error);
748}
749
750static int
750ztest_replay_remove(ztest_replay_t *zr, lr_remove_t *lr, boolean_t byteswap)
751ztest_replay_remove(objset_t *os, lr_remove_t *lr, boolean_t byteswap)
751{
752{
752 objset_t *os = zr->zr_os;
753 dmu_tx_t *tx;
754 int error;
755
756 if (byteswap)
757 byteswap_uint64_array(lr, sizeof (*lr));
758
759 tx = dmu_tx_create(os);
760 dmu_tx_hold_free(tx, lr->lr_doid, 0, DMU_OBJECT_END);
753 dmu_tx_t *tx;
754 int error;
755
756 if (byteswap)
757 byteswap_uint64_array(lr, sizeof (*lr));
758
759 tx = dmu_tx_create(os);
760 dmu_tx_hold_free(tx, lr->lr_doid, 0, DMU_OBJECT_END);
761 error = dmu_tx_assign(tx, zr->zr_assign);
761 error = dmu_tx_assign(tx, TXG_WAIT);
762 if (error) {
763 dmu_tx_abort(tx);
764 return (error);
765 }
766
767 error = dmu_object_free(os, lr->lr_doid, tx);
768 dmu_tx_commit(tx);
769

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

779 ztest_replay_remove, /* TX_REMOVE */
780 NULL, /* TX_RMDIR */
781 NULL, /* TX_LINK */
782 NULL, /* TX_RENAME */
783 NULL, /* TX_WRITE */
784 NULL, /* TX_TRUNCATE */
785 NULL, /* TX_SETATTR */
786 NULL, /* TX_ACL */
762 if (error) {
763 dmu_tx_abort(tx);
764 return (error);
765 }
766
767 error = dmu_object_free(os, lr->lr_doid, tx);
768 dmu_tx_commit(tx);
769

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

779 ztest_replay_remove, /* TX_REMOVE */
780 NULL, /* TX_RMDIR */
781 NULL, /* TX_LINK */
782 NULL, /* TX_RENAME */
783 NULL, /* TX_WRITE */
784 NULL, /* TX_TRUNCATE */
785 NULL, /* TX_SETATTR */
786 NULL, /* TX_ACL */
787 NULL, /* TX_CREATE_ACL */
788 NULL, /* TX_CREATE_ATTR */
789 NULL, /* TX_CREATE_ACL_ATTR */
790 NULL, /* TX_MKDIR_ACL */
791 NULL, /* TX_MKDIR_ATTR */
792 NULL, /* TX_MKDIR_ACL_ATTR */
793 NULL, /* TX_WRITE2 */
787};
788
789/*
790 * Verify that we can't destroy an active pool, create an existing pool,
791 * or create a pool with a bad vdev spec.
792 */
793void
794ztest_spa_create_destroy(ztest_args_t *za)

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

980 spa_t *spa = za->za_spa;
981 spa_aux_vdev_t *sav = &spa->spa_spares;
982 vdev_t *rvd = spa->spa_root_vdev;
983 vdev_t *oldvd, *newvd, *pvd;
984 nvlist_t *root;
985 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz;
986 uint64_t leaf, top;
987 uint64_t ashift = ztest_get_ashift();
794};
795
796/*
797 * Verify that we can't destroy an active pool, create an existing pool,
798 * or create a pool with a bad vdev spec.
799 */
800void
801ztest_spa_create_destroy(ztest_args_t *za)

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

987 spa_t *spa = za->za_spa;
988 spa_aux_vdev_t *sav = &spa->spa_spares;
989 vdev_t *rvd = spa->spa_root_vdev;
990 vdev_t *oldvd, *newvd, *pvd;
991 nvlist_t *root;
992 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz;
993 uint64_t leaf, top;
994 uint64_t ashift = ztest_get_ashift();
988 uint64_t oldguid;
995 uint64_t oldguid, pguid;
989 size_t oldsize, newsize;
990 char oldpath[MAXPATHLEN], newpath[MAXPATHLEN];
991 int replacing;
992 int oldvd_has_siblings = B_FALSE;
993 int newvd_is_spare = B_FALSE;
994 int oldvd_is_log;
995 int error, expected_error;
996

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

1012 * Pick a random leaf within it.
1013 */
1014 leaf = ztest_random(leaves);
1015
1016 /*
1017 * Locate this vdev.
1018 */
1019 oldvd = rvd->vdev_child[top];
996 size_t oldsize, newsize;
997 char oldpath[MAXPATHLEN], newpath[MAXPATHLEN];
998 int replacing;
999 int oldvd_has_siblings = B_FALSE;
1000 int newvd_is_spare = B_FALSE;
1001 int oldvd_is_log;
1002 int error, expected_error;
1003

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

1019 * Pick a random leaf within it.
1020 */
1021 leaf = ztest_random(leaves);
1022
1023 /*
1024 * Locate this vdev.
1025 */
1026 oldvd = rvd->vdev_child[top];
1020 if (zopt_mirrors >= 1)
1027 if (zopt_mirrors >= 1) {
1028 ASSERT(oldvd->vdev_ops == &vdev_mirror_ops);
1029 ASSERT(oldvd->vdev_children >= zopt_mirrors);
1021 oldvd = oldvd->vdev_child[leaf / zopt_raidz];
1030 oldvd = oldvd->vdev_child[leaf / zopt_raidz];
1022 if (zopt_raidz > 1)
1031 }
1032 if (zopt_raidz > 1) {
1033 ASSERT(oldvd->vdev_ops == &vdev_raidz_ops);
1034 ASSERT(oldvd->vdev_children == zopt_raidz);
1023 oldvd = oldvd->vdev_child[leaf % zopt_raidz];
1035 oldvd = oldvd->vdev_child[leaf % zopt_raidz];
1036 }
1024
1025 /*
1026 * If we're already doing an attach or replace, oldvd may be a
1027 * mirror vdev -- in which case, pick a random child.
1028 */
1029 while (oldvd->vdev_children != 0) {
1030 oldvd_has_siblings = B_TRUE;
1037
1038 /*
1039 * If we're already doing an attach or replace, oldvd may be a
1040 * mirror vdev -- in which case, pick a random child.
1041 */
1042 while (oldvd->vdev_children != 0) {
1043 oldvd_has_siblings = B_TRUE;
1031 ASSERT(oldvd->vdev_children == 2);
1032 oldvd = oldvd->vdev_child[ztest_random(2)];
1044 ASSERT(oldvd->vdev_children >= 2);
1045 oldvd = oldvd->vdev_child[ztest_random(oldvd->vdev_children)];
1033 }
1034
1035 oldguid = oldvd->vdev_guid;
1036 oldsize = vdev_get_rsize(oldvd);
1037 oldvd_is_log = oldvd->vdev_top->vdev_islog;
1038 (void) strcpy(oldpath, oldvd->vdev_path);
1039 pvd = oldvd->vdev_parent;
1046 }
1047
1048 oldguid = oldvd->vdev_guid;
1049 oldsize = vdev_get_rsize(oldvd);
1050 oldvd_is_log = oldvd->vdev_top->vdev_islog;
1051 (void) strcpy(oldpath, oldvd->vdev_path);
1052 pvd = oldvd->vdev_parent;
1053 pguid = pvd->vdev_guid;
1040
1041 /*
1042 * If oldvd has siblings, then half of the time, detach it.
1043 */
1044 if (oldvd_has_siblings && ztest_random(2) == 0) {
1045 spa_config_exit(spa, SCL_VDEV, FTAG);
1054
1055 /*
1056 * If oldvd has siblings, then half of the time, detach it.
1057 */
1058 if (oldvd_has_siblings && ztest_random(2) == 0) {
1059 spa_config_exit(spa, SCL_VDEV, FTAG);
1046 error = spa_vdev_detach(spa, oldguid, B_FALSE);
1047 if (error != 0 && error != ENODEV && error != EBUSY)
1048 fatal(0, "detach (%s) returned %d",
1049 oldpath, error);
1060 error = spa_vdev_detach(spa, oldguid, pguid, B_FALSE);
1061 if (error != 0 && error != ENODEV && error != EBUSY &&
1062 error != ENOTSUP)
1063 fatal(0, "detach (%s) returned %d", oldpath, error);
1050 (void) mutex_unlock(&ztest_shared->zs_vdev_lock);
1051 return;
1052 }
1053
1054 /*
1055 * For the new vdev, choose with equal probability between the two
1056 * standard paths (ending in either 'a' or 'b') or a random hot spare.
1057 */

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

1141 }
1142
1143 (void) mutex_unlock(&ztest_shared->zs_vdev_lock);
1144}
1145
1146/*
1147 * Verify that dynamic LUN growth works as expected.
1148 */
1064 (void) mutex_unlock(&ztest_shared->zs_vdev_lock);
1065 return;
1066 }
1067
1068 /*
1069 * For the new vdev, choose with equal probability between the two
1070 * standard paths (ending in either 'a' or 'b') or a random hot spare.
1071 */

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

1155 }
1156
1157 (void) mutex_unlock(&ztest_shared->zs_vdev_lock);
1158}
1159
1160/*
1161 * Verify that dynamic LUN growth works as expected.
1162 */
1149/* ARGSUSED */
1150void
1151ztest_vdev_LUN_growth(ztest_args_t *za)
1152{
1153 spa_t *spa = za->za_spa;
1154 char dev_name[MAXPATHLEN];
1155 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz;
1156 uint64_t vdev;
1157 size_t fsize;

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

1281{
1282 int error;
1283 objset_t *os, *os2;
1284 char name[100];
1285 int basemode, expected_error;
1286 zilog_t *zilog;
1287 uint64_t seq;
1288 uint64_t objects;
1163void
1164ztest_vdev_LUN_growth(ztest_args_t *za)
1165{
1166 spa_t *spa = za->za_spa;
1167 char dev_name[MAXPATHLEN];
1168 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz;
1169 uint64_t vdev;
1170 size_t fsize;

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

1294{
1295 int error;
1296 objset_t *os, *os2;
1297 char name[100];
1298 int basemode, expected_error;
1299 zilog_t *zilog;
1300 uint64_t seq;
1301 uint64_t objects;
1289 ztest_replay_t zr;
1290
1291 (void) rw_rdlock(&ztest_shared->zs_name_lock);
1292 (void) snprintf(name, 100, "%s/%s_temp_%llu", za->za_pool, za->za_pool,
1293 (u_longlong_t)za->za_instance);
1294
1295 basemode = DS_MODE_TYPE(za->za_instance);
1296 if (basemode != DS_MODE_USER && basemode != DS_MODE_OWNER)
1297 basemode = DS_MODE_USER;
1298
1299 /*
1300 * If this dataset exists from a previous run, process its replay log
1301 * half of the time. If we don't replay it, then dmu_objset_destroy()
1302 * (invoked from ztest_destroy_cb() below) should just throw it away.
1303 */
1304 if (ztest_random(2) == 0 &&
1305 dmu_objset_open(name, DMU_OST_OTHER, DS_MODE_OWNER, &os) == 0) {
1302
1303 (void) rw_rdlock(&ztest_shared->zs_name_lock);
1304 (void) snprintf(name, 100, "%s/%s_temp_%llu", za->za_pool, za->za_pool,
1305 (u_longlong_t)za->za_instance);
1306
1307 basemode = DS_MODE_TYPE(za->za_instance);
1308 if (basemode != DS_MODE_USER && basemode != DS_MODE_OWNER)
1309 basemode = DS_MODE_USER;
1310
1311 /*
1312 * If this dataset exists from a previous run, process its replay log
1313 * half of the time. If we don't replay it, then dmu_objset_destroy()
1314 * (invoked from ztest_destroy_cb() below) should just throw it away.
1315 */
1316 if (ztest_random(2) == 0 &&
1317 dmu_objset_open(name, DMU_OST_OTHER, DS_MODE_OWNER, &os) == 0) {
1306 zr.zr_os = os;
1307 zil_replay(os, &zr, &zr.zr_assign, ztest_replay_vector, NULL);
1318 zil_replay(os, os, ztest_replay_vector);
1308 dmu_objset_close(os);
1309 }
1310
1311 /*
1312 * There may be an old instance of the dataset we're about to
1313 * create lying around from a previous run. If so, destroy it
1314 * and all of its snapshots.
1315 */

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

1431 (void) rw_rdlock(&ztest_shared->zs_name_lock);
1432 dmu_objset_name(os, osname);
1433 (void) snprintf(snapname, 100, "%s@%llu", osname,
1434 (u_longlong_t)za->za_instance);
1435
1436 error = dmu_objset_destroy(snapname);
1437 if (error != 0 && error != ENOENT)
1438 fatal(0, "dmu_objset_destroy() = %d", error);
1319 dmu_objset_close(os);
1320 }
1321
1322 /*
1323 * There may be an old instance of the dataset we're about to
1324 * create lying around from a previous run. If so, destroy it
1325 * and all of its snapshots.
1326 */

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

1442 (void) rw_rdlock(&ztest_shared->zs_name_lock);
1443 dmu_objset_name(os, osname);
1444 (void) snprintf(snapname, 100, "%s@%llu", osname,
1445 (u_longlong_t)za->za_instance);
1446
1447 error = dmu_objset_destroy(snapname);
1448 if (error != 0 && error != ENOENT)
1449 fatal(0, "dmu_objset_destroy() = %d", error);
1439 error = dmu_objset_snapshot(osname, strchr(snapname, '@')+1, FALSE);
1450 error = dmu_objset_snapshot(osname, strchr(snapname, '@')+1,
1451 NULL, FALSE);
1440 if (error == ENOSPC)
1441 ztest_record_enospc("dmu_take_snapshot");
1442 else if (error != 0 && error != EEXIST)
1443 fatal(0, "dmu_take_snapshot() = %d", error);
1444 (void) rw_unlock(&ztest_shared->zs_name_lock);
1445}
1446
1447/*

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

1469
1470 dmu_objset_name(os, osname);
1471 (void) snprintf(snap1name, 100, "%s@s1_%llu", osname, curval++);
1472 (void) snprintf(clone1name, 100, "%s/c1_%llu", osname, curval++);
1473 (void) snprintf(snap2name, 100, "%s@s2_%llu", clone1name, curval++);
1474 (void) snprintf(clone2name, 100, "%s/c2_%llu", osname, curval++);
1475 (void) snprintf(snap3name, 100, "%s@s3_%llu", clone1name, curval++);
1476
1452 if (error == ENOSPC)
1453 ztest_record_enospc("dmu_take_snapshot");
1454 else if (error != 0 && error != EEXIST)
1455 fatal(0, "dmu_take_snapshot() = %d", error);
1456 (void) rw_unlock(&ztest_shared->zs_name_lock);
1457}
1458
1459/*

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

1481
1482 dmu_objset_name(os, osname);
1483 (void) snprintf(snap1name, 100, "%s@s1_%llu", osname, curval++);
1484 (void) snprintf(clone1name, 100, "%s/c1_%llu", osname, curval++);
1485 (void) snprintf(snap2name, 100, "%s@s2_%llu", clone1name, curval++);
1486 (void) snprintf(clone2name, 100, "%s/c2_%llu", osname, curval++);
1487 (void) snprintf(snap3name, 100, "%s@s3_%llu", clone1name, curval++);
1488
1477 error = dmu_objset_snapshot(osname, strchr(snap1name, '@')+1, FALSE);
1478 if (error == ENOSPC)
1479 ztest_record_enospc("dmu_take_snapshot");
1480 else if (error != 0 && error != EEXIST)
1481 fatal(0, "dmu_take_snapshot = %d", error);
1489 error = dmu_objset_snapshot(osname, strchr(snap1name, '@')+1,
1490 NULL, FALSE);
1491 if (error && error != EEXIST) {
1492 if (error == ENOSPC) {
1493 ztest_record_enospc(FTAG);
1494 goto out;
1495 }
1496 fatal(0, "dmu_take_snapshot(%s) = %d", snap1name, error);
1497 }
1482
1483 error = dmu_objset_open(snap1name, DMU_OST_OTHER,
1484 DS_MODE_USER | DS_MODE_READONLY, &clone);
1485 if (error)
1486 fatal(0, "dmu_open_snapshot(%s) = %d", snap1name, error);
1487
1488 error = dmu_objset_create(clone1name, DMU_OST_OTHER, clone, 0,
1489 NULL, NULL);
1498
1499 error = dmu_objset_open(snap1name, DMU_OST_OTHER,
1500 DS_MODE_USER | DS_MODE_READONLY, &clone);
1501 if (error)
1502 fatal(0, "dmu_open_snapshot(%s) = %d", snap1name, error);
1503
1504 error = dmu_objset_create(clone1name, DMU_OST_OTHER, clone, 0,
1505 NULL, NULL);
1490 if (error)
1491 fatal(0, "dmu_objset_create(%s) = %d", clone1name, error);
1492 dmu_objset_close(clone);
1506 dmu_objset_close(clone);
1507 if (error) {
1508 if (error == ENOSPC) {
1509 ztest_record_enospc(FTAG);
1510 goto out;
1511 }
1512 fatal(0, "dmu_objset_create(%s) = %d", clone1name, error);
1513 }
1493
1494 error = dmu_objset_snapshot(clone1name, strchr(snap2name, '@')+1,
1514
1515 error = dmu_objset_snapshot(clone1name, strchr(snap2name, '@')+1,
1495 FALSE);
1496 if (error == ENOSPC)
1497 ztest_record_enospc("dmu_take_snapshot");
1498 else if (error != 0 && error != EEXIST)
1499 fatal(0, "dmu_take_snapshot = %d", error);
1516 NULL, FALSE);
1517 if (error && error != EEXIST) {
1518 if (error == ENOSPC) {
1519 ztest_record_enospc(FTAG);
1520 goto out;
1521 }
1522 fatal(0, "dmu_open_snapshot(%s) = %d", snap2name, error);
1523 }
1500
1501 error = dmu_objset_snapshot(clone1name, strchr(snap3name, '@')+1,
1524
1525 error = dmu_objset_snapshot(clone1name, strchr(snap3name, '@')+1,
1502 FALSE);
1503 if (error == ENOSPC)
1504 ztest_record_enospc("dmu_take_snapshot");
1505 else if (error != 0 && error != EEXIST)
1506 fatal(0, "dmu_take_snapshot = %d", error);
1526 NULL, FALSE);
1527 if (error && error != EEXIST) {
1528 if (error == ENOSPC) {
1529 ztest_record_enospc(FTAG);
1530 goto out;
1531 }
1532 fatal(0, "dmu_open_snapshot(%s) = %d", snap3name, error);
1533 }
1507
1508 error = dmu_objset_open(snap3name, DMU_OST_OTHER,
1509 DS_MODE_USER | DS_MODE_READONLY, &clone);
1510 if (error)
1511 fatal(0, "dmu_open_snapshot(%s) = %d", snap3name, error);
1512
1513 error = dmu_objset_create(clone2name, DMU_OST_OTHER, clone, 0,
1514 NULL, NULL);
1534
1535 error = dmu_objset_open(snap3name, DMU_OST_OTHER,
1536 DS_MODE_USER | DS_MODE_READONLY, &clone);
1537 if (error)
1538 fatal(0, "dmu_open_snapshot(%s) = %d", snap3name, error);
1539
1540 error = dmu_objset_create(clone2name, DMU_OST_OTHER, clone, 0,
1541 NULL, NULL);
1515 if (error)
1516 fatal(0, "dmu_objset_create(%s) = %d", clone2name, error);
1517 dmu_objset_close(clone);
1542 dmu_objset_close(clone);
1543 if (error) {
1544 if (error == ENOSPC) {
1545 ztest_record_enospc("dmu_objset_create");
1546 goto out;
1547 }
1548 fatal(0, "dmu_objset_create(%s) = %d", clone2name, error);
1549 }
1518
1519 error = dsl_dataset_own(snap1name, 0, FTAG, &ds);
1520 if (error)
1521 fatal(0, "dsl_dataset_own(%s) = %d", snap1name, error);
1522 error = dsl_dataset_promote(clone2name);
1523 if (error != EBUSY)
1524 fatal(0, "dsl_dataset_promote(%s), %d, not EBUSY", clone2name,
1525 error);
1526 dsl_dataset_disown(ds, FTAG);
1527
1550
1551 error = dsl_dataset_own(snap1name, 0, FTAG, &ds);
1552 if (error)
1553 fatal(0, "dsl_dataset_own(%s) = %d", snap1name, error);
1554 error = dsl_dataset_promote(clone2name);
1555 if (error != EBUSY)
1556 fatal(0, "dsl_dataset_promote(%s), %d, not EBUSY", clone2name,
1557 error);
1558 dsl_dataset_disown(ds, FTAG);
1559
1560out:
1528 error = dmu_objset_destroy(clone2name);
1561 error = dmu_objset_destroy(clone2name);
1529 if (error)
1562 if (error && error != ENOENT)
1530 fatal(0, "dmu_objset_destroy(%s) = %d", clone2name, error);
1531
1532 error = dmu_objset_destroy(snap3name);
1563 fatal(0, "dmu_objset_destroy(%s) = %d", clone2name, error);
1564
1565 error = dmu_objset_destroy(snap3name);
1533 if (error)
1566 if (error && error != ENOENT)
1534 fatal(0, "dmu_objset_destroy(%s) = %d", snap2name, error);
1535
1536 error = dmu_objset_destroy(snap2name);
1567 fatal(0, "dmu_objset_destroy(%s) = %d", snap2name, error);
1568
1569 error = dmu_objset_destroy(snap2name);
1537 if (error)
1570 if (error && error != ENOENT)
1538 fatal(0, "dmu_objset_destroy(%s) = %d", snap2name, error);
1539
1540 error = dmu_objset_destroy(clone1name);
1571 fatal(0, "dmu_objset_destroy(%s) = %d", snap2name, error);
1572
1573 error = dmu_objset_destroy(clone1name);
1541 if (error)
1574 if (error && error != ENOENT)
1542 fatal(0, "dmu_objset_destroy(%s) = %d", clone1name, error);
1543 error = dmu_objset_destroy(snap1name);
1575 fatal(0, "dmu_objset_destroy(%s) = %d", clone1name, error);
1576 error = dmu_objset_destroy(snap1name);
1544 if (error)
1577 if (error && error != ENOENT)
1545 fatal(0, "dmu_objset_destroy(%s) = %d", snap1name, error);
1546
1547 (void) rw_unlock(&ztest_shared->zs_name_lock);
1548}
1549
1550/*
1551 * Verify that dmu_object_{alloc,free} work as expected.
1552 */

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

1565
1566 endoff = -8ULL;
1567 batchsize = 2;
1568
1569 /*
1570 * Create a batch object if necessary, and record it in the directory.
1571 */
1572 VERIFY3U(0, ==, dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
1578 fatal(0, "dmu_objset_destroy(%s) = %d", snap1name, error);
1579
1580 (void) rw_unlock(&ztest_shared->zs_name_lock);
1581}
1582
1583/*
1584 * Verify that dmu_object_{alloc,free} work as expected.
1585 */

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

1598
1599 endoff = -8ULL;
1600 batchsize = 2;
1601
1602 /*
1603 * Create a batch object if necessary, and record it in the directory.
1604 */
1605 VERIFY3U(0, ==, dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
1573 sizeof (uint64_t), &batchobj));
1606 sizeof (uint64_t), &batchobj, DMU_READ_PREFETCH));
1574 if (batchobj == 0) {
1575 tx = dmu_tx_create(os);
1576 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff,
1577 sizeof (uint64_t));
1578 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1579 error = dmu_tx_assign(tx, TXG_WAIT);
1580 if (error) {
1581 ztest_record_enospc("create a batch object");

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

1590 dmu_tx_commit(tx);
1591 }
1592
1593 /*
1594 * Destroy the previous batch of objects.
1595 */
1596 for (b = 0; b < batchsize; b++) {
1597 VERIFY3U(0, ==, dmu_read(os, batchobj, b * sizeof (uint64_t),
1607 if (batchobj == 0) {
1608 tx = dmu_tx_create(os);
1609 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff,
1610 sizeof (uint64_t));
1611 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1612 error = dmu_tx_assign(tx, TXG_WAIT);
1613 if (error) {
1614 ztest_record_enospc("create a batch object");

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

1623 dmu_tx_commit(tx);
1624 }
1625
1626 /*
1627 * Destroy the previous batch of objects.
1628 */
1629 for (b = 0; b < batchsize; b++) {
1630 VERIFY3U(0, ==, dmu_read(os, batchobj, b * sizeof (uint64_t),
1598 sizeof (uint64_t), &object));
1631 sizeof (uint64_t), &object, DMU_READ_PREFETCH));
1599 if (object == 0)
1600 continue;
1601 /*
1602 * Read and validate contents.
1603 * We expect the nth byte of the bonus buffer to be n.
1604 */
1605 VERIFY(0 == dmu_bonus_hold(os, object, FTAG, &db));
1606 za->za_dbuf = db;

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

1625
1626 dmu_buf_rele(db, FTAG);
1627 za->za_dbuf = NULL;
1628
1629 /*
1630 * We expect the word at endoff to be our object number.
1631 */
1632 VERIFY(0 == dmu_read(os, object, endoff,
1632 if (object == 0)
1633 continue;
1634 /*
1635 * Read and validate contents.
1636 * We expect the nth byte of the bonus buffer to be n.
1637 */
1638 VERIFY(0 == dmu_bonus_hold(os, object, FTAG, &db));
1639 za->za_dbuf = db;

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

1658
1659 dmu_buf_rele(db, FTAG);
1660 za->za_dbuf = NULL;
1661
1662 /*
1663 * We expect the word at endoff to be our object number.
1664 */
1665 VERIFY(0 == dmu_read(os, object, endoff,
1633 sizeof (uint64_t), &temp));
1666 sizeof (uint64_t), &temp, DMU_READ_PREFETCH));
1634
1635 if (temp != object) {
1636 fatal(0, "bad data in %s, got %llu, expected %llu",
1637 osname, temp, object);
1638 }
1639
1640 /*
1641 * Destroy old object and clear batch entry.

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

1810 * tracking which parts of an object are allocated and free,
1811 * and that the contents of the allocated blocks are correct.
1812 */
1813
1814 /*
1815 * Read the directory info. If it's the first time, set things up.
1816 */
1817 VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
1667
1668 if (temp != object) {
1669 fatal(0, "bad data in %s, got %llu, expected %llu",
1670 osname, temp, object);
1671 }
1672
1673 /*
1674 * Destroy old object and clear batch entry.

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

1843 * tracking which parts of an object are allocated and free,
1844 * and that the contents of the allocated blocks are correct.
1845 */
1846
1847 /*
1848 * Read the directory info. If it's the first time, set things up.
1849 */
1850 VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
1818 sizeof (dd), &dd));
1851 sizeof (dd), &dd, DMU_READ_PREFETCH));
1819 if (dd.dd_chunk == 0) {
1820 ASSERT(dd.dd_packobj == 0);
1821 ASSERT(dd.dd_bigobj == 0);
1822 tx = dmu_tx_create(os);
1823 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, sizeof (dd));
1824 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1825 error = dmu_tx_assign(tx, TXG_WAIT);
1826 if (error) {

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

1872 * free_percent of the time, free a range of bigobj rather than
1873 * overwriting it.
1874 */
1875 freeit = (ztest_random(100) < free_percent);
1876
1877 /*
1878 * Read the current contents of our objects.
1879 */
1852 if (dd.dd_chunk == 0) {
1853 ASSERT(dd.dd_packobj == 0);
1854 ASSERT(dd.dd_bigobj == 0);
1855 tx = dmu_tx_create(os);
1856 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, sizeof (dd));
1857 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1858 error = dmu_tx_assign(tx, TXG_WAIT);
1859 if (error) {

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

1905 * free_percent of the time, free a range of bigobj rather than
1906 * overwriting it.
1907 */
1908 freeit = (ztest_random(100) < free_percent);
1909
1910 /*
1911 * Read the current contents of our objects.
1912 */
1880 error = dmu_read(os, dd.dd_packobj, packoff, packsize, packbuf);
1913 error = dmu_read(os, dd.dd_packobj, packoff, packsize, packbuf,
1914 DMU_READ_PREFETCH);
1881 ASSERT3U(error, ==, 0);
1915 ASSERT3U(error, ==, 0);
1882 error = dmu_read(os, dd.dd_bigobj, bigoff, bigsize, bigbuf);
1916 error = dmu_read(os, dd.dd_bigobj, bigoff, bigsize, bigbuf,
1917 DMU_READ_PREFETCH);
1883 ASSERT3U(error, ==, 0);
1884
1885 /*
1886 * Get a tx for the mods to both packobj and bigobj.
1887 */
1888 tx = dmu_tx_create(os);
1889
1890 dmu_tx_hold_write(tx, dd.dd_packobj, packoff, packsize);

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

1980 /*
1981 * Sanity check the stuff we just wrote.
1982 */
1983 {
1984 void *packcheck = umem_alloc(packsize, UMEM_NOFAIL);
1985 void *bigcheck = umem_alloc(bigsize, UMEM_NOFAIL);
1986
1987 VERIFY(0 == dmu_read(os, dd.dd_packobj, packoff,
1918 ASSERT3U(error, ==, 0);
1919
1920 /*
1921 * Get a tx for the mods to both packobj and bigobj.
1922 */
1923 tx = dmu_tx_create(os);
1924
1925 dmu_tx_hold_write(tx, dd.dd_packobj, packoff, packsize);

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

2015 /*
2016 * Sanity check the stuff we just wrote.
2017 */
2018 {
2019 void *packcheck = umem_alloc(packsize, UMEM_NOFAIL);
2020 void *bigcheck = umem_alloc(bigsize, UMEM_NOFAIL);
2021
2022 VERIFY(0 == dmu_read(os, dd.dd_packobj, packoff,
1988 packsize, packcheck));
2023 packsize, packcheck, DMU_READ_PREFETCH));
1989 VERIFY(0 == dmu_read(os, dd.dd_bigobj, bigoff,
2024 VERIFY(0 == dmu_read(os, dd.dd_bigobj, bigoff,
1990 bigsize, bigcheck));
2025 bigsize, bigcheck, DMU_READ_PREFETCH));
1991
1992 ASSERT(bcmp(packbuf, packcheck, packsize) == 0);
1993 ASSERT(bcmp(bigbuf, bigcheck, bigsize) == 0);
1994
1995 umem_free(packcheck, packsize);
1996 umem_free(bigcheck, bigsize);
1997 }
1998
1999 umem_free(packbuf, packsize);
2000 umem_free(bigbuf, bigsize);
2001}
2002
2003void
2026
2027 ASSERT(bcmp(packbuf, packcheck, packsize) == 0);
2028 ASSERT(bcmp(bigbuf, bigcheck, bigsize) == 0);
2029
2030 umem_free(packcheck, packsize);
2031 umem_free(bigcheck, bigsize);
2032 }
2033
2034 umem_free(packbuf, packsize);
2035 umem_free(bigbuf, bigsize);
2036}
2037
2038void
2039compare_and_update_pbbufs(uint64_t s, bufwad_t *packbuf, bufwad_t *bigbuf,
2040 uint64_t bigsize, uint64_t n, dmu_read_write_dir_t dd, uint64_t txg)
2041{
2042 uint64_t i;
2043 bufwad_t *pack;
2044 bufwad_t *bigH;
2045 bufwad_t *bigT;
2046
2047 /*
2048 * For each index from n to n + s, verify that the existing bufwad
2049 * in packobj matches the bufwads at the head and tail of the
2050 * corresponding chunk in bigobj. Then update all three bufwads
2051 * with the new values we want to write out.
2052 */
2053 for (i = 0; i < s; i++) {
2054 /* LINTED */
2055 pack = (bufwad_t *)((char *)packbuf + i * sizeof (bufwad_t));
2056 /* LINTED */
2057 bigH = (bufwad_t *)((char *)bigbuf + i * dd.dd_chunk);
2058 /* LINTED */
2059 bigT = (bufwad_t *)((char *)bigH + dd.dd_chunk) - 1;
2060
2061 ASSERT((uintptr_t)bigH - (uintptr_t)bigbuf < bigsize);
2062 ASSERT((uintptr_t)bigT - (uintptr_t)bigbuf < bigsize);
2063
2064 if (pack->bw_txg > txg)
2065 fatal(0, "future leak: got %llx, open txg is %llx",
2066 pack->bw_txg, txg);
2067
2068 if (pack->bw_data != 0 && pack->bw_index != n + i)
2069 fatal(0, "wrong index: got %llx, wanted %llx+%llx",
2070 pack->bw_index, n, i);
2071
2072 if (bcmp(pack, bigH, sizeof (bufwad_t)) != 0)
2073 fatal(0, "pack/bigH mismatch in %p/%p", pack, bigH);
2074
2075 if (bcmp(pack, bigT, sizeof (bufwad_t)) != 0)
2076 fatal(0, "pack/bigT mismatch in %p/%p", pack, bigT);
2077
2078 pack->bw_index = n + i;
2079 pack->bw_txg = txg;
2080 pack->bw_data = 1 + ztest_random(-2ULL);
2081
2082 *bigH = *pack;
2083 *bigT = *pack;
2084 }
2085}
2086
2087void
2088ztest_dmu_read_write_zcopy(ztest_args_t *za)
2089{
2090 objset_t *os = za->za_os;
2091 dmu_read_write_dir_t dd;
2092 dmu_tx_t *tx;
2093 uint64_t i;
2094 int error;
2095 uint64_t n, s, txg;
2096 bufwad_t *packbuf, *bigbuf;
2097 uint64_t packoff, packsize, bigoff, bigsize;
2098 uint64_t regions = 997;
2099 uint64_t stride = 123456789ULL;
2100 uint64_t width = 9;
2101 dmu_buf_t *bonus_db;
2102 arc_buf_t **bigbuf_arcbufs;
2103 dmu_object_info_t *doi = &za->za_doi;
2104
2105 /*
2106 * This test uses two objects, packobj and bigobj, that are always
2107 * updated together (i.e. in the same tx) so that their contents are
2108 * in sync and can be compared. Their contents relate to each other
2109 * in a simple way: packobj is a dense array of 'bufwad' structures,
2110 * while bigobj is a sparse array of the same bufwads. Specifically,
2111 * for any index n, there are three bufwads that should be identical:
2112 *
2113 * packobj, at offset n * sizeof (bufwad_t)
2114 * bigobj, at the head of the nth chunk
2115 * bigobj, at the tail of the nth chunk
2116 *
2117 * The chunk size is set equal to bigobj block size so that
2118 * dmu_assign_arcbuf() can be tested for object updates.
2119 */
2120
2121 /*
2122 * Read the directory info. If it's the first time, set things up.
2123 */
2124 VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
2125 sizeof (dd), &dd, DMU_READ_PREFETCH));
2126 if (dd.dd_chunk == 0) {
2127 ASSERT(dd.dd_packobj == 0);
2128 ASSERT(dd.dd_bigobj == 0);
2129 tx = dmu_tx_create(os);
2130 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, sizeof (dd));
2131 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
2132 error = dmu_tx_assign(tx, TXG_WAIT);
2133 if (error) {
2134 ztest_record_enospc("create r/w directory");
2135 dmu_tx_abort(tx);
2136 return;
2137 }
2138
2139 dd.dd_packobj = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
2140 DMU_OT_NONE, 0, tx);
2141 dd.dd_bigobj = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
2142 DMU_OT_NONE, 0, tx);
2143 ztest_set_random_blocksize(os, dd.dd_packobj, tx);
2144 ztest_set_random_blocksize(os, dd.dd_bigobj, tx);
2145
2146 VERIFY(dmu_object_info(os, dd.dd_bigobj, doi) == 0);
2147 ASSERT(doi->doi_data_block_size >= 2 * sizeof (bufwad_t));
2148 ASSERT(ISP2(doi->doi_data_block_size));
2149 dd.dd_chunk = doi->doi_data_block_size;
2150
2151 dmu_write(os, ZTEST_DIROBJ, za->za_diroff, sizeof (dd), &dd,
2152 tx);
2153 dmu_tx_commit(tx);
2154 } else {
2155 VERIFY(dmu_object_info(os, dd.dd_bigobj, doi) == 0);
2156 VERIFY(ISP2(doi->doi_data_block_size));
2157 VERIFY(dd.dd_chunk == doi->doi_data_block_size);
2158 VERIFY(dd.dd_chunk >= 2 * sizeof (bufwad_t));
2159 }
2160
2161 /*
2162 * Pick a random index and compute the offsets into packobj and bigobj.
2163 */
2164 n = ztest_random(regions) * stride + ztest_random(width);
2165 s = 1 + ztest_random(width - 1);
2166
2167 packoff = n * sizeof (bufwad_t);
2168 packsize = s * sizeof (bufwad_t);
2169
2170 bigoff = n * dd.dd_chunk;
2171 bigsize = s * dd.dd_chunk;
2172
2173 packbuf = umem_zalloc(packsize, UMEM_NOFAIL);
2174 bigbuf = umem_zalloc(bigsize, UMEM_NOFAIL);
2175
2176 VERIFY(dmu_bonus_hold(os, dd.dd_bigobj, FTAG, &bonus_db) == 0);
2177
2178 bigbuf_arcbufs = umem_zalloc(2 * s * sizeof (arc_buf_t *), UMEM_NOFAIL);
2179
2180 /*
2181 * Iteration 0 test zcopy for DB_UNCACHED dbufs.
2182 * Iteration 1 test zcopy to already referenced dbufs.
2183 * Iteration 2 test zcopy to dirty dbuf in the same txg.
2184 * Iteration 3 test zcopy to dbuf dirty in previous txg.
2185 * Iteration 4 test zcopy when dbuf is no longer dirty.
2186 * Iteration 5 test zcopy when it can't be done.
2187 * Iteration 6 one more zcopy write.
2188 */
2189 for (i = 0; i < 7; i++) {
2190 uint64_t j;
2191 uint64_t off;
2192
2193 /*
2194 * In iteration 5 (i == 5) use arcbufs
2195 * that don't match bigobj blksz to test
2196 * dmu_assign_arcbuf() when it can't directly
2197 * assign an arcbuf to a dbuf.
2198 */
2199 for (j = 0; j < s; j++) {
2200 if (i != 5) {
2201 bigbuf_arcbufs[j] =
2202 dmu_request_arcbuf(bonus_db,
2203 dd.dd_chunk);
2204 } else {
2205 bigbuf_arcbufs[2 * j] =
2206 dmu_request_arcbuf(bonus_db,
2207 dd.dd_chunk / 2);
2208 bigbuf_arcbufs[2 * j + 1] =
2209 dmu_request_arcbuf(bonus_db,
2210 dd.dd_chunk / 2);
2211 }
2212 }
2213
2214 /*
2215 * Get a tx for the mods to both packobj and bigobj.
2216 */
2217 tx = dmu_tx_create(os);
2218
2219 dmu_tx_hold_write(tx, dd.dd_packobj, packoff, packsize);
2220 dmu_tx_hold_write(tx, dd.dd_bigobj, bigoff, bigsize);
2221
2222 if (ztest_random(100) == 0) {
2223 error = -1;
2224 } else {
2225 error = dmu_tx_assign(tx, TXG_WAIT);
2226 }
2227
2228 if (error) {
2229 if (error != -1) {
2230 ztest_record_enospc("dmu r/w range");
2231 }
2232 dmu_tx_abort(tx);
2233 umem_free(packbuf, packsize);
2234 umem_free(bigbuf, bigsize);
2235 for (j = 0; j < s; j++) {
2236 if (i != 5) {
2237 dmu_return_arcbuf(bigbuf_arcbufs[j]);
2238 } else {
2239 dmu_return_arcbuf(
2240 bigbuf_arcbufs[2 * j]);
2241 dmu_return_arcbuf(
2242 bigbuf_arcbufs[2 * j + 1]);
2243 }
2244 }
2245 umem_free(bigbuf_arcbufs, 2 * s * sizeof (arc_buf_t *));
2246 dmu_buf_rele(bonus_db, FTAG);
2247 return;
2248 }
2249
2250 txg = dmu_tx_get_txg(tx);
2251
2252 /*
2253 * 50% of the time don't read objects in the 1st iteration to
2254 * test dmu_assign_arcbuf() for the case when there're no
2255 * existing dbufs for the specified offsets.
2256 */
2257 if (i != 0 || ztest_random(2) != 0) {
2258 error = dmu_read(os, dd.dd_packobj, packoff,
2259 packsize, packbuf, DMU_READ_PREFETCH);
2260 ASSERT3U(error, ==, 0);
2261 error = dmu_read(os, dd.dd_bigobj, bigoff, bigsize,
2262 bigbuf, DMU_READ_PREFETCH);
2263 ASSERT3U(error, ==, 0);
2264 }
2265 compare_and_update_pbbufs(s, packbuf, bigbuf, bigsize,
2266 n, dd, txg);
2267
2268 /*
2269 * We've verified all the old bufwads, and made new ones.
2270 * Now write them out.
2271 */
2272 dmu_write(os, dd.dd_packobj, packoff, packsize, packbuf, tx);
2273 if (zopt_verbose >= 6) {
2274 (void) printf("writing offset %llx size %llx"
2275 " txg %llx\n",
2276 (u_longlong_t)bigoff,
2277 (u_longlong_t)bigsize,
2278 (u_longlong_t)txg);
2279 }
2280 for (off = bigoff, j = 0; j < s; j++, off += dd.dd_chunk) {
2281 dmu_buf_t *dbt;
2282 if (i != 5) {
2283 bcopy((caddr_t)bigbuf + (off - bigoff),
2284 bigbuf_arcbufs[j]->b_data, dd.dd_chunk);
2285 } else {
2286 bcopy((caddr_t)bigbuf + (off - bigoff),
2287 bigbuf_arcbufs[2 * j]->b_data,
2288 dd.dd_chunk / 2);
2289 bcopy((caddr_t)bigbuf + (off - bigoff) +
2290 dd.dd_chunk / 2,
2291 bigbuf_arcbufs[2 * j + 1]->b_data,
2292 dd.dd_chunk / 2);
2293 }
2294
2295 if (i == 1) {
2296 VERIFY(dmu_buf_hold(os, dd.dd_bigobj, off,
2297 FTAG, &dbt) == 0);
2298 }
2299 if (i != 5) {
2300 dmu_assign_arcbuf(bonus_db, off,
2301 bigbuf_arcbufs[j], tx);
2302 } else {
2303 dmu_assign_arcbuf(bonus_db, off,
2304 bigbuf_arcbufs[2 * j], tx);
2305 dmu_assign_arcbuf(bonus_db,
2306 off + dd.dd_chunk / 2,
2307 bigbuf_arcbufs[2 * j + 1], tx);
2308 }
2309 if (i == 1) {
2310 dmu_buf_rele(dbt, FTAG);
2311 }
2312 }
2313 dmu_tx_commit(tx);
2314
2315 /*
2316 * Sanity check the stuff we just wrote.
2317 */
2318 {
2319 void *packcheck = umem_alloc(packsize, UMEM_NOFAIL);
2320 void *bigcheck = umem_alloc(bigsize, UMEM_NOFAIL);
2321
2322 VERIFY(0 == dmu_read(os, dd.dd_packobj, packoff,
2323 packsize, packcheck, DMU_READ_PREFETCH));
2324 VERIFY(0 == dmu_read(os, dd.dd_bigobj, bigoff,
2325 bigsize, bigcheck, DMU_READ_PREFETCH));
2326
2327 ASSERT(bcmp(packbuf, packcheck, packsize) == 0);
2328 ASSERT(bcmp(bigbuf, bigcheck, bigsize) == 0);
2329
2330 umem_free(packcheck, packsize);
2331 umem_free(bigcheck, bigsize);
2332 }
2333 if (i == 2) {
2334 txg_wait_open(dmu_objset_pool(os), 0);
2335 } else if (i == 3) {
2336 txg_wait_synced(dmu_objset_pool(os), 0);
2337 }
2338 }
2339
2340 dmu_buf_rele(bonus_db, FTAG);
2341 umem_free(packbuf, packsize);
2342 umem_free(bigbuf, bigsize);
2343 umem_free(bigbuf_arcbufs, 2 * s * sizeof (arc_buf_t *));
2344}
2345
2346void
2004ztest_dmu_check_future_leak(ztest_args_t *za)
2005{
2006 objset_t *os = za->za_os;
2007 dmu_buf_t *db;
2008 ztest_block_tag_t *bt;
2009 dmu_object_info_t *doi = &za->za_doi;
2010
2011 /*

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

2044 uint64_t off, txg, txg_how;
2045 mutex_t *lp;
2046 char osname[MAXNAMELEN];
2047 char iobuf[SPA_MAXBLOCKSIZE];
2048 blkptr_t blk = { 0 };
2049 uint64_t blkoff;
2050 zbookmark_t zb;
2051 dmu_tx_t *tx = dmu_tx_create(os);
2347ztest_dmu_check_future_leak(ztest_args_t *za)
2348{
2349 objset_t *os = za->za_os;
2350 dmu_buf_t *db;
2351 ztest_block_tag_t *bt;
2352 dmu_object_info_t *doi = &za->za_doi;
2353
2354 /*

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

2387 uint64_t off, txg, txg_how;
2388 mutex_t *lp;
2389 char osname[MAXNAMELEN];
2390 char iobuf[SPA_MAXBLOCKSIZE];
2391 blkptr_t blk = { 0 };
2392 uint64_t blkoff;
2393 zbookmark_t zb;
2394 dmu_tx_t *tx = dmu_tx_create(os);
2395 dmu_buf_t *bonus_db;
2396 arc_buf_t *abuf = NULL;
2052
2053 dmu_objset_name(os, osname);
2054
2055 /*
2056 * Have multiple threads write to large offsets in ZTEST_DIROBJ
2057 * to verify that having multiple threads writing to the same object
2058 * in parallel doesn't cause any trouble.
2059 */

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

2072 if (ztest_random(4) == 0) {
2073 do_free = 1;
2074 dmu_tx_hold_free(tx, ZTEST_DIROBJ, off, bs);
2075 } else {
2076 dmu_tx_hold_write(tx, ZTEST_DIROBJ, off, bs);
2077 }
2078 }
2079
2397
2398 dmu_objset_name(os, osname);
2399
2400 /*
2401 * Have multiple threads write to large offsets in ZTEST_DIROBJ
2402 * to verify that having multiple threads writing to the same object
2403 * in parallel doesn't cause any trouble.
2404 */

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

2417 if (ztest_random(4) == 0) {
2418 do_free = 1;
2419 dmu_tx_hold_free(tx, ZTEST_DIROBJ, off, bs);
2420 } else {
2421 dmu_tx_hold_write(tx, ZTEST_DIROBJ, off, bs);
2422 }
2423 }
2424
2425 if (off != -1ULL && P2PHASE(off, bs) == 0 && !do_free &&
2426 ztest_random(8) == 0) {
2427 VERIFY(dmu_bonus_hold(os, ZTEST_DIROBJ, FTAG, &bonus_db) == 0);
2428 abuf = dmu_request_arcbuf(bonus_db, bs);
2429 }
2430
2080 txg_how = ztest_random(2) == 0 ? TXG_WAIT : TXG_NOWAIT;
2081 error = dmu_tx_assign(tx, txg_how);
2082 if (error) {
2083 if (error == ERESTART) {
2084 ASSERT(txg_how == TXG_NOWAIT);
2085 dmu_tx_wait(tx);
2086 } else {
2087 ztest_record_enospc("dmu write parallel");
2088 }
2089 dmu_tx_abort(tx);
2431 txg_how = ztest_random(2) == 0 ? TXG_WAIT : TXG_NOWAIT;
2432 error = dmu_tx_assign(tx, txg_how);
2433 if (error) {
2434 if (error == ERESTART) {
2435 ASSERT(txg_how == TXG_NOWAIT);
2436 dmu_tx_wait(tx);
2437 } else {
2438 ztest_record_enospc("dmu write parallel");
2439 }
2440 dmu_tx_abort(tx);
2441 if (abuf != NULL) {
2442 dmu_return_arcbuf(abuf);
2443 dmu_buf_rele(bonus_db, FTAG);
2444 }
2090 return;
2091 }
2092 txg = dmu_tx_get_txg(tx);
2093
2094 lp = &ztest_shared->zs_sync_lock[b];
2095 (void) mutex_lock(lp);
2096
2097 wbt->bt_objset = dmu_objset_id(os);

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

2136 dboff = (char *)db->db_data + newsize - btsize;
2137 }
2138 dmu_buf_will_dirty(db, tx);
2139 bcopy(wbt, dboff, btsize);
2140 dmu_buf_rele(db, FTAG);
2141 za->za_dbuf = NULL;
2142 } else if (do_free) {
2143 VERIFY(dmu_free_range(os, ZTEST_DIROBJ, off, bs, tx) == 0);
2445 return;
2446 }
2447 txg = dmu_tx_get_txg(tx);
2448
2449 lp = &ztest_shared->zs_sync_lock[b];
2450 (void) mutex_lock(lp);
2451
2452 wbt->bt_objset = dmu_objset_id(os);

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

2491 dboff = (char *)db->db_data + newsize - btsize;
2492 }
2493 dmu_buf_will_dirty(db, tx);
2494 bcopy(wbt, dboff, btsize);
2495 dmu_buf_rele(db, FTAG);
2496 za->za_dbuf = NULL;
2497 } else if (do_free) {
2498 VERIFY(dmu_free_range(os, ZTEST_DIROBJ, off, bs, tx) == 0);
2144 } else {
2499 } else if (abuf == NULL) {
2145 dmu_write(os, ZTEST_DIROBJ, off, btsize, wbt, tx);
2500 dmu_write(os, ZTEST_DIROBJ, off, btsize, wbt, tx);
2501 } else {
2502 bcopy(wbt, abuf->b_data, btsize);
2503 dmu_assign_arcbuf(bonus_db, off, abuf, tx);
2504 dmu_buf_rele(bonus_db, FTAG);
2146 }
2147
2148 (void) mutex_unlock(lp);
2149
2150 if (ztest_random(1000) == 0)
2151 (void) poll(NULL, 0, 1); /* open dn_notxholds window */
2152
2153 dmu_tx_commit(tx);

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

2165 * dmu_sync() the block we just wrote.
2166 */
2167 (void) mutex_lock(lp);
2168
2169 blkoff = P2ALIGN_TYPED(off, bs, uint64_t);
2170 error = dmu_buf_hold(os, ZTEST_DIROBJ, blkoff, FTAG, &db);
2171 za->za_dbuf = db;
2172 if (error) {
2505 }
2506
2507 (void) mutex_unlock(lp);
2508
2509 if (ztest_random(1000) == 0)
2510 (void) poll(NULL, 0, 1); /* open dn_notxholds window */
2511
2512 dmu_tx_commit(tx);

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

2524 * dmu_sync() the block we just wrote.
2525 */
2526 (void) mutex_lock(lp);
2527
2528 blkoff = P2ALIGN_TYPED(off, bs, uint64_t);
2529 error = dmu_buf_hold(os, ZTEST_DIROBJ, blkoff, FTAG, &db);
2530 za->za_dbuf = db;
2531 if (error) {
2173 dprintf("dmu_buf_hold(%s, %d, %llx) = %d\n",
2174 osname, ZTEST_DIROBJ, blkoff, error);
2175 (void) mutex_unlock(lp);
2176 return;
2177 }
2178 blkoff = off - blkoff;
2179 error = dmu_sync(NULL, db, &blk, txg, NULL, NULL);
2180 dmu_buf_rele(db, FTAG);
2181 za->za_dbuf = NULL;
2182
2532 (void) mutex_unlock(lp);
2533 return;
2534 }
2535 blkoff = off - blkoff;
2536 error = dmu_sync(NULL, db, &blk, txg, NULL, NULL);
2537 dmu_buf_rele(db, FTAG);
2538 za->za_dbuf = NULL;
2539
2183 (void) mutex_unlock(lp);
2184
2185 if (error) {
2540 if (error) {
2186 dprintf("dmu_sync(%s, %d, %llx) = %d\n",
2187 osname, ZTEST_DIROBJ, off, error);
2541 (void) mutex_unlock(lp);
2188 return;
2189 }
2190
2542 return;
2543 }
2544
2191 if (blk.blk_birth == 0) /* concurrent free */
2545 if (blk.blk_birth == 0) { /* concurrent free */
2546 (void) mutex_unlock(lp);
2192 return;
2547 return;
2548 }
2193
2194 txg_suspend(dmu_objset_pool(os));
2195
2549
2550 txg_suspend(dmu_objset_pool(os));
2551
2552 (void) mutex_unlock(lp);
2553
2196 ASSERT(blk.blk_fill == 1);
2197 ASSERT3U(BP_GET_TYPE(&blk), ==, DMU_OT_UINT64_OTHER);
2198 ASSERT3U(BP_GET_LEVEL(&blk), ==, 0);
2199 ASSERT3U(BP_GET_LSIZE(&blk), ==, bs);
2200
2201 /*
2202 * Read the block that dmu_sync() returned to make sure its contents
2203 * match what we wrote. We do this while still txg_suspend()ed

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

2260 char *hc[2] = { "s.acl.h", ".s.open.h.hyLZlg" };
2261
2262 dmu_objset_name(os, osname);
2263
2264 /*
2265 * Create a new object if necessary, and record it in the directory.
2266 */
2267 VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
2554 ASSERT(blk.blk_fill == 1);
2555 ASSERT3U(BP_GET_TYPE(&blk), ==, DMU_OT_UINT64_OTHER);
2556 ASSERT3U(BP_GET_LEVEL(&blk), ==, 0);
2557 ASSERT3U(BP_GET_LSIZE(&blk), ==, bs);
2558
2559 /*
2560 * Read the block that dmu_sync() returned to make sure its contents
2561 * match what we wrote. We do this while still txg_suspend()ed

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

2618 char *hc[2] = { "s.acl.h", ".s.open.h.hyLZlg" };
2619
2620 dmu_objset_name(os, osname);
2621
2622 /*
2623 * Create a new object if necessary, and record it in the directory.
2624 */
2625 VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
2268 sizeof (uint64_t), &object));
2626 sizeof (uint64_t), &object, DMU_READ_PREFETCH));
2269
2270 if (object == 0) {
2271 tx = dmu_tx_create(os);
2272 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff,
2273 sizeof (uint64_t));
2274 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, TRUE, NULL);
2275 error = dmu_tx_assign(tx, TXG_WAIT);
2276 if (error) {

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

2439 fatal(0, "zap_destroy('%s', %llu) = %d",
2440 osname, object, error);
2441 object = 0;
2442 dmu_write(os, ZTEST_DIROBJ, za->za_diroff, sizeof (uint64_t),
2443 &object, tx);
2444 dmu_tx_commit(tx);
2445}
2446
2627
2628 if (object == 0) {
2629 tx = dmu_tx_create(os);
2630 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff,
2631 sizeof (uint64_t));
2632 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, TRUE, NULL);
2633 error = dmu_tx_assign(tx, TXG_WAIT);
2634 if (error) {

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

2797 fatal(0, "zap_destroy('%s', %llu) = %d",
2798 osname, object, error);
2799 object = 0;
2800 dmu_write(os, ZTEST_DIROBJ, za->za_diroff, sizeof (uint64_t),
2801 &object, tx);
2802 dmu_tx_commit(tx);
2803}
2804
2805/*
2806 * Testcase to test the upgrading of a microzap to fatzap.
2807 */
2447void
2808void
2809ztest_fzap(ztest_args_t *za)
2810{
2811 objset_t *os = za->za_os;
2812 uint64_t object;
2813 uint64_t value;
2814 dmu_tx_t *tx;
2815 int i, error;
2816 char osname[MAXNAMELEN];
2817 char *name = "aaa";
2818 char entname[MAXNAMELEN];
2819
2820 dmu_objset_name(os, osname);
2821
2822 /*
2823 * Create a new object if necessary, and record it in the directory.
2824 */
2825 VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
2826 sizeof (uint64_t), &object, DMU_READ_PREFETCH));
2827
2828 if (object == 0) {
2829 tx = dmu_tx_create(os);
2830 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff,
2831 sizeof (uint64_t));
2832 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, TRUE, NULL);
2833 error = dmu_tx_assign(tx, TXG_WAIT);
2834 if (error) {
2835 ztest_record_enospc("create zap test obj");
2836 dmu_tx_abort(tx);
2837 return;
2838 }
2839 object = zap_create(os, DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx);
2840 if (error) {
2841 fatal(0, "zap_create('%s', %llu) = %d",
2842 osname, object, error);
2843 }
2844 ASSERT(object != 0);
2845 dmu_write(os, ZTEST_DIROBJ, za->za_diroff,
2846 sizeof (uint64_t), &object, tx);
2847 dmu_tx_commit(tx);
2848 }
2849
2850 /*
2851 * Add entries to this ZAP amd make sure it spills over
2852 * and gets upgraded to a fatzap. Also, since we are adding
2853 * 2050 entries we should see ptrtbl growth and leaf-block
2854 * split.
2855 */
2856 for (i = 0; i < 2050; i++) {
2857 (void) snprintf(entname, sizeof (entname), "%s-%d", name, i);
2858 value = i;
2859
2860 tx = dmu_tx_create(os);
2861 dmu_tx_hold_zap(tx, object, TRUE, entname);
2862 error = dmu_tx_assign(tx, TXG_WAIT);
2863
2864 if (error) {
2865 ztest_record_enospc("create zap entry");
2866 dmu_tx_abort(tx);
2867 return;
2868 }
2869 error = zap_add(os, object, entname, sizeof (uint64_t),
2870 1, &value, tx);
2871
2872 ASSERT(error == 0 || error == EEXIST);
2873 dmu_tx_commit(tx);
2874 }
2875
2876 /*
2877 * Once in a while, destroy the object.
2878 */
2879 if (ztest_random(1000) != 0)
2880 return;
2881
2882 tx = dmu_tx_create(os);
2883 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, sizeof (uint64_t));
2884 dmu_tx_hold_free(tx, object, 0, DMU_OBJECT_END);
2885 error = dmu_tx_assign(tx, TXG_WAIT);
2886 if (error) {
2887 ztest_record_enospc("destroy zap object");
2888 dmu_tx_abort(tx);
2889 return;
2890 }
2891 error = zap_destroy(os, object, tx);
2892 if (error)
2893 fatal(0, "zap_destroy('%s', %llu) = %d",
2894 osname, object, error);
2895 object = 0;
2896 dmu_write(os, ZTEST_DIROBJ, za->za_diroff, sizeof (uint64_t),
2897 &object, tx);
2898 dmu_tx_commit(tx);
2899}
2900
2901void
2448ztest_zap_parallel(ztest_args_t *za)
2449{
2450 objset_t *os = za->za_os;
2451 uint64_t txg, object, count, wsize, wc, zl_wsize, zl_wc;
2452 dmu_tx_t *tx;
2453 int i, namelen, error;
2454 char name[20], string_value[20];
2455 void *data;

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

2690 (void) strcpy(path0, vd0->vdev_path);
2691 (void) strcpy(pathrand, vd0->vdev_path);
2692
2693 leaf = 0;
2694 leaves = 1;
2695 maxfaults = INT_MAX; /* no limit on cache devices */
2696 }
2697
2902ztest_zap_parallel(ztest_args_t *za)
2903{
2904 objset_t *os = za->za_os;
2905 uint64_t txg, object, count, wsize, wc, zl_wsize, zl_wc;
2906 dmu_tx_t *tx;
2907 int i, namelen, error;
2908 char name[20], string_value[20];
2909 void *data;

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

3144 (void) strcpy(path0, vd0->vdev_path);
3145 (void) strcpy(pathrand, vd0->vdev_path);
3146
3147 leaf = 0;
3148 leaves = 1;
3149 maxfaults = INT_MAX; /* no limit on cache devices */
3150 }
3151
2698 dprintf("damaging %s and %s\n", path0, pathrand);
2699
2700 spa_config_exit(spa, SCL_STATE, FTAG);
2701
2702 if (maxfaults == 0)
2703 return;
2704
2705 /*
2706 * If we can tolerate two or more faults, randomly online/offline vd0.
2707 */
2708 if (maxfaults >= 2 && guid0 != 0) {
3152 spa_config_exit(spa, SCL_STATE, FTAG);
3153
3154 if (maxfaults == 0)
3155 return;
3156
3157 /*
3158 * If we can tolerate two or more faults, randomly online/offline vd0.
3159 */
3160 if (maxfaults >= 2 && guid0 != 0) {
2709 if (ztest_random(10) < 6)
2710 (void) vdev_offline(spa, guid0, B_TRUE);
2711 else
2712 (void) vdev_online(spa, guid0, B_FALSE, NULL);
3161 if (ztest_random(10) < 6) {
3162 int flags = (ztest_random(2) == 0 ?
3163 ZFS_OFFLINE_TEMPORARY : 0);
3164 VERIFY(vdev_offline(spa, guid0, flags) != EBUSY);
3165 } else {
3166 (void) vdev_online(spa, guid0, 0, NULL);
3167 }
2713 }
2714
2715 /*
2716 * We have at least single-fault tolerance, so inject data corruption.
2717 */
2718 fd = open(pathrand, O_RDWR);
2719
2720 if (fd == -1) /* we hit a gap in the device namespace */

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

2913 /* zdb lives in /usr/sbin, while ztest lives in /usr/bin */
2914 bin = strstr(zdb, "/usr/bin/");
2915 ztest = strstr(bin, "/ztest");
2916 isa = bin + 8;
2917 isalen = ztest - isa;
2918 isa = strdup(isa);
2919 /* LINTED */
2920 (void) sprintf(bin,
3168 }
3169
3170 /*
3171 * We have at least single-fault tolerance, so inject data corruption.
3172 */
3173 fd = open(pathrand, O_RDWR);
3174
3175 if (fd == -1) /* we hit a gap in the device namespace */

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

3368 /* zdb lives in /usr/sbin, while ztest lives in /usr/bin */
3369 bin = strstr(zdb, "/usr/bin/");
3370 ztest = strstr(bin, "/ztest");
3371 isa = bin + 8;
3372 isalen = ztest - isa;
3373 isa = strdup(isa);
3374 /* LINTED */
3375 (void) sprintf(bin,
2921 "/usr/sbin%.*s/zdb -bc%s%s -U /tmp/zpool.cache %s",
3376 "/usr/sbin%.*s/zdb -bcc%s%s -U /tmp/zpool.cache %s",
2922 isalen,
2923 isa,
2924 zopt_verbose >= 3 ? "s" : "",
2925 zopt_verbose >= 4 ? "v" : "",
2926 pool);
2927 free(isa);
2928
2929 if (zopt_verbose >= 5)

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

2961 if (zopt_verbose >= 6)
2962 (void) printf("\t%s\n", spa_name(spa));
2963 mutex_exit(&spa_namespace_lock);
2964}
2965
2966static void
2967ztest_spa_import_export(char *oldname, char *newname)
2968{
3377 isalen,
3378 isa,
3379 zopt_verbose >= 3 ? "s" : "",
3380 zopt_verbose >= 4 ? "v" : "",
3381 pool);
3382 free(isa);
3383
3384 if (zopt_verbose >= 5)

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

3416 if (zopt_verbose >= 6)
3417 (void) printf("\t%s\n", spa_name(spa));
3418 mutex_exit(&spa_namespace_lock);
3419}
3420
3421static void
3422ztest_spa_import_export(char *oldname, char *newname)
3423{
2969 nvlist_t *config;
3424 nvlist_t *config, *newconfig;
2970 uint64_t pool_guid;
2971 spa_t *spa;
2972 int error;
2973
2974 if (zopt_verbose >= 4) {
2975 (void) printf("import/export: old = %s, new = %s\n",
2976 oldname, newname);
2977 }

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

2983
2984 /*
2985 * Get the pool's configuration and guid.
2986 */
2987 error = spa_open(oldname, &spa, FTAG);
2988 if (error)
2989 fatal(0, "spa_open('%s') = %d", oldname, error);
2990
3425 uint64_t pool_guid;
3426 spa_t *spa;
3427 int error;
3428
3429 if (zopt_verbose >= 4) {
3430 (void) printf("import/export: old = %s, new = %s\n",
3431 oldname, newname);
3432 }

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

3438
3439 /*
3440 * Get the pool's configuration and guid.
3441 */
3442 error = spa_open(oldname, &spa, FTAG);
3443 if (error)
3444 fatal(0, "spa_open('%s') = %d", oldname, error);
3445
3446 /*
3447 * Kick off a scrub to tickle scrub/export races.
3448 */
3449 if (ztest_random(2) == 0)
3450 (void) spa_scrub(spa, POOL_SCRUB_EVERYTHING);
3451
2991 pool_guid = spa_guid(spa);
2992 spa_close(spa, FTAG);
2993
2994 ztest_walk_pool_directory("pools before export");
2995
2996 /*
2997 * Export it.
2998 */
2999 error = spa_export(oldname, &config, B_FALSE, B_FALSE);
3000 if (error)
3001 fatal(0, "spa_export('%s') = %d", oldname, error);
3002
3003 ztest_walk_pool_directory("pools after export");
3004
3005 /*
3452 pool_guid = spa_guid(spa);
3453 spa_close(spa, FTAG);
3454
3455 ztest_walk_pool_directory("pools before export");
3456
3457 /*
3458 * Export it.
3459 */
3460 error = spa_export(oldname, &config, B_FALSE, B_FALSE);
3461 if (error)
3462 fatal(0, "spa_export('%s') = %d", oldname, error);
3463
3464 ztest_walk_pool_directory("pools after export");
3465
3466 /*
3467 * Try to import it.
3468 */
3469 newconfig = spa_tryimport(config);
3470 ASSERT(newconfig != NULL);
3471 nvlist_free(newconfig);
3472
3473 /*
3006 * Import it under the new name.
3007 */
3008 error = spa_import(newname, config, NULL);
3009 if (error)
3010 fatal(0, "spa_import('%s') = %d", newname, error);
3011
3012 ztest_walk_pool_directory("pools after import");
3013

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

3039 if (error)
3040 fatal(0, "spa_open('%s') = %d", newname, error);
3041 ASSERT(pool_guid == spa_guid(spa));
3042 spa_close(spa, FTAG);
3043
3044 nvlist_free(config);
3045}
3046
3474 * Import it under the new name.
3475 */
3476 error = spa_import(newname, config, NULL);
3477 if (error)
3478 fatal(0, "spa_import('%s') = %d", newname, error);
3479
3480 ztest_walk_pool_directory("pools after import");
3481

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

3507 if (error)
3508 fatal(0, "spa_open('%s') = %d", newname, error);
3509 ASSERT(pool_guid == spa_guid(spa));
3510 spa_close(spa, FTAG);
3511
3512 nvlist_free(config);
3513}
3514
3515static void
3516ztest_resume(spa_t *spa)
3517{
3518 if (spa_suspended(spa)) {
3519 spa_vdev_state_enter(spa);
3520 vdev_clear(spa, NULL);
3521 (void) spa_vdev_state_exit(spa, NULL, 0);
3522 (void) zio_resume(spa);
3523 }
3524}
3525
3047static void *
3526static void *
3048ztest_resume(void *arg)
3527ztest_resume_thread(void *arg)
3049{
3050 spa_t *spa = arg;
3051
3052 while (!ztest_exiting) {
3053 (void) poll(NULL, 0, 1000);
3528{
3529 spa_t *spa = arg;
3530
3531 while (!ztest_exiting) {
3532 (void) poll(NULL, 0, 1000);
3054
3055 if (!spa_suspended(spa))
3056 continue;
3057
3058 spa_vdev_state_enter(spa);
3059 vdev_clear(spa, NULL);
3060 (void) spa_vdev_state_exit(spa, NULL, 0);
3061
3062 zio_resume(spa);
3533 ztest_resume(spa);
3063 }
3064 return (NULL);
3065}
3066
3067static void *
3068ztest_thread(void *arg)
3069{
3070 ztest_args_t *za = arg;

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

3197 mutex_exit(&spa_namespace_lock);
3198
3199 /*
3200 * Open our pool.
3201 */
3202 VERIFY(spa_open(pool, &spa, FTAG) == 0);
3203
3204 /*
3534 }
3535 return (NULL);
3536}
3537
3538static void *
3539ztest_thread(void *arg)
3540{
3541 ztest_args_t *za = arg;

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

3668 mutex_exit(&spa_namespace_lock);
3669
3670 /*
3671 * Open our pool.
3672 */
3673 VERIFY(spa_open(pool, &spa, FTAG) == 0);
3674
3675 /*
3676 * We don't expect the pool to suspend unless maxfaults == 0,
3677 * in which case ztest_fault_inject() temporarily takes away
3678 * the only valid replica.
3679 */
3680 if (zopt_maxfaults == 0)
3681 spa->spa_failmode = ZIO_FAILURE_MODE_WAIT;
3682 else
3683 spa->spa_failmode = ZIO_FAILURE_MODE_PANIC;
3684
3685 /*
3205 * Create a thread to periodically resume suspended I/O.
3206 */
3686 * Create a thread to periodically resume suspended I/O.
3687 */
3207 VERIFY(thr_create(0, 0, ztest_resume, spa, THR_BOUND,
3688 VERIFY(thr_create(0, 0, ztest_resume_thread, spa, THR_BOUND,
3208 &resume_tid) == 0);
3209
3210 /*
3211 * Verify that we can safely inquire about about any object,
3212 * whether it's allocated or not. To make it interesting,
3213 * we probe a 5-wide window around each power of two.
3214 * This hits all edge cases, including zero and the max.
3215 */

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

3248 za[t].za_zilog = za[d].za_zilog;
3249 za[t].za_instance = t;
3250 za[t].za_random = ztest_random(-1ULL);
3251 za[t].za_start = za[0].za_start;
3252 za[t].za_stop = za[0].za_stop;
3253 za[t].za_kill = za[0].za_kill;
3254
3255 if (t < zopt_datasets) {
3689 &resume_tid) == 0);
3690
3691 /*
3692 * Verify that we can safely inquire about about any object,
3693 * whether it's allocated or not. To make it interesting,
3694 * we probe a 5-wide window around each power of two.
3695 * This hits all edge cases, including zero and the max.
3696 */

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

3729 za[t].za_zilog = za[d].za_zilog;
3730 za[t].za_instance = t;
3731 za[t].za_random = ztest_random(-1ULL);
3732 za[t].za_start = za[0].za_start;
3733 za[t].za_stop = za[0].za_stop;
3734 za[t].za_kill = za[0].za_kill;
3735
3736 if (t < zopt_datasets) {
3256 ztest_replay_t zr;
3257 int test_future = FALSE;
3258 (void) rw_rdlock(&ztest_shared->zs_name_lock);
3259 (void) snprintf(name, 100, "%s/%s_%d", pool, pool, d);
3260 error = dmu_objset_create(name, DMU_OST_OTHER, NULL, 0,
3261 ztest_create_cb, NULL);
3262 if (error == EEXIST) {
3263 test_future = TRUE;
3264 } else if (error == ENOSPC) {

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

3272 error = dmu_objset_open(name, DMU_OST_OTHER,
3273 DS_MODE_USER, &za[d].za_os);
3274 if (error)
3275 fatal(0, "dmu_objset_open('%s') = %d",
3276 name, error);
3277 (void) rw_unlock(&ztest_shared->zs_name_lock);
3278 if (test_future)
3279 ztest_dmu_check_future_leak(&za[t]);
3737 int test_future = FALSE;
3738 (void) rw_rdlock(&ztest_shared->zs_name_lock);
3739 (void) snprintf(name, 100, "%s/%s_%d", pool, pool, d);
3740 error = dmu_objset_create(name, DMU_OST_OTHER, NULL, 0,
3741 ztest_create_cb, NULL);
3742 if (error == EEXIST) {
3743 test_future = TRUE;
3744 } else if (error == ENOSPC) {

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

3752 error = dmu_objset_open(name, DMU_OST_OTHER,
3753 DS_MODE_USER, &za[d].za_os);
3754 if (error)
3755 fatal(0, "dmu_objset_open('%s') = %d",
3756 name, error);
3757 (void) rw_unlock(&ztest_shared->zs_name_lock);
3758 if (test_future)
3759 ztest_dmu_check_future_leak(&za[t]);
3280 zr.zr_os = za[d].za_os;
3281 zil_replay(zr.zr_os, &zr, &zr.zr_assign,
3282 ztest_replay_vector, NULL);
3760 zil_replay(za[d].za_os, za[d].za_os,
3761 ztest_replay_vector);
3283 za[d].za_zilog = zil_open(za[d].za_os, NULL);
3284 }
3285
3286 VERIFY(thr_create(0, 0, ztest_thread, &za[t], THR_BOUND,
3287 &za[t].za_thread) == 0);
3288 }
3289
3290 while (--t >= 0) {

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

3319
3320 txg_wait_synced(spa_get_dsl(spa), 0);
3321
3322 umem_free(za, zopt_threads * sizeof (ztest_args_t));
3323
3324 /* Kill the resume thread */
3325 ztest_exiting = B_TRUE;
3326 VERIFY(thr_join(resume_tid, NULL, NULL) == 0);
3762 za[d].za_zilog = zil_open(za[d].za_os, NULL);
3763 }
3764
3765 VERIFY(thr_create(0, 0, ztest_thread, &za[t], THR_BOUND,
3766 &za[t].za_thread) == 0);
3767 }
3768
3769 while (--t >= 0) {

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

3798
3799 txg_wait_synced(spa_get_dsl(spa), 0);
3800
3801 umem_free(za, zopt_threads * sizeof (ztest_args_t));
3802
3803 /* Kill the resume thread */
3804 ztest_exiting = B_TRUE;
3805 VERIFY(thr_join(resume_tid, NULL, NULL) == 0);
3806 ztest_resume(spa);
3327
3328 /*
3329 * Right before closing the pool, kick off a bunch of async I/O;
3330 * spa_close() should wait for it to complete.
3331 */
3332 for (t = 1; t < 50; t++)
3333 dmu_prefetch(spa->spa_meta_objset, t, 0, 1 << 15);
3334

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

3386 nvlist_free(nvroot);
3387
3388 if (error)
3389 fatal(0, "spa_create() = %d", error);
3390 error = spa_open(pool, &spa, FTAG);
3391 if (error)
3392 fatal(0, "spa_open() = %d", error);
3393
3807
3808 /*
3809 * Right before closing the pool, kick off a bunch of async I/O;
3810 * spa_close() should wait for it to complete.
3811 */
3812 for (t = 1; t < 50; t++)
3813 dmu_prefetch(spa->spa_meta_objset, t, 0, 1 << 15);
3814

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

3866 nvlist_free(nvroot);
3867
3868 if (error)
3869 fatal(0, "spa_create() = %d", error);
3870 error = spa_open(pool, &spa, FTAG);
3871 if (error)
3872 fatal(0, "spa_open() = %d", error);
3873
3874 metaslab_sz = 1ULL << spa->spa_root_vdev->vdev_child[0]->vdev_ms_shift;
3875
3394 if (zopt_verbose >= 3)
3395 show_pool_stats(spa);
3396
3397 spa_close(spa, FTAG);
3398
3399 kernel_fini();
3400}
3401

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

3414
3415 /* Override location of zpool.cache */
3416 spa_config_path = "/tmp/zpool.cache";
3417
3418 ztest_random_fd = open("/dev/urandom", O_RDONLY);
3419
3420 process_options(argc, argv);
3421
3876 if (zopt_verbose >= 3)
3877 show_pool_stats(spa);
3878
3879 spa_close(spa, FTAG);
3880
3881 kernel_fini();
3882}
3883

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

3896
3897 /* Override location of zpool.cache */
3898 spa_config_path = "/tmp/zpool.cache";
3899
3900 ztest_random_fd = open("/dev/urandom", O_RDONLY);
3901
3902 process_options(argc, argv);
3903
3422 argc -= optind;
3423 argv += optind;
3424
3425 dprintf_setup(&argc, argv);
3426
3427 /*
3428 * Blow away any existing copy of zpool.cache
3429 */
3430 if (zopt_init != 0)
3431 (void) remove("/tmp/zpool.cache");
3432
3433 zs = ztest_shared = (void *)mmap(0,
3434 P2ROUNDUP(sizeof (ztest_shared_t), getpagesize()),

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

3482 * Initialize the workload counters for each function.
3483 */
3484 for (f = 0; f < ZTEST_FUNCS; f++) {
3485 zi = &zs->zs_info[f];
3486 zi->zi_calls = 0;
3487 zi->zi_call_time = 0;
3488 }
3489
3904 /*
3905 * Blow away any existing copy of zpool.cache
3906 */
3907 if (zopt_init != 0)
3908 (void) remove("/tmp/zpool.cache");
3909
3910 zs = ztest_shared = (void *)mmap(0,
3911 P2ROUNDUP(sizeof (ztest_shared_t), getpagesize()),

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

3959 * Initialize the workload counters for each function.
3960 */
3961 for (f = 0; f < ZTEST_FUNCS; f++) {
3962 zi = &zs->zs_info[f];
3963 zi->zi_calls = 0;
3964 zi->zi_call_time = 0;
3965 }
3966
3967 /* Set the allocation switch size */
3968 metaslab_df_alloc_threshold = ztest_random(metaslab_sz / 4) + 1;
3969
3490 pid = fork();
3491
3492 if (pid == -1)
3493 fatal(1, "fork failed");
3494
3495 if (pid == 0) { /* child */
3496 struct rlimit rl = { 1024, 1024 };
3497 (void) setrlimit(RLIMIT_NOFILE, &rl);

--- 91 unchanged lines hidden ---
3970 pid = fork();
3971
3972 if (pid == -1)
3973 fatal(1, "fork failed");
3974
3975 if (pid == 0) { /* child */
3976 struct rlimit rl = { 1024, 1024 };
3977 (void) setrlimit(RLIMIT_NOFILE, &rl);

--- 91 unchanged lines hidden ---