Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2011 Red Hat, Inc.
0003  *
0004  * This file is released under the GPL.
0005  */
0006 
0007 #ifndef _LINUX_DM_SPACE_MAP_H
0008 #define _LINUX_DM_SPACE_MAP_H
0009 
0010 #include "dm-block-manager.h"
0011 
0012 typedef void (*dm_sm_threshold_fn)(void *context);
0013 
0014 /*
0015  * struct dm_space_map keeps a record of how many times each block in a device
0016  * is referenced.  It needs to be fixed on disk as part of the transaction.
0017  */
0018 struct dm_space_map {
0019     void (*destroy)(struct dm_space_map *sm);
0020 
0021     /*
0022      * You must commit before allocating the newly added space.
0023      */
0024     int (*extend)(struct dm_space_map *sm, dm_block_t extra_blocks);
0025 
0026     /*
0027      * Extensions do not appear in this count until after commit has
0028      * been called.
0029      */
0030     int (*get_nr_blocks)(struct dm_space_map *sm, dm_block_t *count);
0031 
0032     /*
0033      * Space maps must never allocate a block from the previous
0034      * transaction, in case we need to rollback.  This complicates the
0035      * semantics of get_nr_free(), it should return the number of blocks
0036      * that are available for allocation _now_.  For instance you may
0037      * have blocks with a zero reference count that will not be
0038      * available for allocation until after the next commit.
0039      */
0040     int (*get_nr_free)(struct dm_space_map *sm, dm_block_t *count);
0041 
0042     int (*get_count)(struct dm_space_map *sm, dm_block_t b, uint32_t *result);
0043     int (*count_is_more_than_one)(struct dm_space_map *sm, dm_block_t b,
0044                       int *result);
0045     int (*set_count)(struct dm_space_map *sm, dm_block_t b, uint32_t count);
0046 
0047     int (*commit)(struct dm_space_map *sm);
0048 
0049     int (*inc_blocks)(struct dm_space_map *sm, dm_block_t b, dm_block_t e);
0050     int (*dec_blocks)(struct dm_space_map *sm, dm_block_t b, dm_block_t e);
0051 
0052     /*
0053      * new_block will increment the returned block.
0054      */
0055     int (*new_block)(struct dm_space_map *sm, dm_block_t *b);
0056 
0057     /*
0058      * The root contains all the information needed to fix the space map.
0059      * Generally this info is small, so squirrel it away in a disk block
0060      * along with other info.
0061      */
0062     int (*root_size)(struct dm_space_map *sm, size_t *result);
0063     int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
0064 
0065     /*
0066      * You can register one threshold callback which is edge-triggered
0067      * when the free space in the space map drops below the threshold.
0068      */
0069     int (*register_threshold_callback)(struct dm_space_map *sm,
0070                        dm_block_t threshold,
0071                        dm_sm_threshold_fn fn,
0072                        void *context);
0073 };
0074 
0075 /*----------------------------------------------------------------*/
0076 
0077 static inline void dm_sm_destroy(struct dm_space_map *sm)
0078 {
0079     sm->destroy(sm);
0080 }
0081 
0082 static inline int dm_sm_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
0083 {
0084     return sm->extend(sm, extra_blocks);
0085 }
0086 
0087 static inline int dm_sm_get_nr_blocks(struct dm_space_map *sm, dm_block_t *count)
0088 {
0089     return sm->get_nr_blocks(sm, count);
0090 }
0091 
0092 static inline int dm_sm_get_nr_free(struct dm_space_map *sm, dm_block_t *count)
0093 {
0094     return sm->get_nr_free(sm, count);
0095 }
0096 
0097 static inline int dm_sm_get_count(struct dm_space_map *sm, dm_block_t b,
0098                   uint32_t *result)
0099 {
0100     return sm->get_count(sm, b, result);
0101 }
0102 
0103 static inline int dm_sm_count_is_more_than_one(struct dm_space_map *sm,
0104                            dm_block_t b, int *result)
0105 {
0106     return sm->count_is_more_than_one(sm, b, result);
0107 }
0108 
0109 static inline int dm_sm_set_count(struct dm_space_map *sm, dm_block_t b,
0110                   uint32_t count)
0111 {
0112     return sm->set_count(sm, b, count);
0113 }
0114 
0115 static inline int dm_sm_commit(struct dm_space_map *sm)
0116 {
0117     return sm->commit(sm);
0118 }
0119 
0120 static inline int dm_sm_inc_blocks(struct dm_space_map *sm, dm_block_t b, dm_block_t e)
0121 {
0122     return sm->inc_blocks(sm, b, e);
0123 }
0124 
0125 static inline int dm_sm_inc_block(struct dm_space_map *sm, dm_block_t b)
0126 {
0127     return dm_sm_inc_blocks(sm, b, b + 1);
0128 }
0129 
0130 static inline int dm_sm_dec_blocks(struct dm_space_map *sm, dm_block_t b, dm_block_t e)
0131 {
0132     return sm->dec_blocks(sm, b, e);
0133 }
0134 
0135 static inline int dm_sm_dec_block(struct dm_space_map *sm, dm_block_t b)
0136 {
0137     return dm_sm_dec_blocks(sm, b, b + 1);
0138 }
0139 
0140 static inline int dm_sm_new_block(struct dm_space_map *sm, dm_block_t *b)
0141 {
0142     return sm->new_block(sm, b);
0143 }
0144 
0145 static inline int dm_sm_root_size(struct dm_space_map *sm, size_t *result)
0146 {
0147     return sm->root_size(sm, result);
0148 }
0149 
0150 static inline int dm_sm_copy_root(struct dm_space_map *sm, void *copy_to_here_le, size_t len)
0151 {
0152     return sm->copy_root(sm, copy_to_here_le, len);
0153 }
0154 
0155 static inline int dm_sm_register_threshold_callback(struct dm_space_map *sm,
0156                             dm_block_t threshold,
0157                             dm_sm_threshold_fn fn,
0158                             void *context)
0159 {
0160     if (sm->register_threshold_callback)
0161         return sm->register_threshold_callback(sm, threshold, fn, context);
0162 
0163     return -EINVAL;
0164 }
0165 
0166 
0167 #endif  /* _LINUX_DM_SPACE_MAP_H */