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