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

Function vdev_metaslab_init

freebsd/contrib/openzfs/module/zfs/vdev.c:1339–1434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1337}
1338
1339int
1340vdev_metaslab_init(vdev_t *vd, uint64_t txg)
1341{
1342 spa_t *spa = vd->vdev_spa;
1343 objset_t *mos = spa->spa_meta_objset;
1344 uint64_t m;
1345 uint64_t oldc = vd->vdev_ms_count;
1346 uint64_t newc = vd->vdev_asize >> vd->vdev_ms_shift;
1347 metaslab_t **mspp;
1348 int error;
1349 boolean_t expanding = (oldc != 0);
1350
1351 ASSERT(txg == 0 || spa_config_held(spa, SCL_ALLOC, RW_WRITER));
1352
1353 /*
1354 * This vdev is not being allocated from yet or is a hole.
1355 */
1356 if (vd->vdev_ms_shift == 0)
1357 return (0);
1358
1359 ASSERT(!vd->vdev_ishole);
1360
1361 ASSERT(oldc <= newc);
1362
1363 mspp = vmem_zalloc(newc * sizeof (*mspp), KM_SLEEP);
1364
1365 if (expanding) {
1366 bcopy(vd->vdev_ms, mspp, oldc * sizeof (*mspp));
1367 vmem_free(vd->vdev_ms, oldc * sizeof (*mspp));
1368 }
1369
1370 vd->vdev_ms = mspp;
1371 vd->vdev_ms_count = newc;
1372 for (m = oldc; m < newc; m++) {
1373 uint64_t object = 0;
1374
1375 /*
1376 * vdev_ms_array may be 0 if we are creating the "fake"
1377 * metaslabs for an indirect vdev for zdb's leak detection.
1378 * See zdb_leak_init().
1379 */
1380 if (txg == 0 && vd->vdev_ms_array != 0) {
1381 error = dmu_read(mos, vd->vdev_ms_array,
1382 m * sizeof (uint64_t), sizeof (uint64_t), &object,
1383 DMU_READ_PREFETCH);
1384 if (error != 0) {
1385 vdev_dbgmsg(vd, "unable to read the metaslab "
1386 "array [error=%d]", error);
1387 return (error);
1388 }
1389 }
1390
1391#ifndef _KERNEL
1392 /*
1393 * To accommodate zdb_leak_init() fake indirect
1394 * metaslabs, we allocate a metaslab group for
1395 * indirect vdevs which normally don't have one.
1396 */

Callers 3

vdev_loadFunction · 0.85
vdev_expandFunction · 0.85

Calls 11

spa_config_heldFunction · 0.85
vmem_freeFunction · 0.85
dmu_readFunction · 0.85
vdev_dbgmsgFunction · 0.85
vdev_is_concreteFunction · 0.85
metaslab_initFunction · 0.85
spa_config_enterFunction · 0.85
metaslab_group_activateFunction · 0.85
spa_config_exitFunction · 0.85

Tested by

no test coverage detected