Blame view

drivers/md/dm-thin-metadata.h 6.17 KB
991d9fa02   Joe Thornber   dm: add thin prov...
1
2
3
4
5
6
7
8
9
10
  /*
   * Copyright (C) 2010-2011 Red Hat, Inc.
   *
   * This file is released under the GPL.
   */
  
  #ifndef DM_THIN_METADATA_H
  #define DM_THIN_METADATA_H
  
  #include "persistent-data/dm-block-manager.h"
ac8c3f3df   Joe Thornber   dm thin: generate...
11
  #include "persistent-data/dm-space-map.h"
7d48935ef   Mike Snitzer   dm thin: allow me...
12
  #include "persistent-data/dm-space-map-metadata.h"
991d9fa02   Joe Thornber   dm: add thin prov...
13

7d48935ef   Mike Snitzer   dm thin: allow me...
14
  #define THIN_METADATA_BLOCK_SIZE DM_SM_METADATA_BLOCK_SIZE
991d9fa02   Joe Thornber   dm: add thin prov...
15

c4a69ecdb   Mike Snitzer   dm thin: relax ha...
16
17
  /*
   * The metadata device is currently limited in size.
c4a69ecdb   Mike Snitzer   dm thin: relax ha...
18
   */
7d48935ef   Mike Snitzer   dm thin: allow me...
19
  #define THIN_METADATA_MAX_SECTORS DM_SM_METADATA_MAX_SECTORS
c4a69ecdb   Mike Snitzer   dm thin: relax ha...
20
21
22
23
24
  
  /*
   * A metadata device larger than 16GB triggers a warning.
   */
  #define THIN_METADATA_MAX_SECTORS_WARNING (16 * (1024 * 1024 * 1024 >> SECTOR_SHIFT))
991d9fa02   Joe Thornber   dm: add thin prov...
25
  /*----------------------------------------------------------------*/
07f2b6e03   Mike Snitzer   dm thin: ensure u...
26
27
28
29
  /*
   * Thin metadata superblock flags.
   */
  #define THIN_METADATA_NEEDS_CHECK_FLAG (1 << 0)
991d9fa02   Joe Thornber   dm: add thin prov...
30
31
32
33
34
35
36
37
38
39
40
41
  struct dm_pool_metadata;
  struct dm_thin_device;
  
  /*
   * Device identifier
   */
  typedef uint64_t dm_thin_id;
  
  /*
   * Reopens or creates a new, empty metadata volume.
   */
  struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
66b1edc05   Joe Thornber   dm thin metadata:...
42
43
  					       sector_t data_block_size,
  					       bool format_device);
991d9fa02   Joe Thornber   dm: add thin prov...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  
  int dm_pool_metadata_close(struct dm_pool_metadata *pmd);
  
  /*
   * Compat feature flags.  Any incompat flags beyond the ones
   * specified below will prevent use of the thin metadata.
   */
  #define THIN_FEATURE_COMPAT_SUPP	  0UL
  #define THIN_FEATURE_COMPAT_RO_SUPP	  0UL
  #define THIN_FEATURE_INCOMPAT_SUPP	  0UL
  
  /*
   * Device creation/deletion.
   */
  int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev);
  
  /*
   * An internal snapshot.
   *
   * You can only snapshot a quiesced origin i.e. one that is either
   * suspended or not instanced at all.
   */
  int dm_pool_create_snap(struct dm_pool_metadata *pmd, dm_thin_id dev,
  			dm_thin_id origin);
  
  /*
   * Deletes a virtual device from the metadata.  It _is_ safe to call this
   * when that device is open.  Operations on that device will just start
   * failing.  You still need to call close() on the device.
   */
  int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
  			       dm_thin_id dev);
  
  /*
   * Commits _all_ metadata changes: device creation, deletion, mapping
   * updates.
   */
  int dm_pool_commit_metadata(struct dm_pool_metadata *pmd);
  
  /*
da105ed5f   Joe Thornber   dm thin metadata:...
84
85
86
87
88
89
90
91
92
93
   * Discards all uncommitted changes.  Rereads the superblock, rolling back
   * to the last good transaction.  Thin devices remain open.
   * dm_thin_aborted_changes() tells you if they had uncommitted changes.
   *
   * If this call fails it's only useful to call dm_pool_metadata_close().
   * All other methods will fail with -EINVAL.
   */
  int dm_pool_abort_metadata(struct dm_pool_metadata *pmd);
  
  /*
991d9fa02   Joe Thornber   dm: add thin prov...
94
95
96
97
98
99
100
101
102
103
104
   * Set/get userspace transaction id.
   */
  int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
  					uint64_t current_id,
  					uint64_t new_id);
  
  int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd,
  					uint64_t *result);
  
  /*
   * Hold/get root for userspace transaction.
cc8394d86   Joe Thornber   dm thin: provide ...
105
106
107
108
109
110
   *
   * The metadata snapshot is a copy of the current superblock (minus the
   * space maps).  Userland can access the data structures for READ
   * operations only.  A small performance hit is incurred by providing this
   * copy of the metadata to userland due to extra copy-on-write operations
   * on the metadata nodes.  Release this as soon as you finish with it.
991d9fa02   Joe Thornber   dm: add thin prov...
111
   */
