diff options
| author | Joe Thornber <ejt@redhat.com> | 2013-05-10 09:37:20 -0400 |
|---|---|---|
| committer | Alasdair G Kergon <agk@redhat.com> | 2013-05-10 09:37:20 -0400 |
| commit | 7c3d3f2a87b01ff167a5f048285d5e3dee920235 (patch) | |
| tree | 44b483cd78221e412b314c872cb5ddedfdfd2abe /drivers/md/persistent-data | |
| parent | 24347e9595704464f62a4ed8f46abf62b4c79cdd (diff) | |
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>
Diffstat (limited to 'drivers/md/persistent-data')
| -rw-r--r-- | drivers/md/persistent-data/dm-space-map-disk.c | 3 | ||||
| -rw-r--r-- | drivers/md/persistent-data/dm-space-map-metadata.c | 6 | ||||
| -rw-r--r-- | drivers/md/persistent-data/dm-space-map.h | 23 |
3 files changed, 29 insertions, 3 deletions
diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c index f6d29e614ab7..e735a6d5a793 100644 --- a/drivers/md/persistent-data/dm-space-map-disk.c +++ b/drivers/md/persistent-data/dm-space-map-disk.c | |||
| @@ -248,7 +248,8 @@ static struct dm_space_map ops = { | |||
| 248 | .new_block = sm_disk_new_block, | 248 | .new_block = sm_disk_new_block, |
| 249 | .commit = sm_disk_commit, | 249 | .commit = sm_disk_commit, |
| 250 | .root_size = sm_disk_root_size, | 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 | struct dm_space_map *dm_sm_disk_create(struct dm_transaction_manager *tm, | 255 | struct dm_space_map *dm_sm_disk_create(struct dm_transaction_manager *tm, |
diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c index 51ca9edef444..883b465794d4 100644 --- a/drivers/md/persistent-data/dm-space-map-metadata.c +++ b/drivers/md/persistent-data/dm-space-map-metadata.c | |||
| @@ -391,7 +391,8 @@ static struct dm_space_map ops = { | |||
| 391 | .new_block = sm_metadata_new_block, | 391 | .new_block = sm_metadata_new_block, |
| 392 | .commit = sm_metadata_commit, | 392 | .commit = sm_metadata_commit, |
| 393 | .root_size = sm_metadata_root_size, | 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 | /*----------------------------------------------------------------*/ |
| @@ -513,7 +514,8 @@ static struct dm_space_map bootstrap_ops = { | |||
| 513 | .new_block = sm_bootstrap_new_block, | 514 | .new_block = sm_bootstrap_new_block, |
| 514 | .commit = sm_bootstrap_commit, | 515 | .commit = sm_bootstrap_commit, |
| 515 | .root_size = sm_bootstrap_root_size, | 516 | .root_size = sm_bootstrap_root_size, |
| 516 | .copy_root = sm_bootstrap_copy_root | 517 | .copy_root = sm_bootstrap_copy_root, |
| 518 | .register_threshold_callback = NULL | ||
| 517 | }; | 519 | }; |
| 518 | 520 | ||
| 519 | /*----------------------------------------------------------------*/ | 521 | /*----------------------------------------------------------------*/ |
diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h index 1cbfc6b1638a..3e6d1153b7c4 100644 --- a/drivers/md/persistent-data/dm-space-map.h +++ b/drivers/md/persistent-data/dm-space-map.h | |||
| @@ -9,6 +9,8 @@ | |||
| 9 | 9 | ||
| 10 | #include "dm-block-manager.h" | 10 | #include "dm-block-manager.h" |
| 11 | 11 | ||
| 12 | typedef void (*dm_sm_threshold_fn)(void *context); | ||
| 13 | |||
| 12 | /* | 14 | /* |
| 13 | * struct dm_space_map keeps a record of how many times each block in a device | 15 | * struct dm_space_map keeps a record of how many times each block in a device |
| 14 | * is referenced. It needs to be fixed on disk as part of the transaction. | 16 | * is referenced. It needs to be fixed on disk as part of the transaction. |
| @@ -59,6 +61,15 @@ struct dm_space_map { | |||
| 59 | */ | 61 | */ |
| 60 | int (*root_size)(struct dm_space_map *sm, size_t *result); | 62 | int (*root_size)(struct dm_space_map *sm, size_t *result); |
| 61 | int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len); | 63 | int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len); |
| 64 | |||
| 65 | /* | ||
| 66 | * You can register one threshold callback which is edge-triggered | ||
| 67 | * when the free space in the space map drops below the threshold. | ||
| 68 | */ | ||
| 69 | int (*register_threshold_callback)(struct dm_space_map *sm, | ||
| 70 | dm_block_t threshold, | ||
| 71 | dm_sm_threshold_fn fn, | ||
| 72 | void *context); | ||
| 62 | }; | 73 | }; |
| 63 | 74 | ||
| 64 | /*----------------------------------------------------------------*/ | 75 | /*----------------------------------------------------------------*/ |
| @@ -131,4 +142,16 @@ static inline int dm_sm_copy_root(struct dm_space_map *sm, void *copy_to_here_le | |||
| 131 | return sm->copy_root(sm, copy_to_here_le, len); | 142 | return sm->copy_root(sm, copy_to_here_le, len); |
| 132 | } | 143 | } |
| 133 | 144 | ||
| 145 | static inline int dm_sm_register_threshold_callback(struct dm_space_map *sm, | ||
| 146 | dm_block_t threshold, | ||
| 147 | dm_sm_threshold_fn fn, | ||
| 148 | void *context) | ||
| 149 | { | ||
| 150 | if (sm->register_threshold_callback) | ||
| 151 | return sm->register_threshold_callback(sm, threshold, fn, context); | ||
| 152 | |||
| 153 | return -EINVAL; | ||
| 154 | } | ||
| 155 | |||
| 156 | |||
| 134 | #endif /* _LINUX_DM_SPACE_MAP_H */ | 157 | #endif /* _LINUX_DM_SPACE_MAP_H */ |
