2 * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
4 * This file is released under the GPL.
7 #ifndef _LINUX_DM_SPACE_MAP_H
8 #define _LINUX_DM_SPACE_MAP_H
10 #include "dm-block-manager.h"
13 * struct dm_space_map keeps a record of how many times each block in a device
14 * is referenced. It needs to be fixed on disk as part of the transaction.
17 void (*destroy
)(struct dm_space_map
*sm
);
19 int (*extend
)(struct dm_space_map
*sm
, dm_block_t extra_blocks
);
21 int (*get_nr_blocks
)(struct dm_space_map
*sm
, dm_block_t
*count
);
22 int (*get_nr_free
)(struct dm_space_map
*sm
, dm_block_t
*count
);
24 int (*get_count
)(struct dm_space_map
*sm
, dm_block_t b
, uint32_t *result
);
25 int (*count_is_more_than_one
)(struct dm_space_map
*sm
, dm_block_t b
,
27 int (*set_count
)(struct dm_space_map
*sm
, dm_block_t b
, uint32_t count
);
29 int (*commit
)(struct dm_space_map
*sm
);
31 int (*inc_block
)(struct dm_space_map
*sm
, dm_block_t b
);
32 int (*dec_block
)(struct dm_space_map
*sm
, dm_block_t b
);
35 * new_block will increment the returned block.
37 int (*new_block
)(struct dm_space_map
*sm
, dm_block_t
*b
);
40 * The root contains all the information needed to fix the space map.
41 * Generally this info is small, so squirrel it away in a disk block
42 * along with other info.
44 int (*root_size
)(struct dm_space_map
*sm
, size_t *result
);
45 int (*copy_root
)(struct dm_space_map
*sm
, void *copy_to_here_le
, size_t len
);
48 /*----------------------------------------------------------------*/
50 static inline void dm_sm_destroy(struct dm_space_map
*sm
)
55 static inline int dm_sm_extend(struct dm_space_map
*sm
, dm_block_t extra_blocks
)
57 return sm
->extend(sm
, extra_blocks
);
60 static inline int dm_sm_get_nr_blocks(struct dm_space_map
*sm
, dm_block_t
*count
)
62 return sm
->get_nr_blocks(sm
, count
);
65 static inline int dm_sm_get_nr_free(struct dm_space_map
*sm
, dm_block_t
*count
)
67 return sm
->get_nr_free(sm
, count
);
70 static inline int dm_sm_get_count(struct dm_space_map
*sm
, dm_block_t b
,
73 return sm
->get_count(sm
, b
, result
);
76 static inline int dm_sm_count_is_more_than_one(struct dm_space_map
*sm
,
77 dm_block_t b
, int *result
)
79 return sm
->count_is_more_than_one(sm
, b
, result
);
82 static inline int dm_sm_set_count(struct dm_space_map
*sm
, dm_block_t b
,
85 return sm
->set_count(sm
, b
, count
);
88 static inline int dm_sm_commit(struct dm_space_map
*sm
)
90 return sm
->commit(sm
);
93 static inline int dm_sm_inc_block(struct dm_space_map
*sm
, dm_block_t b
)
95 return sm
->inc_block(sm
, b
);
98 static inline int dm_sm_dec_block(struct dm_space_map
*sm
, dm_block_t b
)
100 return sm
->dec_block(sm
, b
);
103 static inline int dm_sm_new_block(struct dm_space_map
*sm
, dm_block_t
*b
)
105 return sm
->new_block(sm
, b
);
108 static inline int dm_sm_root_size(struct dm_space_map
*sm
, size_t *result
)
110 return sm
->root_size(sm
, result
);
113 static inline int dm_sm_copy_root(struct dm_space_map
*sm
, void *copy_to_here_le
, size_t len
)
115 return sm
->copy_root(sm
, copy_to_here_le
, len
);
118 #endif /* _LINUX_DM_SPACE_MAP_H */