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"
12 #define THIN_METADATA_BLOCK_SIZE 4096
15 * The metadata device is currently limited in size.
17 * We have one block of index, which can hold 255 index entries. Each
18 * index entry contains allocation info about 16k metadata blocks.
20 #define THIN_METADATA_MAX_SECTORS (255 * (1 << 14) * (THIN_METADATA_BLOCK_SIZE / (1 << SECTOR_SHIFT)))
23 * A metadata device larger than 16GB triggers a warning.
25 #define THIN_METADATA_MAX_SECTORS_WARNING (16 * (1024 * 1024 * 1024 >> SECTOR_SHIFT))
27 /*----------------------------------------------------------------*/
29 struct dm_pool_metadata
;
30 struct dm_thin_device
;
35 typedef uint64_t dm_thin_id
;
38 * Reopens or creates a new, empty metadata volume.
40 struct dm_pool_metadata
*dm_pool_metadata_open(struct block_device
*bdev
,
41 sector_t data_block_size
,
44 int dm_pool_metadata_close(struct dm_pool_metadata
*pmd
);
47 * Compat feature flags. Any incompat flags beyond the ones
48 * specified below will prevent use of the thin metadata.
50 #define THIN_FEATURE_COMPAT_SUPP 0UL
51 #define THIN_FEATURE_COMPAT_RO_SUPP 0UL
52 #define THIN_FEATURE_INCOMPAT_SUPP 0UL
55 * Device creation/deletion.
57 int dm_pool_create_thin(struct dm_pool_metadata
*pmd
, dm_thin_id dev
);
60 * An internal snapshot.
62 * You can only snapshot a quiesced origin i.e. one that is either
63 * suspended or not instanced at all.
65 int dm_pool_create_snap(struct dm_pool_metadata
*pmd
, dm_thin_id dev
,
69 * Deletes a virtual device from the metadata. It _is_ safe to call this
70 * when that device is open. Operations on that device will just start
71 * failing. You still need to call close() on the device.
73 int dm_pool_delete_thin_device(struct dm_pool_metadata
*pmd
,
77 * Commits _all_ metadata changes: device creation, deletion, mapping
80 int dm_pool_commit_metadata(struct dm_pool_metadata
*pmd
);
83 * Set/get userspace transaction id.
85 int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata
*pmd
,
89 int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata
*pmd
,
93 * Hold/get root for userspace transaction.
95 * The metadata snapshot is a copy of the current superblock (minus the
96 * space maps). Userland can access the data structures for READ
97 * operations only. A small performance hit is incurred by providing this
98 * copy of the metadata to userland due to extra copy-on-write operations
99 * on the metadata nodes. Release this as soon as you finish with it.
101 int dm_pool_reserve_metadata_snap(struct dm_pool_metadata
*pmd
);
102 int dm_pool_release_metadata_snap(struct dm_pool_metadata
*pmd
);
104 int dm_pool_get_metadata_snap(struct dm_pool_metadata
*pmd
,
108 * Actions on a single virtual device.
112 * Opening the same device more than once will fail with -EBUSY.
114 int dm_pool_open_thin_device(struct dm_pool_metadata
*pmd
, dm_thin_id dev
,
115 struct dm_thin_device
**td
);
117 int dm_pool_close_thin_device(struct dm_thin_device
*td
);
119 dm_thin_id
dm_thin_dev_id(struct dm_thin_device
*td
);
121 struct dm_thin_lookup_result
{
128 * -EWOULDBLOCK iff @can_block is set and would block.
129 * -ENODATA iff that mapping is not present.
132 int dm_thin_find_block(struct dm_thin_device
*td
, dm_block_t block
,
133 int can_block
, struct dm_thin_lookup_result
*result
);
136 * Obtain an unused block.
138 int dm_pool_alloc_data_block(struct dm_pool_metadata
*pmd
, dm_block_t
*result
);
141 * Insert or remove block.
143 int dm_thin_insert_block(struct dm_thin_device
*td
, dm_block_t block
,
144 dm_block_t data_block
);
146 int dm_thin_remove_block(struct dm_thin_device
*td
, dm_block_t block
);
151 bool dm_thin_changed_this_transaction(struct dm_thin_device
*td
);
153 int dm_thin_get_highest_mapped_block(struct dm_thin_device
*td
,
154 dm_block_t
*highest_mapped
);
156 int dm_thin_get_mapped_count(struct dm_thin_device
*td
, dm_block_t
*result
);
158 int dm_pool_get_free_block_count(struct dm_pool_metadata
*pmd
,
161 int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata
*pmd
,
164 int dm_pool_get_metadata_dev_size(struct dm_pool_metadata
*pmd
,
167 int dm_pool_get_data_block_size(struct dm_pool_metadata
*pmd
, sector_t
*result
);
169 int dm_pool_get_data_dev_size(struct dm_pool_metadata
*pmd
, dm_block_t
*result
);
172 * Returns -ENOSPC if the new size is too small and already allocated
173 * blocks would be lost.
175 int dm_pool_resize_data_dev(struct dm_pool_metadata
*pmd
, dm_block_t new_size
);
178 * Flicks the underlying block manager into read only mode, so you know
179 * that nothing is changing.
181 void dm_pool_metadata_read_only(struct dm_pool_metadata
*pmd
);
183 /*----------------------------------------------------------------*/
This page took 0.035811 seconds and 6 git commands to generate.