Linux 3.12.39
[linux/fpc-iii.git] / drivers / md / dm-thin-metadata.h
blobc6d123bb768af7ae33f0ded05c5f76edafef3e3e
1 /*
2 * Copyright (C) 2010-2011 Red Hat, Inc.
4 * This file is released under the GPL.
5 */
7 #ifndef DM_THIN_METADATA_H
8 #define DM_THIN_METADATA_H
10 #include "persistent-data/dm-block-manager.h"
11 #include "persistent-data/dm-space-map.h"
13 #define THIN_METADATA_BLOCK_SIZE 4096
16 * The metadata device is currently limited in size.
18 * We have one block of index, which can hold 255 index entries. Each
19 * index entry contains allocation info about 16k metadata blocks.
21 #define THIN_METADATA_MAX_SECTORS (255 * (1 << 14) * (THIN_METADATA_BLOCK_SIZE / (1 << SECTOR_SHIFT)))
24 * A metadata device larger than 16GB triggers a warning.
26 #define THIN_METADATA_MAX_SECTORS_WARNING (16 * (1024 * 1024 * 1024 >> SECTOR_SHIFT))
28 /*----------------------------------------------------------------*/
30 struct dm_pool_metadata;
31 struct dm_thin_device;
34 * Device identifier
36 typedef uint64_t dm_thin_id;
39 * Reopens or creates a new, empty metadata volume.
41 struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
42 sector_t data_block_size,
43 bool format_device);
45 int dm_pool_metadata_close(struct dm_pool_metadata *pmd);
48 * Compat feature flags. Any incompat flags beyond the ones
49 * specified below will prevent use of the thin metadata.
51 #define THIN_FEATURE_COMPAT_SUPP 0UL
52 #define THIN_FEATURE_COMPAT_RO_SUPP 0UL
53 #define THIN_FEATURE_INCOMPAT_SUPP 0UL
56 * Device creation/deletion.
58 int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev);
61 * An internal snapshot.
63 * You can only snapshot a quiesced origin i.e. one that is either
64 * suspended or not instanced at all.
66 int dm_pool_create_snap(struct dm_pool_metadata *pmd, dm_thin_id dev,
67 dm_thin_id origin);
70 * Deletes a virtual device from the metadata. It _is_ safe to call this
71 * when that device is open. Operations on that device will just start
72 * failing. You still need to call close() on the device.
74 int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
75 dm_thin_id dev);
78 * Commits _all_ metadata changes: device creation, deletion, mapping
79 * updates.
81 int dm_pool_commit_metadata(struct dm_pool_metadata *pmd);
84 * Discards all uncommitted changes. Rereads the superblock, rolling back
85 * to the last good transaction. Thin devices remain open.
86 * dm_thin_aborted_changes() tells you if they had uncommitted changes.
88 * If this call fails it's only useful to call dm_pool_metadata_close().
89 * All other methods will fail with -EINVAL.
91 int dm_pool_abort_metadata(struct dm_pool_metadata *pmd);
94 * Set/get userspace transaction id.
96 int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
97 uint64_t current_id,
98 uint64_t new_id);
100 int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd,
101 uint64_t *result);
104 * Hold/get root for userspace transaction.
106 * The metadata snapshot is a copy of the current superblock (minus the
107 * space maps). Userland can access the data structures for READ
108 * operations only. A small performance hit is incurred by providing this
109 * copy of the metadata to userland due to extra copy-on-write operations
110 * on the metadata nodes. Release this as soon as you finish with it.
112 int dm_pool_reserve_metadata_snap(struct dm_pool_metadata *pmd);
113 int dm_pool_release_metadata_snap(struct dm_pool_metadata *pmd);
115 int dm_pool_get_metadata_snap(struct dm_pool_metadata *pmd,
116 dm_block_t *result);
119 * Actions on a single virtual device.
123 * Opening the same device more than once will fail with -EBUSY.
125 int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev,
126 struct dm_thin_device **td);
128 int dm_pool_close_thin_device(struct dm_thin_device *td);
130 dm_thin_id dm_thin_dev_id(struct dm_thin_device *td);
132 struct dm_thin_lookup_result {
133 dm_block_t block;
134 unsigned shared:1;
138 * Returns:
139 * -EWOULDBLOCK iff @can_block is set and would block.
140 * -ENODATA iff that mapping is not present.
141 * 0 success
143 int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
144 int can_block, struct dm_thin_lookup_result *result);
147 * Obtain an unused block.
149 int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result);
152 * Insert or remove block.
154 int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block,
155 dm_block_t data_block);
157 int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
160 * Queries.
162 bool dm_thin_changed_this_transaction(struct dm_thin_device *td);
164 bool dm_pool_changed_this_transaction(struct dm_pool_metadata *pmd);
166 bool dm_thin_aborted_changes(struct dm_thin_device *td);
168 int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
169 dm_block_t *highest_mapped);
171 int dm_thin_get_mapped_count(struct dm_thin_device *td, dm_block_t *result);
173 int dm_pool_get_free_block_count(struct dm_pool_metadata *pmd,
174 dm_block_t *result);
176 int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd,
177 dm_block_t *result);
179 int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd,
180 dm_block_t *result);
182 int dm_pool_get_data_block_size(struct dm_pool_metadata *pmd, sector_t *result);
184 int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result);
186 int dm_pool_block_is_used(struct dm_pool_metadata *pmd, dm_block_t b, bool *result);
189 * Returns -ENOSPC if the new size is too small and already allocated
190 * blocks would be lost.
192 int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
193 int dm_pool_resize_metadata_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
196 * Flicks the underlying block manager into read only mode, so you know
197 * that nothing is changing.
199 void dm_pool_metadata_read_only(struct dm_pool_metadata *pmd);
200 void dm_pool_metadata_read_write(struct dm_pool_metadata *pmd);
202 int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd,
203 dm_block_t threshold,
204 dm_sm_threshold_fn fn,
205 void *context);
207 /*----------------------------------------------------------------*/
209 #endif