Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / drivers / md / dm-thin-metadata.h
blob859c16896877795732ad89df1b854bd2242d019b
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"
12 #define THIN_METADATA_BLOCK_SIZE 4096
14 /*----------------------------------------------------------------*/
16 struct dm_pool_metadata;
17 struct dm_thin_device;
20 * Device identifier
22 typedef uint64_t dm_thin_id;
25 * Reopens or creates a new, empty metadata volume.
27 struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
28 sector_t data_block_size);
30 int dm_pool_metadata_close(struct dm_pool_metadata *pmd);
33 * Compat feature flags. Any incompat flags beyond the ones
34 * specified below will prevent use of the thin metadata.
36 #define THIN_FEATURE_COMPAT_SUPP 0UL
37 #define THIN_FEATURE_COMPAT_RO_SUPP 0UL
38 #define THIN_FEATURE_INCOMPAT_SUPP 0UL
41 * Device creation/deletion.
43 int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev);
46 * An internal snapshot.
48 * You can only snapshot a quiesced origin i.e. one that is either
49 * suspended or not instanced at all.
51 int dm_pool_create_snap(struct dm_pool_metadata *pmd, dm_thin_id dev,
52 dm_thin_id origin);
55 * Deletes a virtual device from the metadata. It _is_ safe to call this
56 * when that device is open. Operations on that device will just start
57 * failing. You still need to call close() on the device.
59 int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
60 dm_thin_id dev);
63 * Commits _all_ metadata changes: device creation, deletion, mapping
64 * updates.
66 int dm_pool_commit_metadata(struct dm_pool_metadata *pmd);
69 * Set/get userspace transaction id.
71 int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
72 uint64_t current_id,
73 uint64_t new_id);
75 int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd,
76 uint64_t *result);
79 * Hold/get root for userspace transaction.
81 int dm_pool_hold_metadata_root(struct dm_pool_metadata *pmd);
83 int dm_pool_get_held_metadata_root(struct dm_pool_metadata *pmd,
84 dm_block_t *result);
87 * Actions on a single virtual device.
91 * Opening the same device more than once will fail with -EBUSY.
93 int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev,
94 struct dm_thin_device **td);
96 int dm_pool_close_thin_device(struct dm_thin_device *td);
98 dm_thin_id dm_thin_dev_id(struct dm_thin_device *td);
100 struct dm_thin_lookup_result {
101 dm_block_t block;
102 int shared;
106 * Returns:
107 * -EWOULDBLOCK iff @can_block is set and would block.
108 * -ENODATA iff that mapping is not present.
109 * 0 success
111 int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
112 int can_block, struct dm_thin_lookup_result *result);
115 * Obtain an unused block.
117 int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result);
120 * Insert or remove block.
122 int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block,
123 dm_block_t data_block);
125 int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
128 * Queries.
130 int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
131 dm_block_t *highest_mapped);
133 int dm_thin_get_mapped_count(struct dm_thin_device *td, dm_block_t *result);
135 int dm_pool_get_free_block_count(struct dm_pool_metadata *pmd,
136 dm_block_t *result);
138 int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd,
139 dm_block_t *result);
141 int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd,
142 dm_block_t *result);
144 int dm_pool_get_data_block_size(struct dm_pool_metadata *pmd, sector_t *result);
146 int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result);
149 * Returns -ENOSPC if the new size is too small and already allocated
150 * blocks would be lost.
152 int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
154 /*----------------------------------------------------------------*/
156 #endif