Lines Matching full:layout
6 #include "index-layout.h"
21 * The UDS layout on storage media is divided into a number of fixed-size regions, the sizes of
40 * The header contains the encoded region layout table as well as some index configuration data.
53 * The header contains the encoded region layout table as well as index state data for that save.
101 static const u8 LAYOUT_MAGIC[MAGIC_SIZE] = "*ALBIREO*SINGLE*FILE*LAYOUT*001*";
321 static int __must_check open_layout_reader(struct index_layout *layout, in open_layout_reader() argument
325 return uds_make_buffered_reader(layout->factory, lr->start_block + offset, in open_layout_reader()
329 static int open_region_reader(struct index_layout *layout, struct layout_region *region, in open_region_reader() argument
332 return open_layout_reader(layout, region, -layout->super.start_offset, in open_region_reader()
336 static int __must_check open_layout_writer(struct index_layout *layout, in open_layout_writer() argument
340 return uds_make_buffered_writer(layout->factory, lr->start_block + offset, in open_layout_writer()
344 static int open_region_writer(struct index_layout *layout, struct layout_region *region, in open_region_writer() argument
347 return open_layout_writer(layout, region, -layout->super.start_offset, in open_region_writer()
370 static void define_sub_index_nonce(struct index_layout *layout) in define_sub_index_nonce() argument
376 struct sub_index_layout *sil = &layout->index; in define_sub_index_nonce()
377 u64 primary_nonce = layout->super.nonce; in define_sub_index_nonce()
390 static void setup_sub_index(struct index_layout *layout, u64 start_block, in setup_sub_index() argument
393 struct sub_index_layout *sil = &layout->index; in setup_sub_index()
424 define_sub_index_nonce(layout); in setup_sub_index()
427 static void initialize_layout(struct index_layout *layout, struct save_layout_sizes *sls) in initialize_layout() argument
429 u64 next_block = layout->offset / sls->block_size; in initialize_layout()
431 layout->total_blocks = sls->total_blocks; in initialize_layout()
432 generate_super_block_data(sls, &layout->super); in initialize_layout()
433 layout->header = (struct layout_region) { in initialize_layout()
440 layout->config = (struct layout_region) { in initialize_layout()
447 setup_sub_index(layout, next_block, sls); in initialize_layout()
450 layout->seal = (struct layout_region) { in initialize_layout()
489 "layout region table for ISL", &table); in make_index_save_region_table()
574 static int write_index_save_layout(struct index_layout *layout, in write_index_save_layout() argument
585 result = open_region_writer(layout, &isl->header, &writer); in write_index_save_layout()
631 static int __must_check invalidate_old_save(struct index_layout *layout, in invalidate_old_save() argument
634 reset_index_save_layout(isl, layout->super.page_map_blocks); in invalidate_old_save()
635 return write_index_save_layout(layout, isl); in invalidate_old_save()
638 static int discard_index_state_data(struct index_layout *layout) in discard_index_state_data() argument
644 for (i = 0; i < layout->super.max_saves; i++) { in discard_index_state_data()
645 result = invalidate_old_save(layout, &layout->index.saves[i]); in discard_index_state_data()
659 static int __must_check make_layout_region_table(struct index_layout *layout, in make_layout_region_table() argument
665 u16 region_count = 5 + layout->super.max_saves; in make_layout_region_table()
671 struct layout_region, "layout region table", in make_layout_region_table()
677 *lr++ = layout->header; in make_layout_region_table()
678 *lr++ = layout->config; in make_layout_region_table()
679 *lr++ = layout->index.sub_index; in make_layout_region_table()
680 *lr++ = layout->index.volume; in make_layout_region_table()
682 for (i = 0; i < layout->super.max_saves; i++) in make_layout_region_table()
683 *lr++ = layout->index.saves[i].index_save; in make_layout_region_table()
685 *lr++ = layout->seal; in make_layout_region_table()
687 if (is_converted_super_block(&layout->super)) { in make_layout_region_table()
691 sizeof(layout->super.volume_offset) - in make_layout_region_table()
692 sizeof(layout->super.start_offset)); in make_layout_region_table()
697 .region_blocks = layout->total_blocks, in make_layout_region_table()
710 static int __must_check write_layout_header(struct index_layout *layout, in write_layout_header() argument
718 result = vdo_allocate(table->encoded_size, u8, "layout data", &buffer); in write_layout_header()
723 memcpy(buffer + offset, &layout->super.magic_label, MAGIC_SIZE); in write_layout_header()
725 memcpy(buffer + offset, &layout->super.nonce_info, NONCE_INFO_SIZE); in write_layout_header()
727 encode_u64_le(buffer, &offset, layout->super.nonce); in write_layout_header()
728 encode_u32_le(buffer, &offset, layout->super.version); in write_layout_header()
729 encode_u32_le(buffer, &offset, layout->super.block_size); in write_layout_header()
730 encode_u16_le(buffer, &offset, layout->super.index_count); in write_layout_header()
731 encode_u16_le(buffer, &offset, layout->super.max_saves); in write_layout_header()
733 encode_u64_le(buffer, &offset, layout->super.open_chapter_blocks); in write_layout_header()
734 encode_u64_le(buffer, &offset, layout->super.page_map_blocks); in write_layout_header()
736 if (is_converted_super_block(&layout->super)) { in write_layout_header()
737 encode_u64_le(buffer, &offset, layout->super.volume_offset); in write_layout_header()
738 encode_u64_le(buffer, &offset, layout->super.start_offset); in write_layout_header()
749 static int __must_check write_uds_index_config(struct index_layout *layout, in write_uds_index_config() argument
756 result = open_layout_writer(layout, &layout->config, offset, &writer); in write_uds_index_config()
760 result = uds_write_config_contents(writer, config, layout->super.version); in write_uds_index_config()
776 static int __must_check save_layout(struct index_layout *layout, off_t offset) in save_layout() argument
782 result = make_layout_region_table(layout, &table); in save_layout()
786 result = open_layout_writer(layout, &layout->header, offset, &writer); in save_layout()
792 result = write_layout_header(layout, table, writer); in save_layout()
799 static int create_index_layout(struct index_layout *layout, struct uds_configuration *config) in create_index_layout() argument
809 &layout->index.saves); in create_index_layout()
813 initialize_layout(layout, &sizes); in create_index_layout()
815 result = discard_index_state_data(layout); in create_index_layout()
819 result = write_uds_index_config(layout, config, 0); in create_index_layout()
823 return save_layout(layout, 0); in create_index_layout()
857 static int find_latest_uds_index_save_slot(struct index_layout *layout, in find_latest_uds_index_save_slot() argument
866 for (i = 0; i < layout->super.max_saves; i++) { in find_latest_uds_index_save_slot()
867 isl = &layout->index.saves[i]; in find_latest_uds_index_save_slot()
868 save_time = validate_index_save_layout(isl, layout->index.nonce); in find_latest_uds_index_save_slot()
884 int uds_discard_open_chapter(struct index_layout *layout) in uds_discard_open_chapter() argument
890 result = find_latest_uds_index_save_slot(layout, &isl); in uds_discard_open_chapter()
894 result = open_region_writer(layout, &isl->open_chapter, &writer); in uds_discard_open_chapter()
909 int uds_load_index_state(struct index_layout *layout, struct uds_index *index) in uds_load_index_state() argument
916 result = find_latest_uds_index_save_slot(layout, &isl); in uds_load_index_state()
924 result = open_region_reader(layout, &isl->open_chapter, &readers[0]); in uds_load_index_state()
934 result = open_region_reader(layout, &isl->volume_index_zones[zone], in uds_load_index_state()
950 result = open_region_reader(layout, &isl->index_page_map, &readers[0]); in uds_load_index_state()
960 static struct index_save_layout *select_oldest_index_save_layout(struct index_layout *layout) in select_oldest_index_save_layout() argument
968 for (i = 0; i < layout->super.max_saves; i++) { in select_oldest_index_save_layout()
969 isl = &layout->index.saves[i]; in select_oldest_index_save_layout()
970 save_time = validate_index_save_layout(isl, layout->index.nonce); in select_oldest_index_save_layout()
1044 static int setup_uds_index_save_slot(struct index_layout *layout, in setup_uds_index_save_slot() argument
1051 isl = select_oldest_index_save_layout(layout); in setup_uds_index_save_slot()
1052 result = invalidate_old_save(layout, isl); in setup_uds_index_save_slot()
1056 instantiate_index_save_layout(isl, &layout->super, layout->index.nonce, in setup_uds_index_save_slot()
1070 int uds_save_index_state(struct index_layout *layout, struct uds_index *index) in uds_save_index_state() argument
1077 result = setup_uds_index_save_slot(layout, index->zone_count, &isl); in uds_save_index_state()
1087 result = open_region_writer(layout, &isl->open_chapter, &writers[0]); in uds_save_index_state()
1101 result = open_region_writer(layout, &isl->volume_index_zones[zone], in uds_save_index_state()
1120 result = open_region_writer(layout, &isl->index_page_map, &writers[0]); in uds_save_index_state()
1133 return write_index_save_layout(layout, isl); in uds_save_index_state()
1168 "single file layout region table", &table); in load_region_table()
1197 struct index_layout *layout, in read_super_block_data() argument
1201 struct super_block_data *super = &layout->super; in read_super_block_data()
1257 /* Sub-indexes are no longer used but the layout retains this field. */ in read_super_block_data()
1277 "incorrect layout region offset"); in verify_region()
1281 "incorrect layout region kind"); in verify_region()
1285 "incorrect layout region instance"); in verify_region()
1291 static int __must_check verify_sub_index(struct index_layout *layout, u64 start_block, in verify_sub_index() argument
1296 struct sub_index_layout *sil = &layout->index; in verify_sub_index()
1304 define_sub_index_nonce(layout); in verify_sub_index()
1312 next_block += sil->volume.block_count + layout->super.volume_offset; in verify_sub_index()
1314 for (i = 0; i < layout->super.max_saves; i++) { in verify_sub_index()
1324 next_block -= layout->super.volume_offset; in verify_sub_index()
1333 static int __must_check reconstitute_layout(struct index_layout *layout, in reconstitute_layout() argument
1339 result = vdo_allocate(layout->super.max_saves, struct index_save_layout, in reconstitute_layout()
1340 __func__, &layout->index.saves); in reconstitute_layout()
1344 layout->total_blocks = table->header.region_blocks; in reconstitute_layout()
1346 layout->header = table->regions[0]; in reconstitute_layout()
1347 result = verify_region(&layout->header, next_block++, RL_KIND_HEADER, in reconstitute_layout()
1352 layout->config = table->regions[1]; in reconstitute_layout()
1353 result = verify_region(&layout->config, next_block++, RL_KIND_CONFIG, in reconstitute_layout()
1358 result = verify_sub_index(layout, next_block, table); in reconstitute_layout()
1362 next_block += layout->index.sub_index.block_count; in reconstitute_layout()
1364 layout->seal = table->regions[table->header.region_count - 1]; in reconstitute_layout()
1365 result = verify_region(&layout->seal, next_block + layout->super.volume_offset, in reconstitute_layout()
1370 if (++next_block != (first_block + layout->total_blocks)) { in reconstitute_layout()
1372 "layout table does not span total blocks"); in reconstitute_layout()
1378 static int __must_check load_super_block(struct index_layout *layout, size_t block_size, in load_super_block() argument
1383 struct super_block_data *super = &layout->super; in load_super_block()
1395 result = read_super_block_data(reader, layout, table->header.payload); in load_super_block()
1409 result = reconstitute_layout(layout, table, first_block); in load_super_block()
1527 "index save layout table incomplete"); in reconstruct_index_save()
1589 static int __must_check load_sub_index_regions(struct index_layout *layout) in load_sub_index_regions() argument
1596 for (j = 0; j < layout->super.max_saves; j++) { in load_sub_index_regions()
1597 isl = &layout->index.saves[j]; in load_sub_index_regions()
1598 result = open_region_reader(layout, &isl->index_save, &reader); in load_sub_index_regions()
1619 static int __must_check verify_uds_index_config(struct index_layout *layout, in verify_uds_index_config() argument
1626 offset = layout->super.volume_offset - layout->super.start_offset; in verify_uds_index_config()
1627 result = open_layout_reader(layout, &layout->config, offset, &reader); in verify_uds_index_config()
1641 static int load_index_layout(struct index_layout *layout, struct uds_configuration *config) in load_index_layout() argument
1646 result = uds_make_buffered_reader(layout->factory, in load_index_layout()
1647 layout->offset / UDS_BLOCK_SIZE, 1, &reader); in load_index_layout()
1651 result = load_super_block(layout, UDS_BLOCK_SIZE, in load_index_layout()
1652 layout->offset / UDS_BLOCK_SIZE, reader); in load_index_layout()
1657 result = verify_uds_index_config(layout, config); in load_index_layout()
1661 return load_sub_index_regions(layout); in load_index_layout()
1664 static int create_layout_factory(struct index_layout *layout, in create_layout_factory() argument
1683 layout->factory = factory; in create_layout_factory()
1684 layout->factory_size = (config->size > 0) ? config->size : writable_size; in create_layout_factory()
1685 layout->offset = config->offset; in create_layout_factory()
1693 struct index_layout *layout = NULL; in uds_make_index_layout() local
1700 result = vdo_allocate(1, struct index_layout, __func__, &layout); in uds_make_index_layout()
1704 result = create_layout_factory(layout, config); in uds_make_index_layout()
1706 uds_free_index_layout(layout); in uds_make_index_layout()
1710 if (layout->factory_size < sizes.total_size) { in uds_make_index_layout()
1712 layout->factory_size, in uds_make_index_layout()
1714 uds_free_index_layout(layout); in uds_make_index_layout()
1719 result = create_index_layout(layout, config); in uds_make_index_layout()
1721 result = load_index_layout(layout, config); in uds_make_index_layout()
1723 uds_free_index_layout(layout); in uds_make_index_layout()
1727 *layout_ptr = layout; in uds_make_index_layout()
1731 void uds_free_index_layout(struct index_layout *layout) in uds_free_index_layout() argument
1733 if (layout == NULL) in uds_free_index_layout()
1736 vdo_free(layout->index.saves); in uds_free_index_layout()
1737 if (layout->factory != NULL) in uds_free_index_layout()
1738 uds_put_io_factory(layout->factory); in uds_free_index_layout()
1740 vdo_free(layout); in uds_free_index_layout()
1743 int uds_replace_index_layout_storage(struct index_layout *layout, in uds_replace_index_layout_storage() argument
1746 return uds_replace_storage(layout->factory, bdev); in uds_replace_index_layout_storage()
1750 int uds_open_volume_bufio(struct index_layout *layout, size_t block_size, in uds_open_volume_bufio() argument
1754 off_t offset = (layout->index.volume.start_block + in uds_open_volume_bufio()
1755 layout->super.volume_offset - in uds_open_volume_bufio()
1756 layout->super.start_offset); in uds_open_volume_bufio()
1758 return uds_make_bufio(layout->factory, offset, block_size, reserved_buffers, in uds_open_volume_bufio()
1762 u64 uds_get_volume_nonce(struct index_layout *layout) in uds_get_volume_nonce() argument
1764 return layout->index.nonce; in uds_get_volume_nonce()