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

Function vdev_alloc_common

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

* Allocate and minimally initialize a vdev_t. */

Source from the content-addressed store, hash-verified

537 * Allocate and minimally initialize a vdev_t.
538 */
539vdev_t *
540vdev_alloc_common(spa_t *spa, uint_t id, uint64_t guid, vdev_ops_t *ops)
541{
542 vdev_t *vd;
543 vdev_indirect_config_t *vic;
544
545 vd = kmem_zalloc(sizeof (vdev_t), KM_SLEEP);
546 vic = &vd->vdev_indirect_config;
547
548 if (spa->spa_root_vdev == NULL) {
549 ASSERT(ops == &vdev_root_ops);
550 spa->spa_root_vdev = vd;
551 spa->spa_load_guid = spa_generate_guid(NULL);
552 }
553
554 if (guid == 0 && ops != &vdev_hole_ops) {
555 if (spa->spa_root_vdev == vd) {
556 /*
557 * The root vdev's guid will also be the pool guid,
558 * which must be unique among all pools.
559 */
560 guid = spa_generate_guid(NULL);
561 } else {
562 /*
563 * Any other vdev's guid must be unique within the pool.
564 */
565 guid = spa_generate_guid(spa);
566 }
567 ASSERT(!spa_guid_exists(spa_guid(spa), guid));
568 }
569
570 vd->vdev_spa = spa;
571 vd->vdev_id = id;
572 vd->vdev_guid = guid;
573 vd->vdev_guid_sum = guid;
574 vd->vdev_ops = ops;
575 vd->vdev_state = VDEV_STATE_CLOSED;
576 vd->vdev_ishole = (ops == &vdev_hole_ops);
577 vic->vic_prev_indirect_vdev = UINT64_MAX;
578
579 rw_init(&vd->vdev_indirect_rwlock, NULL, RW_DEFAULT, NULL);
580 mutex_init(&vd->vdev_obsolete_lock, NULL, MUTEX_DEFAULT, NULL);
581 vd->vdev_obsolete_segments = range_tree_create(NULL, RANGE_SEG64, NULL,
582 0, 0);
583
584 /*
585 * Initialize rate limit structs for events. We rate limit ZIO delay
586 * and checksum events so that we don't overwhelm ZED with thousands
587 * of events when a disk is acting up.
588 */
589 zfs_ratelimit_init(&vd->vdev_delay_rl, &zfs_slow_io_events_per_second,
590 1);
591 zfs_ratelimit_init(&vd->vdev_checksum_rl,
592 &zfs_checksum_events_per_second, 1);
593
594 list_link_init(&vd->vdev_config_dirty_node);
595 list_link_init(&vd->vdev_state_dirty_node);
596 list_link_init(&vd->vdev_initialize_node);

Callers 3

vdev_allocFunction · 0.85
vdev_add_parentFunction · 0.85

Calls 13

spa_generate_guidFunction · 0.85
spa_guid_existsFunction · 0.85
spa_guidFunction · 0.85
rw_initFunction · 0.85
range_tree_createFunction · 0.85
zfs_ratelimit_initFunction · 0.85
txg_list_createFunction · 0.85
vdev_queue_initFunction · 0.85
vdev_cache_initFunction · 0.85
mutex_initFunction · 0.50
list_link_initFunction · 0.50
cv_initFunction · 0.50

Tested by

no test coverage detected