2 * Copyright (C) 2010-2011 Red Hat, Inc. All rights reserved.
4 * This file is released under the GPL.
7 #ifndef DM_THIN_METADATA_H
8 #define DM_THIN_METADATA_H
10 #include "persistent-data/dm-block-manager.h"
12 /*----------------------------------------------------------------*/
14 struct dm_pool_metadata
;
15 struct dm_thin_device
;
20 typedef uint64_t dm_thin_id
;
23 * Reopens or creates a new, empty metadata volume.
25 struct dm_pool_metadata
*dm_pool_metadata_open(struct block_device
*bdev
,
26 sector_t data_block_size
);
28 int dm_pool_metadata_close(struct dm_pool_metadata
*pmd
);
31 * This does not currently resize the metadata device, but should eventually.
33 int dm_pool_rebind_metadata_device(struct dm_pool_metadata
*pmd
,
34 struct block_device
*bdev
);
37 * Compat feature flags. Any incompat flags beyond the ones
38 * specified below will prevent use of the thin metadata.
40 #define THIN_FEATURE_COMPAT_SUPP 0UL
41 #define THIN_FEATURE_COMPAT_RO_SUPP 0UL
42 #define THIN_FEATURE_INCOMPAT_SUPP 0UL
45 * Device creation/deletion.
47 int dm_pool_create_thin(struct dm_pool_metadata
*pmd
, dm_thin_id dev
);
50 * An internal snapshot.
52 * You can only snapshot a quiesced origin i.e. one that is either
53 * suspended or not instanced at all.
55 int dm_pool_create_snap(struct dm_pool_metadata
*pmd
, dm_thin_id dev
,
59 * Deletes a virtual device from the metadata. It _is_ safe to call this
60 * when that device is open. Operations on that device will just start
61 * failing. You still need to call close() on the device.
63 int dm_pool_delete_thin_device(struct dm_pool_metadata
*pmd
,
67 * Thin devices don't have a size, however they do keep track of the
68 * highest mapped block. This trimming function allows the user to remove
69 * mappings above a certain virtual block.
71 int dm_pool_trim_thin_device(struct dm_pool_metadata
*pmd
, dm_thin_id dev
,
75 * Commits _all_ metadata changes: device creation, deletion, mapping
78 int dm_pool_commit_metadata(struct dm_pool_metadata
*pmd
);
81 * Set/get userspace transaction id.
83 int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata
*pmd
,
87 int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata
*pmd
,
91 * Hold/get root for userspace transaction.
93 int dm_pool_hold_metadata_root(struct dm_pool_metadata
*pmd
);
95 int dm_pool_get_held_metadata_root(struct dm_pool_metadata
*pmd
,
99 * Actions on a single virtual device.
103 * Opening the same device more than once will fail with -EBUSY.
105 int dm_pool_open_thin_device(struct dm_pool_metadata
*pmd
, dm_thin_id dev
,
106 struct dm_thin_device
**td
);
108 int dm_pool_close_thin_device(struct dm_thin_device
*td
);
110 dm_thin_id
dm_thin_dev_id(struct dm_thin_device
*td
);
112 struct dm_thin_lookup_result
{
119 * -EWOULDBLOCK iff @can_block is set and would block.
120 * -ENODATA iff that mapping is not present.
123 int dm_thin_find_block(struct dm_thin_device
*td
, dm_block_t block
,
124 int can_block
, struct dm_thin_lookup_result
*result
);
127 * Obtain an unused block.
129 int dm_pool_alloc_data_block(struct dm_pool_metadata
*pmd
, dm_block_t
*result
);
132 * Insert or remove block.
134 int dm_thin_insert_block(struct dm_thin_device
*td
, dm_block_t block
,
135 dm_block_t data_block
);
137 int dm_thin_remove_block(struct dm_thin_device
*td
, dm_block_t block
);
142 int dm_thin_get_highest_mapped_block(struct dm_thin_device
*td
,
143 dm_block_t
*highest_mapped
);
145 int dm_thin_get_mapped_count(struct dm_thin_device
*td
, dm_block_t
*result
);
147 int dm_pool_get_free_block_count(struct dm_pool_metadata
*pmd
,
150 int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata
*pmd
,
153 int dm_pool_get_metadata_dev_size(struct dm_pool_metadata
*pmd
,
156 int dm_pool_get_data_block_size(struct dm_pool_metadata
*pmd
, sector_t
*result
);
158 int dm_pool_get_data_dev_size(struct dm_pool_metadata
*pmd
, dm_block_t
*result
);
161 * Returns -ENOSPC if the new size is too small and already allocated
162 * blocks would be lost.
164 int dm_pool_resize_data_dev(struct dm_pool_metadata
*pmd
, dm_block_t new_size
);
166 /*----------------------------------------------------------------*/