Skip to content

Commit e073bb0

Browse files
bjohnstoMikulas Patocka
authored andcommitted
dm vdo: add super block initialization to encodings.c
Add vdo_initialize_component_states() to populate the super block, computing the space required for the main VDO components on disk. Those include the slab depot, block map, and recovery journal. Signed-off-by: Bruce Johnston <bjohnsto@redhat.com> Reviewed-by: Matthew Sakai <msakai@redhat.com> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
1 parent 4b4a8d9 commit e073bb0

3 files changed

Lines changed: 90 additions & 0 deletions

File tree

drivers/md/dm-vdo/constants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ enum {
4444
/* The default size of each slab journal, in blocks */
4545
DEFAULT_VDO_SLAB_JOURNAL_SIZE = 224,
4646

47+
/* The recovery journal starting sequence number set at format time */
48+
RECOVERY_JOURNAL_STARTING_SEQUENCE_NUMBER = 1,
49+
4750
/*
4851
* The initial size of lbn_operations and pbn_operations, which is based upon the expected
4952
* maximum number of outstanding VIOs. This value was chosen to make it highly unlikely

drivers/md/dm-vdo/encodings.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

drivers/md/dm-vdo/encodings.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,11 @@ int __must_check vdo_validate_component_states(struct vdo_component_states *stat
12681268
void vdo_encode_super_block(u8 *buffer, struct vdo_component_states *states);
12691269
int __must_check vdo_decode_super_block(u8 *buffer);
12701270

1271+
int vdo_initialize_component_states(const struct vdo_config *vdo_config,
1272+
const struct volume_geometry *geometry,
1273+
nonce_t nonce,
1274+
struct vdo_component_states *states);
1275+
12711276
/* We start with 0L and postcondition with ~0L to match our historical usage in userspace. */
12721277
static inline u32 vdo_crc32(const void *buf, unsigned long len)
12731278
{

0 commit comments

Comments
 (0)