@@ -1488,6 +1488,88 @@ int vdo_decode_super_block(u8 *buffer)
14881488 return ((checksum != saved_checksum ) ? VDO_CHECKSUM_MISMATCH : VDO_SUCCESS );
14891489}
14901490
1491+ /**
1492+ * vdo_initialize_component_states() - Initialize the components so they can be written out.
1493+ * @vdo_config: The config used for component state initialization.
1494+ * @geometry: The volume geometry used to calculate the data region offset.
1495+ * @nonce: The nonce to use to identify the vdo.
1496+ * @states: The component states to initialize.
1497+ *
1498+ * Return: VDO_SUCCESS or an error code.
1499+ */
1500+ int vdo_initialize_component_states (const struct vdo_config * vdo_config ,
1501+ const struct volume_geometry * geometry ,
1502+ nonce_t nonce ,
1503+ struct vdo_component_states * states )
1504+ {
1505+ int result ;
1506+ struct slab_config slab_config ;
1507+ struct partition * partition ;
1508+
1509+ states -> vdo .config = * vdo_config ;
1510+ states -> vdo .nonce = nonce ;
1511+ states -> volume_version = VDO_VOLUME_VERSION_67_0 ;
1512+
1513+ states -> recovery_journal = (struct recovery_journal_state_7_0 ) {
1514+ .journal_start = RECOVERY_JOURNAL_STARTING_SEQUENCE_NUMBER ,
1515+ .logical_blocks_used = 0 ,
1516+ .block_map_data_blocks = 0 ,
1517+ };
1518+
1519+ /*
1520+ * The layout starts 1 block past the beginning of the data region, as the
1521+ * data region contains the super block but the layout does not.
1522+ */
1523+ result = vdo_initialize_layout (vdo_config -> physical_blocks ,
1524+ vdo_get_data_region_start (* geometry ) + 1 ,
1525+ DEFAULT_VDO_BLOCK_MAP_TREE_ROOT_COUNT ,
1526+ vdo_config -> recovery_journal_size ,
1527+ VDO_SLAB_SUMMARY_BLOCKS ,
1528+ & states -> layout );
1529+ if (result != VDO_SUCCESS )
1530+ return result ;
1531+
1532+ result = vdo_configure_slab (vdo_config -> slab_size ,
1533+ vdo_config -> slab_journal_blocks ,
1534+ & slab_config );
1535+ if (result != VDO_SUCCESS ) {
1536+ vdo_uninitialize_layout (& states -> layout );
1537+ return result ;
1538+ }
1539+
1540+ result = vdo_get_partition (& states -> layout , VDO_SLAB_DEPOT_PARTITION ,
1541+ & partition );
1542+ if (result != VDO_SUCCESS ) {
1543+ vdo_uninitialize_layout (& states -> layout );
1544+ return result ;
1545+ }
1546+
1547+ result = vdo_configure_slab_depot (partition , slab_config , 0 ,
1548+ & states -> slab_depot );
1549+ if (result != VDO_SUCCESS ) {
1550+ vdo_uninitialize_layout (& states -> layout );
1551+ return result ;
1552+ }
1553+
1554+ result = vdo_get_partition (& states -> layout , VDO_BLOCK_MAP_PARTITION ,
1555+ & partition );
1556+ if (result != VDO_SUCCESS ) {
1557+ vdo_uninitialize_layout (& states -> layout );
1558+ return result ;
1559+ }
1560+
1561+ states -> block_map = (struct block_map_state_2_0 ) {
1562+ .flat_page_origin = VDO_BLOCK_MAP_FLAT_PAGE_ORIGIN ,
1563+ .flat_page_count = 0 ,
1564+ .root_origin = partition -> offset ,
1565+ .root_count = DEFAULT_VDO_BLOCK_MAP_TREE_ROOT_COUNT ,
1566+ };
1567+
1568+ states -> vdo .state = VDO_NEW ;
1569+
1570+ return VDO_SUCCESS ;
1571+ }
1572+
14911573/**
14921574 * vdo_compute_index_blocks() - Compute the number of blocks that the indexer will use.
14931575 * @config: The index config from which the blocks are calculated.
0 commit comments