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

Function l2arc_add_vdev

freebsd/contrib/openzfs/module/zfs/arc.c:9466–9526  ·  view source on GitHub ↗

* Add a vdev for use by the L2ARC. By this point the spa has already * validated the vdev and opened it. */

Source from the content-addressed store, hash-verified

9464 * validated the vdev and opened it.
9465 */
9466void
9467l2arc_add_vdev(spa_t *spa, vdev_t *vd)
9468{
9469 l2arc_dev_t *adddev;
9470 uint64_t l2dhdr_asize;
9471
9472 ASSERT(!l2arc_vdev_present(vd));
9473
9474 /*
9475 * Create a new l2arc device entry.
9476 */
9477 adddev = vmem_zalloc(sizeof (l2arc_dev_t), KM_SLEEP);
9478 adddev->l2ad_spa = spa;
9479 adddev->l2ad_vdev = vd;
9480 /* leave extra size for an l2arc device header */
9481 l2dhdr_asize = adddev->l2ad_dev_hdr_asize =
9482 MAX(sizeof (*adddev->l2ad_dev_hdr), 1 << vd->vdev_ashift);
9483 adddev->l2ad_start = VDEV_LABEL_START_SIZE + l2dhdr_asize;
9484 adddev->l2ad_end = VDEV_LABEL_START_SIZE + vdev_get_min_asize(vd);
9485 ASSERT3U(adddev->l2ad_start, <, adddev->l2ad_end);
9486 adddev->l2ad_hand = adddev->l2ad_start;
9487 adddev->l2ad_evict = adddev->l2ad_start;
9488 adddev->l2ad_first = B_TRUE;
9489 adddev->l2ad_writing = B_FALSE;
9490 adddev->l2ad_trim_all = B_FALSE;
9491 list_link_init(&adddev->l2ad_node);
9492 adddev->l2ad_dev_hdr = kmem_zalloc(l2dhdr_asize, KM_SLEEP);
9493
9494 mutex_init(&adddev->l2ad_mtx, NULL, MUTEX_DEFAULT, NULL);
9495 /*
9496 * This is a list of all ARC buffers that are still valid on the
9497 * device.
9498 */
9499 list_create(&adddev->l2ad_buflist, sizeof (arc_buf_hdr_t),
9500 offsetof(arc_buf_hdr_t, b_l2hdr.b_l2node));
9501
9502 /*
9503 * This is a list of pointers to log blocks that are still present
9504 * on the device.
9505 */
9506 list_create(&adddev->l2ad_lbptr_list, sizeof (l2arc_lb_ptr_buf_t),
9507 offsetof(l2arc_lb_ptr_buf_t, node));
9508
9509 vdev_space_update(vd, 0, 0, adddev->l2ad_end - adddev->l2ad_hand);
9510 zfs_refcount_create(&adddev->l2ad_alloc);
9511 zfs_refcount_create(&adddev->l2ad_lb_asize);
9512 zfs_refcount_create(&adddev->l2ad_lb_count);
9513
9514 /*
9515 * Add device to global list
9516 */
9517 mutex_enter(&l2arc_dev_mtx);
9518 list_insert_head(l2arc_dev_list, adddev);
9519 atomic_inc_64(&l2arc_ndev);
9520 mutex_exit(&l2arc_dev_mtx);
9521
9522 /*
9523 * Decide if vdev is eligible for L2ARC rebuild

Callers 2

vdev_reopenFunction · 0.85
spa_load_l2cacheFunction · 0.85

Calls 12

l2arc_vdev_presentFunction · 0.85
vdev_get_min_asizeFunction · 0.85
vdev_space_updateFunction · 0.85
zfs_refcount_createFunction · 0.85
mutex_enterFunction · 0.85
atomic_inc_64Function · 0.85
mutex_exitFunction · 0.85
l2arc_rebuild_vdevFunction · 0.85
list_link_initFunction · 0.50
mutex_initFunction · 0.50
list_createFunction · 0.50
list_insert_headFunction · 0.50

Tested by

no test coverage detected