1 1.2 jld /* $NetBSD: rf_paritymap.h,v 1.2 2010/03/14 21:11:41 jld Exp $ */ 2 1.1 jld 3 1.1 jld /*- 4 1.1 jld * Copyright (c) 2009 Jed Davis. 5 1.1 jld * All rights reserved. 6 1.1 jld * 7 1.1 jld * Redistribution and use in source and binary forms, with or without 8 1.1 jld * modification, are permitted provided that the following conditions 9 1.1 jld * are met: 10 1.1 jld * 1. Redistributions of source code must retain the above copyright 11 1.1 jld * notice, this list of conditions and the following disclaimer. 12 1.1 jld * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 jld * notice, this list of conditions and the following disclaimer in the 14 1.1 jld * documentation and/or other materials provided with the distribution. 15 1.1 jld * 16 1.1 jld * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 1.1 jld * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 1.1 jld * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 1.1 jld * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 1.1 jld * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 1.1 jld * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 1.1 jld * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 1.1 jld * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 1.1 jld * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 1.1 jld * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 1.1 jld * POSSIBILITY OF SUCH DAMAGE. 27 1.1 jld */ 28 1.1 jld 29 1.1 jld #include <sys/mutex.h> 30 1.1 jld #include <sys/param.h> 31 1.1 jld #include <sys/rwlock.h> 32 1.1 jld #include <sys/types.h> 33 1.1 jld 34 1.1 jld #include <dev/raidframe/raidframevar.h> 35 1.1 jld 36 1.1 jld /* RF_PARITYMAP_N* in raidframevar.h */ 37 1.1 jld 38 1.1 jld #define RF_PMLABEL_VALID 1 39 1.1 jld #define RF_PMLABEL_WASUSED 2 40 1.1 jld #define RF_PMLABEL_DISABLE 4 41 1.1 jld 42 1.1 jld /* 43 1.1 jld * On-disk format: a single bit for each region; if the bit is clear, 44 1.1 jld * then the parity is clean. 45 1.1 jld */ 46 1.1 jld struct rf_paritymap_ondisk 47 1.1 jld { 48 1.1 jld /* XXX Do these really need to be volatile? */ 49 1.1 jld volatile char bits[RF_PARITYMAP_NBYTE]; 50 1.1 jld }; 51 1.1 jld 52 1.1 jld /* In-core per-region state: a byte for each, encoded as follows. */ 53 1.1 jld struct rf_paritymap_current 54 1.1 jld { 55 1.1 jld volatile int8_t state[RF_PARITYMAP_NREG]; 56 1.1 jld /* 57 1.1 jld * Values: 58 1.1 jld * if x == 0, the region may be written out as clean 59 1.1 jld * if x > 0, then x outstanding IOs to that region 60 1.1 jld * if x < 0, then there was recently IO; periodically increment x 61 1.1 jld */ 62 1.1 jld }; 63 1.1 jld 64 1.1 jld /* The entire state. */ 65 1.1 jld struct rf_paritymap 66 1.1 jld { 67 1.1 jld struct rf_paritymap_ondisk *disk_boot, *disk_now; 68 1.1 jld struct rf_paritymap_current *current; 69 1.1 jld 70 1.1 jld /* 71 1.1 jld * This lock will be held while component disks' caches are 72 1.1 jld * flushed, which could take many milliseconds, so it should 73 1.1 jld * not be taken where that kind of delay is unacceptable. 74 1.1 jld * Contention on this lock is not, however, expected to be a 75 1.1 jld * performance bottleneck. 76 1.1 jld */ 77 1.1 jld kmutex_t lock; 78 1.1 jld /* 79 1.1 jld * The flags field, below, has its own lock so that 80 1.1 jld * inter-thread communication can occur without taking the 81 1.1 jld * overall lock. Ordering is lock -> lk_flags. 82 1.1 jld */ 83 1.1 jld kmutex_t lk_flags; 84 1.1 jld 85 1.1 jld RF_Raid_t *raid; 86 1.1 jld daddr_t region_size; 87 1.1 jld callout_t ticker; 88 1.1 jld struct rf_pmparams params; 89 1.1 jld volatile int flags; 90 1.1 jld struct rf_pmctrs ctrs; 91 1.1 jld }; 92 1.1 jld 93 1.1 jld void rf_paritymap_status(struct rf_paritymap *, struct rf_pmstat *); 94 1.1 jld 95 1.1 jld int rf_paritymap_test(struct rf_paritymap *, daddr_t); 96 1.1 jld void rf_paritymap_begin_region(struct rf_paritymap *, unsigned); 97 1.1 jld void rf_paritymap_begin(struct rf_paritymap *, daddr_t, daddr_t); 98 1.1 jld void rf_paritymap_end_region(struct rf_paritymap *, unsigned); 99 1.1 jld void rf_paritymap_end(struct rf_paritymap *, daddr_t, daddr_t); 100 1.1 jld 101 1.1 jld void rf_paritymap_checkwork(struct rf_paritymap *); 102 1.1 jld void rf_paritymap_invalidate(struct rf_paritymap *); 103 1.1 jld void rf_paritymap_forceclean(struct rf_paritymap *); 104 1.1 jld void rf_paritymap_write(struct rf_paritymap *); 105 1.1 jld 106 1.1 jld int rf_paritymap_init(struct rf_paritymap *, RF_Raid_t *, 107 1.1 jld const struct rf_pmparams *); 108 1.1 jld void rf_paritymap_destroy(struct rf_paritymap *, int); 109 1.1 jld 110 1.1 jld int rf_paritymap_rewrite(struct rf_paritymap *); 111 1.1 jld 112 1.1 jld int rf_paritymap_merge(struct rf_paritymap_ondisk *, 113 1.1 jld struct rf_paritymap_ondisk *); 114 1.1 jld 115 1.2 jld int rf_paritymap_ineligible(RF_Raid_t *); 116 1.1 jld void rf_paritymap_attach(RF_Raid_t *, int); 117 1.1 jld void rf_paritymap_detach(RF_Raid_t *); /* Not while the RAID is live! */ 118 1.1 jld 119 1.1 jld int rf_paritymap_get_disable(RF_Raid_t *); 120 1.1 jld void rf_paritymap_set_disable(RF_Raid_t *, int); 121 1.1 jld 122 1.1 jld int rf_paritymap_set_params(struct rf_paritymap *, 123 1.1 jld const struct rf_pmparams *, int); 124 1.1 jld 125 1.1 jld void rf_paritymap_init_label(struct rf_paritymap *, 126 1.1 jld RF_ComponentLabel_t *); 127