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

dm thin metadata: Add support for a pre-commit callback

Add support for one pre-commit callback which is run right before the
metadata are committed.

This allows the thin provisioning target to run a callback before the
metadata are committed and is required by the next commit.

Cc: stable@vger.kernel.org
Signed-off-by: Nikos Tsironis <ntsironis@arrikto.com>
Acked-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>

authored by

Nikos Tsironis and committed by
Mike Snitzer
ecda7c02 8b3fd1f5

+36
+29
drivers/md/dm-thin-metadata.c
··· 189 189 sector_t data_block_size; 190 190 191 191 /* 192 + * Pre-commit callback. 193 + * 194 + * This allows the thin provisioning target to run a callback before 195 + * the metadata are committed. 196 + */ 197 + dm_pool_pre_commit_fn pre_commit_fn; 198 + void *pre_commit_context; 199 + 200 + /* 192 201 * We reserve a section of the metadata for commit overhead. 193 202 * All reported space does *not* include this. 194 203 */ ··· 835 826 if (unlikely(!pmd->in_service)) 836 827 return 0; 837 828 829 + if (pmd->pre_commit_fn) { 830 + r = pmd->pre_commit_fn(pmd->pre_commit_context); 831 + if (r < 0) { 832 + DMERR("pre-commit callback failed"); 833 + return r; 834 + } 835 + } 836 + 838 837 r = __write_changed_details(pmd); 839 838 if (r < 0) 840 839 return r; ··· 909 892 pmd->in_service = false; 910 893 pmd->bdev = bdev; 911 894 pmd->data_block_size = data_block_size; 895 + pmd->pre_commit_fn = NULL; 896 + pmd->pre_commit_context = NULL; 912 897 913 898 r = __create_persistent_data_objects(pmd, format_device); 914 899 if (r) { ··· 2061 2042 pmd_write_unlock(pmd); 2062 2043 2063 2044 return r; 2045 + } 2046 + 2047 + void dm_pool_register_pre_commit_callback(struct dm_pool_metadata *pmd, 2048 + dm_pool_pre_commit_fn fn, 2049 + void *context) 2050 + { 2051 + pmd_write_lock_in_core(pmd); 2052 + pmd->pre_commit_fn = fn; 2053 + pmd->pre_commit_context = context; 2054 + pmd_write_unlock(pmd); 2064 2055 } 2065 2056 2066 2057 int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd)
+7
drivers/md/dm-thin-metadata.h
··· 230 230 */ 231 231 void dm_pool_issue_prefetches(struct dm_pool_metadata *pmd); 232 232 233 + /* Pre-commit callback */ 234 + typedef int (*dm_pool_pre_commit_fn)(void *context); 235 + 236 + void dm_pool_register_pre_commit_callback(struct dm_pool_metadata *pmd, 237 + dm_pool_pre_commit_fn fn, 238 + void *context); 239 + 233 240 /*----------------------------------------------------------------*/ 234 241 235 242 #endif