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