4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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.
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
23 * Copyright (c) 2013, Intel Corporation.
26 * lustre/mdd/mdd_lfsck.h
28 * Shared definitions and declarations for the LFSCK.
30 * Author: Fan, Yong <fan.yong@intel.com>
36 #include <lustre/lustre_lfsck_user.h>
39 /* The lfsck file is new created, for new MDT, upgrading from old disk,
40 * or re-creating the lfsck file manually. */
43 /* The first-step system scanning. */
44 LS_SCANNING_PHASE1 = 1,
46 /* The second-step system scanning. */
47 LS_SCANNING_PHASE2 = 2,
49 /* The LFSCK processing has completed for all objects. */
52 /* The LFSCK exited automatically for failure, will not auto restart. */
55 /* The LFSCK is stopped manually, will not auto restart. */
58 /* LFSCK is paused automatically when umount,
59 * will be restarted automatically when remount. */
62 /* System crashed during the LFSCK,
63 * will be restarted automatically after recovery. */
68 /* Finish to the cycle scanning. */
69 LF_SCANNED_ONCE = 0x00000001ULL,
71 /* There is some namespace inconsistency. */
72 LF_INCONSISTENT = 0x00000002ULL,
74 /* The device is upgraded from 1.8 format. */
75 LF_UPGRADE = 0x00000004ULL,
78 struct lfsck_position {
79 /* local layer object table-based iteration position. */
82 /* parent FID for directory traversal. */
83 struct lu_fid lp_dir_parent;
85 /* namespace-based directory traversal position. */
89 #define LFSCK_BOOKMARK_MAGIC 0x20130C1D
91 struct lfsck_bookmark {
92 /* Magic number to detect that this struct contains valid data. */
95 /* For compatible with old versions. */
98 /* See 'enum lfsck_param_flags' */
101 /* How many items can be scanned at most per second. */
102 __u32 lb_speed_limit;
104 /* For 64-bits aligned. */
107 /* For future using. */
108 __u64 lb_reserved[6];
111 #define LFSCK_NAMESPACE_MAGIC 0xA0629D03
113 struct lfsck_namespace {
114 /* Magic number to detect that this struct contains valid data. */
117 /* See 'enum lfsck_status'. */
120 /* See 'enum lfsck_flags'. */
123 /* How many completed LFSCK runs on the device. */
124 __u32 ln_success_count;
126 /* How long the LFSCK phase1 has run in seconds. */
127 __u32 ln_run_time_phase1;
129 /* How long the LFSCK phase2 has run in seconds. */
130 __u32 ln_run_time_phase2;
132 /* Time for the last LFSCK completed in seconds since epoch. */
133 __u64 ln_time_last_complete;
135 /* Time for the latest LFSCK ran in seconds since epoch. */
136 __u64 ln_time_latest_start;
138 /* Time for the last LFSCK checkpoint in seconds since epoch. */
139 __u64 ln_time_last_checkpoint;
141 /* Position for the latest LFSCK started from. */
142 struct lfsck_position ln_pos_latest_start;
144 /* Position for the last LFSCK checkpoint. */
145 struct lfsck_position ln_pos_last_checkpoint;
147 /* Position for the first should be updated object. */
148 struct lfsck_position ln_pos_first_inconsistent;
150 /* How many items (including dir) have been checked. */
151 __u64 ln_items_checked;
153 /* How many items have been repaired. */
154 __u64 ln_items_repaired;
156 /* How many items failed to be processed. */
157 __u64 ln_items_failed;
159 /* How many directories have been traversed. */
160 __u64 ln_dirs_checked;
162 /* How many multiple-linked objects have been checked. */
163 __u64 ln_mlinked_checked;
165 /* How many objects have been double scanned. */
166 __u64 ln_objs_checked_phase2;
168 /* How many objects have been reparied during double scan. */
169 __u64 ln_objs_repaired_phase2;
171 /* How many objects failed to be processed during double scan. */
172 __u64 ln_objs_failed_phase2;
174 /* How many objects with nlink fixed. */
175 __u64 ln_objs_nlink_repaired;
177 /* How many objects were lost before, but found back now. */
178 __u64 ln_objs_lost_found;
180 /* The latest object has been processed (failed) during double scan. */
181 struct lu_fid ln_fid_latest_scanned_phase2;
183 /* For further using. 256-bytes aligned now. */
184 __u64 ln_reserved[2];
187 struct lfsck_component;
190 struct lfsck_operations {
191 int (*lfsck_reset)(const struct lu_env *env,
192 struct lfsck_component *com,
195 void (*lfsck_fail)(const struct lu_env *env,
196 struct lfsck_component *com,
199 int (*lfsck_checkpoint)(const struct lu_env *env,
200 struct lfsck_component *com,
203 int (*lfsck_prep)(const struct lu_env *env,
204 struct lfsck_component *com);
206 int (*lfsck_exec_oit)(const struct lu_env *env,
207 struct lfsck_component *com,
208 struct mdd_object *obj);
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);
215 int (*lfsck_post)(const struct lu_env *env,
216 struct lfsck_component *com,
217 int result, bool init);
219 int (*lfsck_dump)(const struct lu_env *env,
220 struct lfsck_component *com,
224 int (*lfsck_double_scan)(const struct lu_env *env,
225 struct lfsck_component *com);
228 struct lfsck_component {
229 /* into md_lfsck::ml_list_(scan,double_scan,idle} */
232 /* into md_lfsck::ml_list_dir */
233 cfs_list_t lc_link_dir;
234 struct rw_semaphore lc_sem;
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;
245 /* How many objects have been checked since last checkpoint. */
246 __u32 lc_new_checked;
247 unsigned int lc_journal:1;
252 struct mutex ml_mutex;
255 /* For the components in (first) scanning via otable-based iteration. */
256 cfs_list_t ml_list_scan;
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;
263 /* For the components in double scanning. */
264 cfs_list_t ml_list_double_scan;
266 /* For the components those are not scanning now. */
267 cfs_list_t ml_list_idle;
269 struct ptlrpc_thread ml_thread;
271 /* The time for last checkpoint, jiffies */
272 cfs_time_t ml_time_last_checkpoint;
274 /* The time for next checkpoint, jiffies */
275 cfs_time_t ml_time_next_checkpoint;
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;
282 /* Obj for otable-based iteration */
283 struct dt_object *ml_obj_oit;
285 /* Obj for directory traversal */
286 struct dt_object *ml_obj_dir;
288 /* It for otable-based iteration */
289 struct dt_it *ml_di_oit;
291 /* It for directory traversal */
292 struct dt_it *ml_di_dir;
294 /* Arguments for low layer otable-based iteration. */
297 /* Arugments for namespace-based directory traversal. */
300 /* Schedule for every N objects. */
303 /* Sleep N jiffies for each schedule. */
306 /* How many objects have been scanned since last sleep. */
307 __u32 ml_new_scanned;
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;
316 enum lfsck_linkea_flags {
317 /* The linkea entries does not match the object nlinks. */
318 LLF_UNMATCH_NLINKS = 0x01,
320 /* Fail to repair the multiple-linked objects during the double scan. */
321 LLF_REPAIR_FAILED = 0x02,
324 #endif /* _MDD_LFSCK_H */