ARGSUSED */
| 6443 | |
| 6444 | /* ARGSUSED */ |
| 6445 | void |
| 6446 | ztest_initialize(ztest_ds_t *zd, uint64_t id) |
| 6447 | { |
| 6448 | spa_t *spa = ztest_spa; |
| 6449 | int error = 0; |
| 6450 | |
| 6451 | mutex_enter(&ztest_vdev_lock); |
| 6452 | |
| 6453 | spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER); |
| 6454 | |
| 6455 | /* Random leaf vdev */ |
| 6456 | vdev_t *rand_vd = ztest_random_concrete_vdev_leaf(spa->spa_root_vdev); |
| 6457 | if (rand_vd == NULL) { |
| 6458 | spa_config_exit(spa, SCL_VDEV, FTAG); |
| 6459 | mutex_exit(&ztest_vdev_lock); |
| 6460 | return; |
| 6461 | } |
| 6462 | |
| 6463 | /* |
| 6464 | * The random vdev we've selected may change as soon as we |
| 6465 | * drop the spa_config_lock. We create local copies of things |
| 6466 | * we're interested in. |
| 6467 | */ |
| 6468 | uint64_t guid = rand_vd->vdev_guid; |
| 6469 | char *path = strdup(rand_vd->vdev_path); |
| 6470 | boolean_t active = rand_vd->vdev_initialize_thread != NULL; |
| 6471 | |
| 6472 | zfs_dbgmsg("vd %px, guid %llu", rand_vd, guid); |
| 6473 | spa_config_exit(spa, SCL_VDEV, FTAG); |
| 6474 | |
| 6475 | uint64_t cmd = ztest_random(POOL_INITIALIZE_FUNCS); |
| 6476 | |
| 6477 | nvlist_t *vdev_guids = fnvlist_alloc(); |
| 6478 | nvlist_t *vdev_errlist = fnvlist_alloc(); |
| 6479 | fnvlist_add_uint64(vdev_guids, path, guid); |
| 6480 | error = spa_vdev_initialize(spa, vdev_guids, cmd, vdev_errlist); |
| 6481 | fnvlist_free(vdev_guids); |
| 6482 | fnvlist_free(vdev_errlist); |
| 6483 | |
| 6484 | switch (cmd) { |
| 6485 | case POOL_INITIALIZE_CANCEL: |
| 6486 | if (ztest_opts.zo_verbose >= 4) { |
| 6487 | (void) printf("Cancel initialize %s", path); |
| 6488 | if (!active) |
| 6489 | (void) printf(" failed (no initialize active)"); |
| 6490 | (void) printf("\n"); |
| 6491 | } |
| 6492 | break; |
| 6493 | case POOL_INITIALIZE_START: |
| 6494 | if (ztest_opts.zo_verbose >= 4) { |
| 6495 | (void) printf("Start initialize %s", path); |
| 6496 | if (active && error == 0) |
| 6497 | (void) printf(" failed (already active)"); |
| 6498 | else if (error != 0) |
| 6499 | (void) printf(" failed (error %d)", error); |
| 6500 | (void) printf("\n"); |
| 6501 | } |
| 6502 | break; |
nothing calls this directly
no test coverage detected