2 * mdmon - monitor external metadata arrays
4 * Copyright (C) 2007-2009 Neil Brown <neilb@suse.de>
5 * Copyright (C) 2007-2009 Intel Corporation
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.
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
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.
21 extern const char Name[];
23 enum array_state { clear, inactive, suspended, readonly, read_auto,
24 clean, active, write_pending, active_idle, bad_word};
26 enum sync_action { idle, reshape, resync, recover, check, repair, bad_action };
30 struct supertype *container;
31 struct active_array *next, *replaces;
36 int metadata_fd; /* for monitoring rw/ro status */
37 int sync_completed_fd; /* for checkpoint notification events */
38 unsigned long long last_checkpoint; /* sync_completed fires for many
39 * reasons this field makes sure the
40 * kernel has made progress before
41 * moving the checkpoint. It is
42 * cleared by the metadata handler
43 * when it determines recovery is
47 enum array_state prev_state, curr_state, next_state;
48 enum sync_action prev_action, curr_action, next_action;
50 int check_degraded; /* flag set by mon, read by manage */
51 int check_reshape; /* flag set by mon, read by manage */
55 * Metadata updates are handled by the monitor thread,
56 * as it has exclusive access to the metadata.
57 * When the manager want to updates metadata, either
58 * for it's own reason (e.g. committing a spare) or
59 * on behalf of mdadm, it creates a metadata_update
60 * structure and queues it to the monitor.
61 * Updates are created and processed by code under the
62 * superswitch. All common code sees them as opaque
65 extern struct metadata_update *update_queue, *update_queue_handled;
69 extern struct active_array *container;
70 extern struct active_array *discard_this;
71 extern struct active_array *pending_discard;
72 extern struct md_generic_cmd *active_cmd;
74 void remove_pidfile(char *devname);
75 void do_monitor(struct supertype *container);
76 void do_manager(struct supertype *container);
79 int read_dev_state(int fd);
80 int is_container_member(struct mdstat_ent *mdstat, char *container);
82 struct mdstat_ent *mdstat_read(int hold, int start);
84 extern int exit_now, manager_ready;
85 extern int mon_tid, mgr_tid;
86 extern int monitor_loop_cnt;
88 /* helper routine to determine resync completion since MaxSector is a
91 static inline int is_resync_complete(struct mdinfo *array)
93 unsigned long long sync_size = 0;
95 switch(array->array.level) {
100 sync_size = array->component_size;
103 l = array->array.layout;
104 ncopies = (l & 0xff) * ((l >> 8) & 0xff);
105 sync_size = array->component_size * array->array.raid_disks;
106 sync_size /= ncopies;
109 return array->resync_start >= sync_size;