]> git.ipfire.org Git - thirdparty/mdadm.git/blame - mdmon.h
mdmon: fix wrong array state when disk fails during mdmon startup
[thirdparty/mdadm.git] / mdmon.h
CommitLineData
a54d5262
DW
1/*
2 * mdmon - monitor external metadata arrays
3 *
e736b623
N
4 * Copyright (C) 2007-2009 Neil Brown <neilb@suse.de>
5 * Copyright (C) 2007-2009 Intel Corporation
a54d5262
DW
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
d56dd607 21extern const char Name[];
a88e119f 22
549e9569
NB
23enum array_state { clear, inactive, suspended, readonly, read_auto,
24 clean, active, write_pending, active_idle, bad_word};
25
26enum sync_action { idle, reshape, resync, recover, check, repair, bad_action };
27
549e9569
NB
28struct active_array {
29 struct mdinfo info;
30 struct supertype *container;
31 struct active_array *next, *replaces;
ba714450 32 int to_remove;
549e9569
NB
33
34 int action_fd;
c052ba30 35 int resync_start_fd;
e9dd1598 36 int metadata_fd; /* for monitoring rw/ro status */
484240d8 37 int sync_completed_fd; /* for checkpoint notification events */
c76242c5 38 int safe_mode_delay_fd;
484240d8
DW
39 unsigned long long last_checkpoint; /* sync_completed fires for many
40 * reasons this field makes sure the
41 * kernel has made progress before
42 * moving the checkpoint. It is
43 * cleared by the metadata handler
44 * when it determines recovery is
45 * terminated.
46 */
549e9569
NB
47
48 enum array_state prev_state, curr_state, next_state;
49 enum sync_action prev_action, curr_action, next_action;
50
6c3fb95c 51 int check_degraded; /* flag set by mon, read by manage */
0f99b4bd 52 int check_reshape; /* flag set by mon, read by manage */
549e9569
NB
53};
54
2e735d19
NB
55/*
56 * Metadata updates are handled by the monitor thread,
57 * as it has exclusive access to the metadata.
58 * When the manager want to updates metadata, either
59 * for it's own reason (e.g. committing a spare) or
60 * on behalf of mdadm, it creates a metadata_update
61 * structure and queues it to the monitor.
62 * Updates are created and processed by code under the
63 * superswitch. All common code sees them as opaque
64 * blobs.
65 */
2e735d19 66extern struct metadata_update *update_queue, *update_queue_handled;
549e9569
NB
67
68#define MD_MAJOR 9
69
70extern struct active_array *container;
549e9569
NB
71extern struct active_array *discard_this;
72extern struct active_array *pending_discard;
3e70c845 73extern struct md_generic_cmd *active_cmd;
549e9569 74
e0d6609f 75void remove_pidfile(char *devname);
549e9569
NB
76void do_monitor(struct supertype *container);
77void do_manager(struct supertype *container);
6144ed44 78extern int sigterm;
549e9569
NB
79
80int read_dev_state(int fd);
883a6142 81int is_container_member(struct mdstat_ent *mdstat, char *container);
549e9569
NB
82
83struct mdstat_ent *mdstat_read(int hold, int start);
84
e0d6609f 85extern int exit_now, manager_ready;
4d43913c 86extern int mon_tid, mgr_tid;
1eb252b8 87extern int monitor_loop_cnt;
593add1b
DW
88
89/* helper routine to determine resync completion since MaxSector is a
90 * moving target
91 */
b7941fd6 92static inline int is_resync_complete(struct mdinfo *array)
593add1b 93{
71d68ff6
N
94 unsigned long long sync_size = 0;
95 int ncopies, l;
96 switch(array->array.level) {
97 case 1:
98 case 4:
99 case 5:
100 case 6:
101 sync_size = array->component_size;
102 break;
103 case 10:
104 l = array->array.layout;
681b7ae2 105 ncopies = (l & 0xff) * ((l >> 8) & 0xff);
71d68ff6
N
106 sync_size = array->component_size * array->array.raid_disks;
107 sync_size /= ncopies;
108 break;
109 }
110 return array->resync_start >= sync_size;
593add1b 111}