MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ztest_freeze

Function ztest_freeze

freebsd/contrib/openzfs/cmd/ztest/ztest.c:7052–7140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7050}
7051
7052static void
7053ztest_freeze(void)
7054{
7055 ztest_ds_t *zd = &ztest_ds[0];
7056 spa_t *spa;
7057 int numloops = 0;
7058
7059 if (ztest_opts.zo_verbose >= 3)
7060 (void) printf("testing spa_freeze()...\n");
7061
7062 kernel_init(SPA_MODE_READ | SPA_MODE_WRITE);
7063 VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
7064 VERIFY3U(0, ==, ztest_dataset_open(0));
7065 ztest_spa = spa;
7066
7067 /*
7068 * Force the first log block to be transactionally allocated.
7069 * We have to do this before we freeze the pool -- otherwise
7070 * the log chain won't be anchored.
7071 */
7072 while (BP_IS_HOLE(&zd->zd_zilog->zl_header->zh_log)) {
7073 ztest_dmu_object_alloc_free(zd, 0);
7074 zil_commit(zd->zd_zilog, 0);
7075 }
7076
7077 txg_wait_synced(spa_get_dsl(spa), 0);
7078
7079 /*
7080 * Freeze the pool. This stops spa_sync() from doing anything,
7081 * so that the only way to record changes from now on is the ZIL.
7082 */
7083 spa_freeze(spa);
7084
7085 /*
7086 * Because it is hard to predict how much space a write will actually
7087 * require beforehand, we leave ourselves some fudge space to write over
7088 * capacity.
7089 */
7090 uint64_t capacity = metaslab_class_get_space(spa_normal_class(spa)) / 2;
7091
7092 /*
7093 * Run tests that generate log records but don't alter the pool config
7094 * or depend on DSL sync tasks (snapshots, objset create/destroy, etc).
7095 * We do a txg_wait_synced() after each iteration to force the txg
7096 * to increase well beyond the last synced value in the uberblock.
7097 * The ZIL should be OK with that.
7098 *
7099 * Run a random number of times less than zo_maxloops and ensure we do
7100 * not run out of space on the pool.
7101 */
7102 while (ztest_random(10) != 0 &&
7103 numloops++ < ztest_opts.zo_maxloops &&
7104 metaslab_class_get_alloc(spa_normal_class(spa)) < capacity) {
7105 ztest_od_t od;
7106 ztest_od_init(&od, 0, FTAG, 0, DMU_OT_UINT64_OTHER, 0, 0, 0);
7107 VERIFY0(ztest_object_init(zd, &od, sizeof (od), B_FALSE));
7108 ztest_io(zd, od.od_object,
7109 ztest_random(ZTEST_RANGE_LOCKS) << SPA_MAXBLOCKSHIFT);

Callers 2

ztest_importFunction · 0.85
ztest_initFunction · 0.85

Calls 15

kernel_initFunction · 0.85
spa_openFunction · 0.85
ztest_dataset_openFunction · 0.85
zil_commitFunction · 0.85
txg_wait_syncedFunction · 0.85
spa_get_dslFunction · 0.85
spa_freezeFunction · 0.85
metaslab_class_get_spaceFunction · 0.85
spa_normal_classFunction · 0.85
ztest_randomFunction · 0.85
metaslab_class_get_allocFunction · 0.85

Tested by

no test coverage detected