cc8394d86   Joe Thornber   dm thin: provide ...
112
113
  int dm_pool_reserve_metadata_snap(struct dm_pool_metadata *pmd);
  int dm_pool_release_metadata_snap(struct dm_pool_metadata *pmd);
991d9fa02   Joe Thornber   dm: add thin prov...
114

cc8394d86   Joe Thornber   dm thin: provide ...
115
116
  int dm_pool_get_metadata_snap(struct dm_pool_metadata *pmd,
  			      dm_block_t *result);
991d9fa02   Joe Thornber   dm: add thin prov...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
  
  /*
   * Actions on a single virtual device.
   */
  
  /*
   * Opening the same device more than once will fail with -EBUSY.
   */
  int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev,
  			     struct dm_thin_device **td);
  
  int dm_pool_close_thin_device(struct dm_thin_device *td);
  
  dm_thin_id dm_thin_dev_id(struct dm_thin_device *td);
  
  struct dm_thin_lookup_result {
  	dm_block_t block;
7f2146651   Mike Snitzer   dm thin: use bool...
134
  	bool shared:1;
991d9fa02   Joe Thornber   dm: add thin prov...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
  };
  
  /*
   * Returns:
   *   -EWOULDBLOCK iff @can_block is set and would block.
   *   -ENODATA iff that mapping is not present.
   *   0 success
   */
  int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
  		       int can_block, struct dm_thin_lookup_result *result);
  
  /*
   * Obtain an unused block.
   */
  int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result);
  
  /*
   * Insert or remove block.
   */
  int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block,
  			 dm_block_t data_block);
  
  int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
  
  /*
   * Queries.
   */
40db5a537   Joe Thornber   dm thin metadata:...
162
  bool dm_thin_changed_this_transaction(struct dm_thin_device *td);
4d1662a30   Mike Snitzer   dm thin: avoid me...
163
  bool dm_pool_changed_this_transaction(struct dm_pool_metadata *pmd);
da105ed5f   Joe Thornber   dm thin metadata:...
164
  bool dm_thin_aborted_changes(struct dm_thin_device *td);
991d9fa02   Joe Thornber   dm: add thin prov...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
  int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
  				     dm_block_t *highest_mapped);
  
  int dm_thin_get_mapped_count(struct dm_thin_device *td, dm_block_t *result);
  
  int dm_pool_get_free_block_count(struct dm_pool_metadata *pmd,
  				 dm_block_t *result);
  
  int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd,
  					  dm_block_t *result);
  
  int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd,
  				  dm_block_t *result);
  
  int dm_pool_get_data_block_size(struct dm_pool_metadata *pmd, sector_t *result);
  
  int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result);
19fa1a675   Joe Thornber   dm thin: fix disc...
182
  int dm_pool_block_is_used(struct dm_pool_metadata *pmd, dm_block_t b, bool *result);
991d9fa02   Joe Thornber   dm: add thin prov...
183
184
185
186
187
  /*
   * Returns -ENOSPC if the new size is too small and already allocated
   * blocks would be lost.
   */
  int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
24347e959   Joe Thornber   dm thin: detect m...
188
  int dm_pool_resize_metadata_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
991d9fa02   Joe Thornber   dm: add thin prov...
189

12ba58af4   Joe Thornber   dm thin metadata:...
190
191
192
193
194
  /*
   * Flicks the underlying block manager into read only mode, so you know
   * that nothing is changing.
   */
  void dm_pool_metadata_read_only(struct dm_pool_metadata *pmd);
9b7aaa64f   Joe Thornber   dm thin: allow po...
195
  void dm_pool_metadata_read_write(struct dm_pool_metadata *pmd);
12ba58af4   Joe Thornber   dm thin metadata:...
196

ac8c3f3df   Joe Thornber   dm thin: generate...
197
198
199
200
  int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd,
  					dm_block_t threshold,
  					dm_sm_threshold_fn fn,
  					void *context);
07f2b6e03   Mike Snitzer   dm thin: ensure u...
201
202
203
204
205
  /*
   * Updates the superblock immediately.
   */
  int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd);
  bool dm_pool_metadata_needs_check(struct dm_pool_metadata *pmd);
991d9fa02   Joe Thornber   dm: add thin prov...
206
207
208
  /*----------------------------------------------------------------*/
  
  #endif