Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

dm vdo: update vdo_allocate_extended to take a field name, no types

All of VDO's "extended" allocations use a flexible array field at the
end of the allocated structure. We can infer the struct type from the
supplied pointer. Replacing the array field type with the field name
lets us use struct_size from overflow.h to compute the size instead of
the local __vdo_do_allocation version.

One allocation of bio structures doesn't conform to this pattern,
since the removal of bi_inline_vecs; directly compute the total size
for that case.

Signed-off-by: Ken Raeburn <raeburn@redhat.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

authored by

Ken Raeburn and committed by
Mikulas Patocka
6af58aa3 5282ac80

+40 -78
+5 -11
drivers/md/dm-vdo/block-map.c
··· 2478 2478 return VDO_SUCCESS; 2479 2479 } 2480 2480 2481 - result = vdo_allocate_extended(struct forest, map->root_count, 2482 - struct block_map_tree, __func__, 2483 - &forest); 2481 + result = vdo_allocate_extended(map->root_count, trees, __func__, &forest); 2484 2482 if (result != VDO_SUCCESS) 2485 2483 return result; 2486 2484 ··· 2705 2707 struct cursors *cursors; 2706 2708 int result; 2707 2709 2708 - result = vdo_allocate_extended(struct cursors, map->root_count, 2709 - struct cursor, __func__, &cursors); 2710 + result = vdo_allocate_extended(map->root_count, cursors, __func__, &cursors); 2710 2711 if (result != VDO_SUCCESS) { 2711 2712 vdo_fail_completion(completion, result); 2712 2713 return; ··· 2755 2758 zone->thread_id = vdo->thread_config.logical_threads[zone_number]; 2756 2759 zone->block_map = map; 2757 2760 2758 - result = vdo_allocate_extended(struct dirty_lists, maximum_age, 2759 - dirty_era_t, __func__, 2760 - &zone->dirty_lists); 2761 + result = vdo_allocate_extended(maximum_age, eras, __func__, &zone->dirty_lists); 2761 2762 if (result != VDO_SUCCESS) 2762 2763 return result; 2763 2764 ··· 2895 2900 if (result != VDO_SUCCESS) 2896 2901 return result; 2897 2902 2898 - result = vdo_allocate_extended(struct block_map, 2899 - vdo->thread_config.logical_zone_count, 2900 - struct block_map_zone, __func__, &map); 2903 + result = vdo_allocate_extended(vdo->thread_config.logical_zone_count, 2904 + zones, __func__, &map); 2901 2905 if (result != VDO_SUCCESS) 2902 2906 return result; 2903 2907
+1 -2
drivers/md/dm-vdo/data-vio.c
··· 842 842 struct data_vio_pool *pool; 843 843 data_vio_count_t i; 844 844 845 - result = vdo_allocate_extended(struct data_vio_pool, pool_size, struct data_vio, 846 - __func__, &pool); 845 + result = vdo_allocate_extended(pool_size, data_vios, __func__, &pool); 847 846 if (result != VDO_SUCCESS) 848 847 return result; 849 848
+1 -2
drivers/md/dm-vdo/dedupe.c
··· 2418 2418 if (zone_count == 0) 2419 2419 return VDO_SUCCESS; 2420 2420 2421 - result = vdo_allocate_extended(struct hash_zones, zone_count, struct hash_zone, 2422 - __func__, &zones); 2421 + result = vdo_allocate_extended(zone_count, zones, __func__, &zones); 2423 2422 if (result != VDO_SUCCESS) 2424 2423 return result; 2425 2424
+4 -7
drivers/md/dm-vdo/indexer/index-layout.c
··· 459 459 type = RH_TYPE_UNSAVED; 460 460 } 461 461 462 - result = vdo_allocate_extended(struct region_table, region_count, 463 - struct layout_region, 462 + result = vdo_allocate_extended(region_count, regions, 464 463 "layout region table for ISL", &table); 465 464 if (result != VDO_SUCCESS) 466 465 return result; ··· 641 642 struct region_table *table; 642 643 struct layout_region *lr; 643 644 644 - result = vdo_allocate_extended(struct region_table, region_count, 645 - struct layout_region, "layout region table", 646 - &table); 645 + result = vdo_allocate_extended(region_count, regions, 646 + "layout region table", &table); 647 647 if (result != VDO_SUCCESS) 648 648 return result; 649 649 ··· 1136 1138 header.version); 1137 1139 } 1138 1140 1139 - result = vdo_allocate_extended(struct region_table, header.region_count, 1140 - struct layout_region, 1141 + result = vdo_allocate_extended(header.region_count, regions, 1141 1142 "single file layout region table", &table); 1142 1143 if (result != VDO_SUCCESS) 1143 1144 return result;
+2 -5
drivers/md/dm-vdo/indexer/index.c
··· 764 764 size_t collated_records_size = 765 765 (sizeof(struct uds_volume_record) * index->volume->geometry->records_per_chapter); 766 766 767 - result = vdo_allocate_extended(struct chapter_writer, index->zone_count, 768 - struct open_chapter_zone *, "Chapter Writer", 769 - &writer); 767 + result = vdo_allocate_extended(index->zone_count, chapters, "Chapter Writer", &writer); 770 768 if (result != VDO_SUCCESS) 771 769 return result; 772 770 ··· 1158 1160 u64 nonce; 1159 1161 unsigned int z; 1160 1162 1161 - result = vdo_allocate_extended(struct uds_index, config->zone_count, 1162 - struct uds_request_queue *, "index", &index); 1163 + result = vdo_allocate_extended(config->zone_count, zone_queues, "index", &index); 1163 1164 if (result != VDO_SUCCESS) 1164 1165 return result; 1165 1166
+1 -3
drivers/md/dm-vdo/indexer/open-chapter.c
··· 68 68 size_t capacity = geometry->records_per_chapter / zone_count; 69 69 size_t slot_count = (1 << bits_per(capacity * LOAD_RATIO)); 70 70 71 - result = vdo_allocate_extended(struct open_chapter_zone, slot_count, 72 - struct open_chapter_zone_slot, "open chapter", 73 - &open_chapter); 71 + result = vdo_allocate_extended(slot_count, slots, "open chapter", &open_chapter); 74 72 if (result != VDO_SUCCESS) 75 73 return result; 76 74
+1 -2
drivers/md/dm-vdo/indexer/radix-sort.c
··· 211 211 unsigned int stack_size = count / INSERTION_SORT_THRESHOLD; 212 212 struct radix_sorter *radix_sorter; 213 213 214 - result = vdo_allocate_extended(struct radix_sorter, stack_size, struct task, 215 - __func__, &radix_sorter); 214 + result = vdo_allocate_extended(stack_size, stack, __func__, &radix_sorter); 216 215 if (result != VDO_SUCCESS) 217 216 return result; 218 217
+1 -2
drivers/md/dm-vdo/io-submitter.c
··· 383 383 struct io_submitter *io_submitter; 384 384 int result; 385 385 386 - result = vdo_allocate_extended(struct io_submitter, thread_count, 387 - struct bio_queue_data, "bio submission data", 386 + result = vdo_allocate_extended(thread_count, bio_queue_data, "bio submission data", 388 387 &io_submitter); 389 388 if (result != VDO_SUCCESS) 390 389 return result;
+1 -2
drivers/md/dm-vdo/logical-zone.c
··· 94 94 if (zone_count == 0) 95 95 return VDO_SUCCESS; 96 96 97 - result = vdo_allocate_extended(struct logical_zones, zone_count, 98 - struct logical_zone, __func__, &zones); 97 + result = vdo_allocate_extended(zone_count, zones, __func__, &zones); 99 98 if (result != VDO_SUCCESS) 100 99 return result; 101 100
+9 -18
drivers/md/dm-vdo/memory-alloc.h
··· 8 8 9 9 #include <linux/cache.h> 10 10 #include <linux/io.h> /* for PAGE_SIZE */ 11 + #include <linux/overflow.h> 11 12 12 13 #include "permassert.h" 13 14 #include "thread-registry.h" ··· 72 71 __vdo_do_allocation(COUNT, sizeof(TYPE), 0, __alignof__(TYPE), WHAT, PTR) 73 72 74 73 /* 75 - * Allocate one object of an indicated type, followed by one or more elements of a second type, 76 - * logging an error if the allocation fails. The memory will be zeroed. 74 + * Allocate a structure with a flexible array member, with a specified number of elements, logging 75 + * an error if the allocation fails. The memory will be zeroed. 77 76 * 78 - * @TYPE1: The type of the primary object to allocate. This type determines the alignment of the 79 - * allocated memory. 80 77 * @COUNT: The number of objects to allocate 81 - * @TYPE2: The type of array objects to allocate 78 + * @FIELD: The flexible array field at the end of the structure 82 79 * @WHAT: What is being allocated (for error logging) 83 80 * @PTR: A pointer to hold the allocated memory 84 81 * 85 82 * Return: VDO_SUCCESS or an error code 86 83 */ 87 - #define vdo_allocate_extended(TYPE1, COUNT, TYPE2, WHAT, PTR) \ 88 - __extension__({ \ 89 - int _result; \ 90 - TYPE1 **_ptr = (PTR); \ 91 - BUILD_BUG_ON(__alignof__(TYPE1) < __alignof__(TYPE2)); \ 92 - _result = __vdo_do_allocation(COUNT, \ 93 - sizeof(TYPE2), \ 94 - sizeof(TYPE1), \ 95 - __alignof__(TYPE1), \ 96 - WHAT, \ 97 - _ptr); \ 98 - _result; \ 99 - }) 84 + #define vdo_allocate_extended(COUNT, FIELD, WHAT, PTR) \ 85 + vdo_allocate_memory(struct_size(*(PTR), FIELD, (COUNT)), \ 86 + __alignof__(typeof(**(PTR))), \ 87 + WHAT, \ 88 + (PTR)) 100 89 101 90 /* 102 91 * Allocate memory starting on a cache line boundary, logging an error if the allocation fails. The
+3 -4
drivers/md/dm-vdo/packer.c
··· 120 120 struct packer_bin *bin; 121 121 int result; 122 122 123 - result = vdo_allocate_extended(struct packer_bin, VDO_MAX_COMPRESSION_SLOTS, 124 - struct vio *, __func__, &bin); 123 + result = vdo_allocate_extended(VDO_MAX_COMPRESSION_SLOTS, incoming, __func__, &bin); 125 124 if (result != VDO_SUCCESS) 126 125 return result; 127 126 ··· 167 168 * bin must have a canceler for which it is waiting, and any canceler will only have 168 169 * canceled one lock holder at a time. 169 170 */ 170 - result = vdo_allocate_extended(struct packer_bin, MAXIMUM_VDO_USER_VIOS / 2, 171 - struct vio *, __func__, &packer->canceled_bin); 171 + result = vdo_allocate_extended(MAXIMUM_VDO_USER_VIOS / 2, incoming, __func__, 172 + &packer->canceled_bin); 172 173 if (result != VDO_SUCCESS) { 173 174 vdo_free_packer(packer); 174 175 return result;
+2 -4
drivers/md/dm-vdo/physical-zone.c
··· 240 240 struct pbn_lock_pool *pool; 241 241 int result; 242 242 243 - result = vdo_allocate_extended(struct pbn_lock_pool, capacity, idle_pbn_lock, 244 - __func__, &pool); 243 + result = vdo_allocate_extended(capacity, locks, __func__, &pool); 245 244 if (result != VDO_SUCCESS) 246 245 return result; 247 246 ··· 367 368 if (zone_count == 0) 368 369 return VDO_SUCCESS; 369 370 370 - result = vdo_allocate_extended(struct physical_zones, zone_count, 371 - struct physical_zone, __func__, &zones); 371 + result = vdo_allocate_extended(zone_count, zones, __func__, &zones); 372 372 if (result != VDO_SUCCESS) 373 373 return result; 374 374
+1 -2
drivers/md/dm-vdo/priority-table.c
··· 60 60 if (max_priority > MAX_PRIORITY) 61 61 return UDS_INVALID_ARGUMENT; 62 62 63 - result = vdo_allocate_extended(struct priority_table, max_priority + 1, 64 - struct bucket, __func__, &table); 63 + result = vdo_allocate_extended(max_priority + 1, buckets, __func__, &table); 65 64 if (result != VDO_SUCCESS) 66 65 return result; 67 66
+2 -4
drivers/md/dm-vdo/recovery-journal.c
··· 711 711 struct recovery_journal *journal; 712 712 int result; 713 713 714 - result = vdo_allocate_extended(struct recovery_journal, 715 - RECOVERY_JOURNAL_RESERVED_BLOCKS, 716 - struct recovery_journal_block, __func__, 717 - &journal); 714 + result = vdo_allocate_extended(RECOVERY_JOURNAL_RESERVED_BLOCKS, blocks, 715 + __func__, &journal); 718 716 if (result != VDO_SUCCESS) 719 717 return result; 720 718
+1 -3
drivers/md/dm-vdo/repair.c
··· 1715 1715 vdo_log_warning("Device was dirty, rebuilding reference counts"); 1716 1716 } 1717 1717 1718 - result = vdo_allocate_extended(struct repair_completion, page_count, 1719 - struct vdo_page_completion, __func__, 1720 - &repair); 1718 + result = vdo_allocate_extended(page_count, page_completions, __func__, &repair); 1721 1719 if (result != VDO_SUCCESS) { 1722 1720 vdo_fail_completion(parent, result); 1723 1721 return;
+2 -3
drivers/md/dm-vdo/slab-depot.c
··· 4266 4266 return vdo_log_error_strerror(UDS_CORRUPT_DATA, 4267 4267 "invalid zone count"); 4268 4268 4269 - result = vdo_allocate_extended(struct slab_depot, 4270 - vdo->thread_config.physical_zone_count, 4271 - struct block_allocator, __func__, &depot); 4269 + result = vdo_allocate_extended(vdo->thread_config.physical_zone_count, 4270 + allocators, __func__, &depot); 4272 4271 if (result != VDO_SUCCESS) 4273 4272 return result; 4274 4273
+3 -4
drivers/md/dm-vdo/vio.c
··· 52 52 struct bio *bio = NULL; 53 53 int result; 54 54 55 - result = vdo_allocate_extended(struct bio, size + 1, struct bio_vec, 56 - "bio", &bio); 55 + result = vdo_allocate_memory(sizeof(struct bio) + sizeof(struct bio_vec) * (size + 1), 56 + __alignof__(struct bio), "bio", &bio); 57 57 if (result != VDO_SUCCESS) 58 58 return result; 59 59 ··· 327 327 int result; 328 328 size_t per_vio_size = VDO_BLOCK_SIZE * block_count; 329 329 330 - result = vdo_allocate_extended(struct vio_pool, pool_size, struct pooled_vio, 331 - __func__, &pool); 330 + result = vdo_allocate_extended(pool_size, vios, __func__, &pool); 332 331 if (result != VDO_SUCCESS) 333 332 return result; 334 333