cgroup: superblock can't be released with active dentries
[firefly-linux-kernel-4.4.55.git] / drivers / md / dm-thin-metadata.h
1 /*
2  * Copyright (C) 2010-2011 Red Hat, Inc.
3  *
4  * This file is released under the GPL.
5  */
6
7 #ifndef DM_THIN_METADATA_H
8 #define DM_THIN_METADATA_H
9
10 #include "persistent-data/dm-block-manager.h"
11
12 #define THIN_METADATA_BLOCK_SIZE 4096
13
14 /*
15  * The metadata device is currently limited in size.
16  *
17  * We have one block of index, which can hold 255 index entries.  Each
18  * index entry contains allocation info about 16k metadata blocks.
19  */
20 #define THIN_METADATA_MAX_SECTORS (255 * (1 << 14) * (THIN_METADATA_BLOCK_SIZE / (1 << SECTOR_SHIFT)))
21
22 /*
23  * A metadata device larger than 16GB triggers a warning.
24  */
25 #define THIN_METADATA_MAX_SECTORS_WARNING (16 * (1024 * 1024 * 1024 >> SECTOR_SHIFT))
26
27 /*----------------------------------------------------------------*/
28
29 struct dm_pool_metadata;
30 struct dm_thin_device;
31
32 /*
33  * Device identifier
34  */
35 typedef uint64_t dm_thin_id;
36
37 /*
38  * Reopens or creates a new, empty metadata volume.
39  */
40 struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
41                                                sector_t data_block_size);
42
43 int dm_pool_metadata_close(struct dm_pool_metadata *pmd);
44
45 /*
46  * Compat feature flags.  Any incompat flags beyond the ones
47  * specified below will prevent use of the thin metadata.
48  */
49 #define THIN_FEATURE_COMPAT_SUPP          0UL
50 #define THIN_FEATURE_COMPAT_RO_SUPP       0UL
51 #define THIN_FEATURE_INCOMPAT_SUPP        0UL
52
53 /*
54  * Device creation/deletion.
55  */
56 int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev);
57
58 /*
59  * An internal snapshot.
60  *
61  * You can only snapshot a quiesced origin i.e. one that is either
62  * suspended or not instanced at all.
63  */
64 int dm_pool_create_snap(struct dm_pool_metadata *pmd, dm_thin_id dev,
65                         dm_thin_id origin);
66
67 /*
68  * Deletes a virtual device from the metadata.  It _is_ safe to call this
69  * when that device is open.  Operations on that device will just start
70  * failing.  You still need to call close() on the device.
71  */
72 int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
73                                dm_thin_id dev);
74
75 /*
76  * Commits _all_ metadata changes: device creation, deletion, mapping
77  * updates.
78  */
79 int dm_pool_commit_metadata(struct dm_pool_metadata *pmd);
80
81 /*
82  * Set/get userspace transaction id.
83  */
84 int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
85                                         uint64_t current_id,
86                                         uint64_t new_id);
87
88 int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd,
89                                         uint64_t *result);
90
91 /*
92  * Hold/get root for userspace transaction.
93  */
94 int dm_pool_hold_metadata_root(struct dm_pool_metadata *pmd);
95
96 int dm_pool_get_held_metadata_root(struct dm_pool_metadata *pmd,
97                                    dm_block_t *result);
98
99 /*
100  * Actions on a single virtual device.
101  */
102
103 /*
104  * Opening the same device more than once will fail with -EBUSY.
105  */
106 int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev,
107                              struct dm_thin_device **td);
108
109 int dm_pool_close_thin_device(struct dm_thin_device *td);
110
111 dm_thin_id dm_thin_dev_id(struct dm_thin_device *td);
112
113 struct dm_thin_lookup_result {
114         dm_block_t block;
115         int shared;
116 };
117
118 /*
119  * Returns:
120  *   -EWOULDBLOCK iff @can_block is set and would block.
121  *   -ENODATA iff that mapping is not present.
122  *   0 success
123  */
124 int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
125                        int can_block, struct dm_thin_lookup_result *result);
126
127 /*
128  * Obtain an unused block.
129  */
130 int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result);
131
132 /*
133  * Insert or remove block.
134  */
135 int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block,
136                          dm_block_t data_block);
137
138 int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
139
140 /*
141  * Queries.
142  */
143 int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
144                                      dm_block_t *highest_mapped);
145
146 int dm_thin_get_mapped_count(struct dm_thin_device *td, dm_block_t *result);
147
148 int dm_pool_get_free_block_count(struct dm_pool_metadata *pmd,
149                                  dm_block_t *result);
150
151 int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd,
152                                           dm_block_t *result);
153
154 int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd,
155                                   dm_block_t *result);
156
157 int dm_pool_get_data_block_size(struct dm_pool_metadata *pmd, sector_t *result);
158
159 int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result);
160
161 /*
162  * Returns -ENOSPC if the new size is too small and already allocated
163  * blocks would be lost.
164  */
165 int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
166
167 /*----------------------------------------------------------------*/
168
169 #endif