Whamcloud - gitweb
LU-3118 lfsck: resume LFSCK from the last checkpoint
[fs/lustre-release.git] / lustre / mdd / mdd_lfsck.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License version 2 for more details.  A copy is
14  * included in the COPYING file that accompanied this code.
15
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2012 Intel Corporation.
24  */
25 /*
26  * lustre/mdd/mdd_lfsck.h
27  *
28  * Shared definitions and declarations for the LFSCK.
29  *
30  * Author: Fan, Yong <fan.yong@intel.com>
31  */
32
33 #ifndef _MDD_LFSCK_H
34 # define _MDD_LFSCK_H
35
36 #include <lustre/lustre_lfsck_user.h>
37
38 enum lfsck_status {
39         /* The lfsck file is new created, for new MDT, upgrading from old disk,
40          * or re-creating the lfsck file manually. */
41         LS_INIT                 = 0,
42
43         /* The first-step system scanning. */
44         LS_SCANNING_PHASE1      = 1,
45
46         /* The second-step system scanning. */
47         LS_SCANNING_PHASE2      = 2,
48
49         /* The LFSCK processing has completed for all objects. */
50         LS_COMPLETED            = 3,
51
52         /* The LFSCK exited automatically for failure, will not auto restart. */
53         LS_FAILED               = 4,
54
55         /* The LFSCK is stopped manually, will not auto restart. */
56         LS_STOPPED              = 5,
57
58         /* LFSCK is paused automatically when umount,
59          * will be restarted automatically when remount. */
60         LS_PAUSED               = 6,
61
62         /* System crashed during the LFSCK,
63          * will be restarted automatically after recovery. */
64         LS_CRASHED              = 7,
65 };
66
67 enum lfsck_flags {
68         /* Finish to the cycle scanning. */
69         LF_SCANNED_ONCE = 0x00000001ULL,
70
71         /* There is some namespace inconsistency. */
72         LF_INCONSISTENT = 0x00000002ULL,
73
74         /* The device is upgraded from 1.8 format. */
75         LF_UPGRADE      = 0x00000004ULL,
76 };
77
78 struct lfsck_position {
79         /* local layer object table-based iteration position. */
80         __u64   lp_oit_cookie;
81
82         /* parent FID for directory traversal. */
83         struct lu_fid lp_dir_parent;
84
85         /* namespace-based directory traversal position. */
86         __u64   lp_dir_cookie;
87 };
88
89 #define LFSCK_BOOKMARK_MAGIC    0x20130C1D
90
91 struct lfsck_bookmark {
92         /* Magic number to detect that this struct contains valid data. */
93         __u32   lb_magic;
94
95         /* For compatible with old versions. */
96         __u16   lb_version;
97
98         /* See 'enum lfsck_param_flags' */
99         __u16   lb_param;
100
101         /* How many items can be scanned at most per second. */
102         __u32   lb_speed_limit;
103
104         /* For 64-bits aligned. */
105         __u32   lb_padding;
106
107         /* For future using. */
108         __u64   lb_reserved[6];
109 };
110
111 #define LFSCK_NAMESPACE_MAGIC   0xA0629D03
112
113 struct lfsck_namespace {
114         /* Magic number to detect that this struct contains valid data. */
115         __u32   ln_magic;
116
117         /* See 'enum lfsck_status'. */
118         __u32   ln_status;
119
120         /* See 'enum lfsck_flags'. */
121         __u32   ln_flags;
122
123         /* How many completed LFSCK runs on the device. */
124         __u32   ln_success_count;
125
126         /*  How long the LFSCK phase1 has run in seconds. */
127         __u32   ln_run_time_phase1;
128
129         /*  How long the LFSCK phase2 has run in seconds. */
130         __u32   ln_run_time_phase2;
131
132         /* Time for the last LFSCK completed in seconds since epoch. */
133         __u64   ln_time_last_complete;
134
135         /* Time for the latest LFSCK ran in seconds since epoch. */
136         __u64   ln_time_latest_start;
137
138         /* Time for the last LFSCK checkpoint in seconds since epoch. */
139         __u64   ln_time_last_checkpoint;
140
141         /* Position for the latest LFSCK started from. */
142         struct lfsck_position   ln_pos_latest_start;
143
144         /* Position for the last LFSCK checkpoint. */
145         struct lfsck_position   ln_pos_last_checkpoint;
146
147         /* Position for the first should be updated object. */
148         struct lfsck_position   ln_pos_first_inconsistent;
149
150         /* How many items (including dir) have been checked. */
151         __u64   ln_items_checked;
152
153         /* How many items have been repaired. */
154         __u64   ln_items_repaired;
155
156         /* How many items failed to be processed. */
157         __u64   ln_items_failed;
158
159         /* How many directories have been traversed. */
160         __u64   ln_dirs_checked;
161
162         /* How many multiple-linked objects have been checked. */
163         __u64   ln_mlinked_checked;
164
165         /* How many objects have been double scanned. */
166         __u64   ln_objs_checked_phase2;
167
168         /* How many objects have been reparied during double scan. */
169         __u64   ln_objs_repaired_phase2;
170
171         /* How many objects failed to be processed during double scan. */
172         __u64   ln_objs_failed_phase2;
173
174         /* How many objects with nlink fixed. */
175         __u64   ln_objs_nlink_repaired;
176
177         /* How many objects were lost before, but found back now. */
178         __u64   ln_objs_lost_found;
179
180         /* The latest object has been processed (failed) during double scan. */
181         struct lu_fid   ln_fid_latest_scanned_phase2;
182
183         /* For further using. 256-bytes aligned now. */
184         __u64   ln_reserved[2];
185 };
186
187 struct lfsck_component;
188 struct mdd_object;
189
190 struct lfsck_operations {
191         int (*lfsck_reset)(const struct lu_env *env,
192                            struct lfsck_component *com,
193                            bool init);
194
195         void (*lfsck_fail)(const struct lu_env *env,
196                            struct lfsck_component *com,
197                            bool new_checked);
198
199         int (*lfsck_checkpoint)(const struct lu_env *env,
200                                 struct lfsck_component *com,
201                                 bool init);
202
203         int (*lfsck_prep)(const struct lu_env *env,
204                           struct lfsck_component *com);
205
206         int (*lfsck_exec_oit)(const struct lu_env *env,
207                               struct lfsck_component *com,
208                               struct mdd_object *obj);
209
210         int (*lfsck_exec_dir)(const struct lu_env *env,
211                               struct lfsck_component *com,
212                               struct mdd_object *obj,
213                               struct lu_dirent *ent);
214
215         int (*lfsck_post)(const struct lu_env *env,
216                           struct lfsck_component *com,
217                           int result, bool init);
218
219         int (*lfsck_dump)(const struct lu_env *env,
220                           struct lfsck_component *com,
221                           char *buf,
222                           int len);
223
224         int (*lfsck_double_scan)(const struct lu_env *env,
225                                  struct lfsck_component *com);
226 };
227
228 struct lfsck_component {
229         /* into md_lfsck::ml_list_(scan,double_scan,idle} */
230         cfs_list_t               lc_link;
231
232         /* into md_lfsck::ml_list_dir */
233         cfs_list_t               lc_link_dir;
234         struct rw_semaphore      lc_sem;
235         cfs_atomic_t             lc_ref;
236
237         struct lfsck_position    lc_pos_start;
238         struct md_lfsck         *lc_lfsck;
239         struct dt_object        *lc_obj;
240         struct lfsck_operations *lc_ops;
241         void                    *lc_file_ram;
242         void                    *lc_file_disk;
243         __u32                    lc_file_size;
244
245         /* How many objects have been checked since last checkpoint. */
246         __u32                    lc_new_checked;
247         unsigned int             lc_journal:1;
248         __u16                    lc_type;
249 };
250
251 struct md_lfsck {
252         struct mutex             ml_mutex;
253         spinlock_t               ml_lock;
254
255         /* For the components in (first) scanning via otable-based iteration. */
256         cfs_list_t               ml_list_scan;
257
258         /* For the components in scanning via directory traversal. Because
259          * directory traversal cannot guarantee all the object be scanned,
260          * so the component in the ml_list_dir must be in ml_list_scan. */
261         cfs_list_t               ml_list_dir;
262
263         /* For the components in double scanning. */
264         cfs_list_t               ml_list_double_scan;
265
266         /* For the components those are not scanning now. */
267         cfs_list_t               ml_list_idle;
268
269         struct ptlrpc_thread     ml_thread;
270
271         /* The time for last checkpoint, jiffies */
272         cfs_time_t               ml_time_last_checkpoint;
273
274         /* The time for next checkpoint, jiffies */
275         cfs_time_t               ml_time_next_checkpoint;
276
277         struct dt_object        *ml_bookmark_obj;
278         struct lfsck_bookmark    ml_bookmark_ram;
279         struct lfsck_bookmark    ml_bookmark_disk;
280         struct lfsck_position    ml_pos_current;
281
282         /* Obj for otable-based iteration */
283         struct dt_object        *ml_obj_oit;
284
285         /* Obj for directory traversal */
286         struct dt_object        *ml_obj_dir;
287
288         /* It for otable-based iteration */
289         struct dt_it            *ml_di_oit;
290
291         /* It for directory traversal */
292         struct dt_it            *ml_di_dir;
293
294         /* Arguments for low layer otable-based iteration. */
295         __u32                    ml_args_oit;
296
297         /* Arugments for namespace-based directory traversal. */
298         __u32                    ml_args_dir;
299
300         /* Schedule for every N objects. */
301         __u32                    ml_sleep_rate;
302
303         /* Sleep N jiffies for each schedule. */
304         __u32                    ml_sleep_jif;
305
306         /* How many objects have been scanned since last sleep. */
307         __u32                    ml_new_scanned;
308
309         unsigned int             ml_paused:1, /* The lfsck is paused. */
310                                  ml_oit_over:1, /* oit is finished. */
311                                  ml_drop_dryrun:1, /* Ever dryrun, not now. */
312                                  ml_initialized:1, /* lfsck_setup is called. */
313                                  ml_current_oit_processed:1;
314 };
315
316 enum lfsck_linkea_flags {
317         /* The linkea entries does not match the object nlinks. */
318         LLF_UNMATCH_NLINKS      = 0x01,
319
320         /* Fail to repair the multiple-linked objects during the double scan. */
321         LLF_REPAIR_FAILED       = 0x02,
322 };
323
324 #endif /* _MDD_LFSCK_H */