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

dm persistent data: add threshold callback to space map

Add a threshold callback function to the persistent data space map
interface for a subsequent patch to use.

dm-thin and dm-cache are interested in knowing when they're getting
low on metadata or data blocks. This patch introduces a new method
for registering a callback against a threshold.

Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>

authored by

Joe Thornber and committed by
Alasdair G Kergon
7c3d3f2a 24347e95

+29 -3
+2 -1
drivers/md/persistent-data/dm-space-map-disk.c
··· 248 248 .new_block = sm_disk_new_block, 249 249 .commit = sm_disk_commit, 250 250 .root_size = sm_disk_root_size, 251 - .copy_root = sm_disk_copy_root 251 + .copy_root = sm_disk_copy_root, 252 + .register_threshold_callback = NULL 252 253 }; 253 254 254 255 struct dm_space_map *dm_sm_disk_create(struct dm_transaction_manager *tm,
+4 -2
drivers/md/persistent-data/dm-space-map-metadata.c
··· 391 391 .new_block = sm_metadata_new_block, 392 392 .commit = sm_metadata_commit, 393 393 .root_size = sm_metadata_root_size, 394 - .copy_root = sm_metadata_copy_root 394 + .copy_root = sm_metadata_copy_root, 395 + .register_threshold_callback = NULL 395 396 }; 396 397 397 398 /*----------------------------------------------------------------*/ ··· 514 513 .new_block = sm_bootstrap_new_block, 515 514 .commit = sm_bootstrap_commit, 516 515 .root_size = sm_bootstrap_root_size, 517 - .copy_root = sm_bootstrap_copy_root 516 + .copy_root = sm_bootstrap_copy_root, 517 + .register_threshold_callback = NULL 518 518 }; 519 519 520 520 /*----------------------------------------------------------------*/
+23
drivers/md/persistent-data/dm-space-map.h
··· 9 9 10 10 #include "dm-block-manager.h" 11 11 12 + typedef void (*dm_sm_threshold_fn)(void *context); 13 + 12 14 /* 13 15 * struct dm_space_map keeps a record of how many times each block in a device 14 16 * is referenced. It needs to be fixed on disk as part of the transaction. ··· 61 59 */ 62 60 int (*root_size)(struct dm_space_map *sm, size_t *result); 63 61 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len); 62 + 63 + /* 64 + * You can register one threshold callback which is edge-triggered 65 + * when the free space in the space map drops below the threshold. 66 + */ 67 + int (*register_threshold_callback)(struct dm_space_map *sm, 68 + dm_block_t threshold, 69 + dm_sm_threshold_fn fn, 70 + void *context); 64 71 }; 65 72 66 73 /*----------------------------------------------------------------*/ ··· 141 130 { 142 131 return sm->copy_root(sm, copy_to_here_le, len); 143 132 } 133 + 134 + static inline int dm_sm_register_threshold_callback(struct dm_space_map *sm, 135 + dm_block_t threshold, 136 + dm_sm_threshold_fn fn, 137 + void *context) 138 + { 139 + if (sm->register_threshold_callback) 140 + return sm->register_threshold_callback(sm, threshold, fn, context); 141 + 142 + return -EINVAL; 143 + } 144 + 144 145 145 146 #endif /* _LINUX_DM_SPACE_MAP_H */