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