2 * Copyright (C) 2010-2011 Red Hat, Inc.
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"
11 #include "persistent-data/dm-space-map.h"
12 #include "persistent-data/dm-space-map-metadata.h"
14 #define THIN_METADATA_BLOCK_SIZE DM_SM_METADATA_BLOCK_SIZE
17 * The metadata device is currently limited in size.
19 #define THIN_METADATA_MAX_SECTORS DM_SM_METADATA_MAX_SECTORS
22 * A metadata device larger than 16GB triggers a warning.
24 #define THIN_METADATA_MAX_SECTORS_WARNING (16 * (1024 * 1024 * 1024 >> SECTOR_SHIFT))
26 /*----------------------------------------------------------------*/
29 * Thin metadata superblock flags.
31 #define THIN_METADATA_NEEDS_CHECK_FLAG (1 << 0)
33 struct dm_pool_metadata
;
34 struct dm_thin_device
;
39 typedef uint64_t dm_thin_id
;
42 * Reopens or creates a new, empty metadata volume.
44 struct dm_pool_metadata
*dm_pool_metadata_open(struct block_device
*bdev
,
45 sector_t data_block_size
,
48 int dm_pool_metadata_close(struct dm_pool_metadata
*pmd
);
51 * Compat feature flags. Any incompat flags beyond the ones
52 * specified below will prevent use of the thin metadata.
54 #define THIN_FEATURE_COMPAT_SUPP 0UL
55 #define THIN_FEATURE_COMPAT_RO_SUPP 0UL
56 #define THIN_FEATURE_INCOMPAT_SUPP 0UL
59 * Device creation/deletion.
61 int dm_pool_create_thin(struct dm_pool_metadata
*pmd
, dm_thin_id dev
);
64 * An internal snapshot.
66 * You can only snapshot a quiesced origin i.e. one that is either
67 * suspended or not instanced at all.
69 int dm_pool_create_snap(struct dm_pool_metadata
*pmd
, dm_thin_id dev
,
73 * Deletes a virtual device from the metadata. It _is_ safe to call this
74 * when that device is open. Operations on that device will just start
75 * failing. You still need to call close() on the device.
77 int dm_pool_delete_thin_device(struct dm_pool_metadata
*pmd
,
81 * Commits _all_ metadata changes: device creation, deletion, mapping
84 int dm_pool_commit_metadata(struct dm_pool_metadata
*pmd
);
87 * Discards all uncommitted changes. Rereads the superblock, rolling back
88 * to the last good transaction. Thin devices remain open.
89 * dm_thin_aborted_changes() tells you if they had uncommitted changes.
91 * If this call fails it's only useful to call dm_pool_metadata_close().
92 * All other methods will fail with -EINVAL.
94 int dm_pool_abort_metadata(struct dm_pool_metadata
*pmd
);
97 * Set/get userspace transaction id.
99 int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata
*pmd
,
103 int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata
*pmd
,
107 * Hold/get root for userspace transaction.
109 * The metadata snapshot is a copy of the current superblock (minus the
110 * space maps). Userland can access the data structures for READ
111 * operations only. A small performance hit is incurred by providing this
112 * copy of the metadata to userland due to extra copy-on-write operations
113 * on the metadata nodes. Release this as soon as you finish with it.
115 int dm_pool_reserve_metadata_snap(struct dm_pool_metadata
*pmd
);
116 int dm_pool_release_metadata_snap(struct dm_pool_metadata
*pmd
);
118 int dm_pool_get_metadata_snap(struct dm_pool_metadata
*pmd
,
122 * Actions on a single virtual device.
126 * Opening the same device more than once will fail with -EBUSY.
128 int dm_pool_open_thin_device(struct dm_pool_metadata
*pmd
, dm_thin_id dev
,
129 struct dm_thin_device
**td
);
131 int dm_pool_close_thin_device(struct dm_thin_device
*td
);
133 dm_thin_id
dm_thin_dev_id(struct dm_thin_device
*td
);
135 struct dm_thin_lookup_result
{
142 * -EWOULDBLOCK iff @can_block is set and would block.
143 * -ENODATA iff that mapping is not present.
146 int dm_thin_find_block(struct dm_thin_device
*td
, dm_block_t block
,
147 int can_block
, struct dm_thin_lookup_result
*result
);
150 * Obtain an unused block.
152 int dm_pool_alloc_data_block(struct dm_pool_metadata
*pmd
, dm_block_t
*result
);
155 * Insert or remove block.
157 int dm_thin_insert_block(struct dm_thin_device
*td
, dm_block_t block
,
158 dm_block_t data_block
);
160 int dm_thin_remove_block(struct dm_thin_device
*td
, dm_block_t block
);
165 bool dm_thin_changed_this_transaction(struct dm_thin_device
*td
);
167 bool dm_pool_changed_this_transaction(struct dm_pool_metadata
*pmd
);
169 bool dm_thin_aborted_changes(struct dm_thin_device
*td
);
171 int dm_thin_get_highest_mapped_block(struct dm_thin_device
*td
,
172 dm_block_t
*highest_mapped
);
174 int dm_thin_get_mapped_count(struct dm_thin_device
*td
, dm_block_t
*result
);
176 int dm_pool_get_free_block_count(struct dm_pool_metadata
*pmd
,
179 int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata
*pmd
,
182 int dm_pool_get_metadata_dev_size(struct dm_pool_metadata
*pmd
,
185 int dm_pool_get_data_block_size(struct dm_pool_metadata
*pmd
, sector_t
*result
);
187 int dm_pool_get_data_dev_size(struct dm_pool_metadata
*pmd
, dm_block_t
*result
);
189 int dm_pool_block_is_used(struct dm_pool_metadata
*pmd
, dm_block_t b
, bool *result
);
192 * Returns -ENOSPC if the new size is too small and already allocated
193 * blocks would be lost.
195 int dm_pool_resize_data_dev(struct dm_pool_metadata
*pmd
, dm_block_t new_size
);
196 int dm_pool_resize_metadata_dev(struct dm_pool_metadata
*pmd
, dm_block_t new_size
);
199 * Flicks the underlying block manager into read only mode, so you know
200 * that nothing is changing.
202 void dm_pool_metadata_read_only(struct dm_pool_metadata
*pmd
);
203 void dm_pool_metadata_read_write(struct dm_pool_metadata
*pmd
);
205 int dm_pool_register_metadata_threshold(struct dm_pool_metadata
*pmd
,
206 dm_block_t threshold
,
207 dm_sm_threshold_fn fn
,
211 * Updates the superblock immediately.
213 int dm_pool_metadata_set_needs_check(struct dm_pool_metadata
*pmd
);
214 bool dm_pool_metadata_needs_check(struct dm_pool_metadata
*pmd
);
216 /*----------------------------------------------------------------*/