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

Function ztest_trim

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

ARGSUSED */

Source from the content-addressed store, hash-verified

6515
6516/* ARGSUSED */
6517void
6518ztest_trim(ztest_ds_t *zd, uint64_t id)
6519{
6520 spa_t *spa = ztest_spa;
6521 int error = 0;
6522
6523 mutex_enter(&ztest_vdev_lock);
6524
6525 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
6526
6527 /* Random leaf vdev */
6528 vdev_t *rand_vd = ztest_random_concrete_vdev_leaf(spa->spa_root_vdev);
6529 if (rand_vd == NULL) {
6530 spa_config_exit(spa, SCL_VDEV, FTAG);
6531 mutex_exit(&ztest_vdev_lock);
6532 return;
6533 }
6534
6535 /*
6536 * The random vdev we've selected may change as soon as we
6537 * drop the spa_config_lock. We create local copies of things
6538 * we're interested in.
6539 */
6540 uint64_t guid = rand_vd->vdev_guid;
6541 char *path = strdup(rand_vd->vdev_path);
6542 boolean_t active = rand_vd->vdev_trim_thread != NULL;
6543
6544 zfs_dbgmsg("vd %p, guid %llu", rand_vd, guid);
6545 spa_config_exit(spa, SCL_VDEV, FTAG);
6546
6547 uint64_t cmd = ztest_random(POOL_TRIM_FUNCS);
6548 uint64_t rate = 1 << ztest_random(30);
6549 boolean_t partial = (ztest_random(5) > 0);
6550 boolean_t secure = (ztest_random(5) > 0);
6551
6552 nvlist_t *vdev_guids = fnvlist_alloc();
6553 nvlist_t *vdev_errlist = fnvlist_alloc();
6554 fnvlist_add_uint64(vdev_guids, path, guid);
6555 error = spa_vdev_trim(spa, vdev_guids, cmd, rate, partial,
6556 secure, vdev_errlist);
6557 fnvlist_free(vdev_guids);
6558 fnvlist_free(vdev_errlist);
6559
6560 switch (cmd) {
6561 case POOL_TRIM_CANCEL:
6562 if (ztest_opts.zo_verbose >= 4) {
6563 (void) printf("Cancel TRIM %s", path);
6564 if (!active)
6565 (void) printf(" failed (no TRIM active)");
6566 (void) printf("\n");
6567 }
6568 break;
6569 case POOL_TRIM_START:
6570 if (ztest_opts.zo_verbose >= 4) {
6571 (void) printf("Start TRIM %s", path);
6572 if (active && error == 0)
6573 (void) printf(" failed (already active)");
6574 else if (error != 0)

Callers

nothing calls this directly

Calls 14

mutex_enterFunction · 0.85
spa_config_enterFunction · 0.85
spa_config_exitFunction · 0.85
mutex_exitFunction · 0.85
strdupFunction · 0.85
ztest_randomFunction · 0.85
fnvlist_allocFunction · 0.85
fnvlist_add_uint64Function · 0.85
spa_vdev_trimFunction · 0.85
fnvlist_freeFunction · 0.85
zfs_dbgmsgClass · 0.50

Tested by

no test coverage detected