Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2003 Sistina Software Limited.
0003  * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
0004  *
0005  * Device-Mapper dirty region hash interface.
0006  *
0007  * This file is released under the GPL.
0008  */
0009 
0010 #ifndef DM_REGION_HASH_H
0011 #define DM_REGION_HASH_H
0012 
0013 #include <linux/dm-dirty-log.h>
0014 
0015 /*-----------------------------------------------------------------
0016  * Region hash
0017  *----------------------------------------------------------------*/
0018 struct dm_region_hash;
0019 struct dm_region;
0020 
0021 /*
0022  * States a region can have.
0023  */
0024 enum dm_rh_region_states {
0025     DM_RH_CLEAN  = 0x01,    /* No writes in flight. */
0026     DM_RH_DIRTY  = 0x02,    /* Writes in flight. */
0027     DM_RH_NOSYNC     = 0x04,    /* Out of sync. */
0028     DM_RH_RECOVERING = 0x08,    /* Under resynchronization. */
0029 };
0030 
0031 /*
0032  * Region hash create/destroy.
0033  */
0034 struct bio_list;
0035 struct dm_region_hash *dm_region_hash_create(
0036         void *context, void (*dispatch_bios)(void *context,
0037                              struct bio_list *bios),
0038         void (*wakeup_workers)(void *context),
0039         void (*wakeup_all_recovery_waiters)(void *context),
0040         sector_t target_begin, unsigned max_recovery,
0041         struct dm_dirty_log *log, uint32_t region_size,
0042         region_t nr_regions);
0043 void dm_region_hash_destroy(struct dm_region_hash *rh);
0044 
0045 struct dm_dirty_log *dm_rh_dirty_log(struct dm_region_hash *rh);
0046 
0047 /*
0048  * Conversion functions.
0049  */
0050 region_t dm_rh_bio_to_region(struct dm_region_hash *rh, struct bio *bio);
0051 sector_t dm_rh_region_to_sector(struct dm_region_hash *rh, region_t region);
0052 void *dm_rh_region_context(struct dm_region *reg);
0053 
0054 /*
0055  * Get region size and key (ie. number of the region).
0056  */
0057 sector_t dm_rh_get_region_size(struct dm_region_hash *rh);
0058 region_t dm_rh_get_region_key(struct dm_region *reg);
0059 
0060 /*
0061  * Get/set/update region state (and dirty log).
0062  *
0063  */
0064 int dm_rh_get_state(struct dm_region_hash *rh, region_t region, int may_block);
0065 void dm_rh_set_state(struct dm_region_hash *rh, region_t region,
0066              enum dm_rh_region_states state, int may_block);
0067 
0068 /* Non-zero errors_handled leaves the state of the region NOSYNC */
0069 void dm_rh_update_states(struct dm_region_hash *rh, int errors_handled);
0070 
0071 /* Flush the region hash and dirty log. */
0072 int dm_rh_flush(struct dm_region_hash *rh);
0073 
0074 /* Inc/dec pending count on regions. */
0075 void dm_rh_inc_pending(struct dm_region_hash *rh, struct bio_list *bios);
0076 void dm_rh_dec(struct dm_region_hash *rh, region_t region);
0077 
0078 /* Delay bios on regions. */
0079 void dm_rh_delay(struct dm_region_hash *rh, struct bio *bio);
0080 
0081 void dm_rh_mark_nosync(struct dm_region_hash *rh, struct bio *bio);
0082 
0083 /*
0084  * Region recovery control.
0085  */
0086 
0087 /* Prepare some regions for recovery by starting to quiesce them. */
0088 void dm_rh_recovery_prepare(struct dm_region_hash *rh);
0089 
0090 /* Try fetching a quiesced region for recovery. */
0091 struct dm_region *dm_rh_recovery_start(struct dm_region_hash *rh);
0092 
0093 /* Report recovery end on a region. */
0094 void dm_rh_recovery_end(struct dm_region *reg, int error);
0095 
0096 /* Returns number of regions with recovery work outstanding. */
0097 int dm_rh_recovery_in_flight(struct dm_region_hash *rh);
0098 
0099 /* Start/stop recovery. */
0100 void dm_rh_start_recovery(struct dm_region_hash *rh);
0101 void dm_rh_stop_recovery(struct dm_region_hash *rh);
0102 
0103 #endif /* DM_REGION_HASH_H */