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, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2017, Intel Corporation.
26 * lustre/include/lustre_scrub.h
28 * Shared definitions and declarations for Lustre OI scrub.
30 * Author: Fan Yong <fan.yong@intel.com>
33 #ifndef _LUSTRE_SCRUB_H
34 # define _LUSTRE_SCRUB_H
36 #include <dt_object.h>
37 #include <lustre_net.h>
39 #define OSD_OI_FID_OID_BITS_MAX 10
40 #define OSD_OI_FID_NR_MAX (1UL << OSD_OI_FID_OID_BITS_MAX)
41 #define SCRUB_OI_BITMAP_SIZE (OSD_OI_FID_NR_MAX >> 3)
43 #define SCRUB_MAGIC_V1 0x4C5FD252
44 #define SCRUB_CHECKPOINT_INTERVAL 60
45 #define SCRUB_WINDOW_SIZE 1024
47 #define HALF_SEC msecs_to_jiffies(MSEC_PER_SEC >> 1)
49 enum scrub_next_status {
50 /* exit current loop and process next group */
53 /* skip current object and process next bit */
54 SCRUB_NEXT_CONTINUE = 2,
56 /* exit all the loops */
59 /* wait for free cache slot */
62 /* simulate system crash during OI scrub */
65 /* simulate failure during OI scrub */
68 /* new created object, no scrub on it */
69 SCRUB_NEXT_NOSCRUB = 7,
71 /* the object has no FID-in-LMA */
75 SCRUB_NEXT_OSTOBJ = 9,
77 /* old OST-object, no LMA or no FID-on-OST flags in LMA */
78 SCRUB_NEXT_OSTOBJ_OLD = 10,
81 enum scrub_local_file_flags {
82 SLFF_SCAN_SUBITEMS = 0x0001,
83 SLFF_HIDE_FID = 0x0002,
84 SLFF_SHOW_NAME = 0x0004,
86 SLFF_IDX_IN_FID = 0x0010,
90 /* The scrub file is new created, for new MDT, upgrading from old disk,
91 * or re-creating the scrub file manually. */
94 /* The scrub is checking/repairing the OI files. */
97 /* The scrub checked/repaired the OI files successfully. */
100 /* The scrub failed to check/repair the OI files. */
103 /* The scrub is stopped manually, the OI files may be inconsistent. */
106 /* The scrub is paused automatically when umount. */
109 /* The scrub crashed during the scanning, should be restarted. */
114 /* OI files have been recreated, OI mappings should be re-inserted. */
115 SF_RECREATED = 0x0000000000000001ULL,
117 /* OI files are invalid, should be rebuild ASAP */
118 SF_INCONSISTENT = 0x0000000000000002ULL,
120 /* OI scrub is triggered automatically. */
121 SF_AUTO = 0x0000000000000004ULL,
123 /* The device is upgraded from 1.8 format. */
124 SF_UPGRADE = 0x0000000000000008ULL,
128 /* Exit when fail. */
131 /* Check only without repairing. */
136 /* Set failout flag. */
137 SS_SET_FAILOUT = 0x00000001,
139 /* Clear failout flag. */
140 SS_CLEAR_FAILOUT = 0x00000002,
142 /* Reset scrub start position. */
143 SS_RESET = 0x00000004,
145 /* Trigger full scrub automatically. */
146 SS_AUTO_FULL = 0x00000008,
148 /* Trigger partial scrub automatically. */
149 SS_AUTO_PARTIAL = 0x00000010,
151 /* Set dryrun flag. */
152 SS_SET_DRYRUN = 0x00000020,
154 /* Clear dryrun flag. */
155 SS_CLEAR_DRYRUN = 0x00000040,
159 OLF_SCAN_SUBITEMS = 0x0001,
160 OLF_HIDE_FID = 0x0002,
161 OLF_SHOW_NAME = 0x0004,
163 OLF_IDX_IN_FID = 0x0010,
167 /* 128-bit uuid for volume. */
170 /* See 'enum scrub_flags'. */
173 /* The scrub magic. */
176 /* See 'enum scrub_status'. */
179 /* See 'enum scrub_param'. */
182 /* The time for the last OI scrub completed. */
183 __u64 sf_time_last_complete;
185 /* The time for the latest OI scrub ran. */
186 __u64 sf_time_latest_start;
188 /* The time for the last OI scrub checkpoint. */
189 __u64 sf_time_last_checkpoint;
191 /* The position for the latest OI scrub started from. */
192 __u64 sf_pos_latest_start;
194 /* The position for the last OI scrub checkpoint. */
195 __u64 sf_pos_last_checkpoint;
197 /* The position for the first should be updated object. */
198 __u64 sf_pos_first_inconsistent;
200 /* How many objects have been checked. */
201 __u64 sf_items_checked;
203 /* How many objects have been updated. */
204 __u64 sf_items_updated;
206 /* How many objects failed to be processed. */
207 __u64 sf_items_failed;
209 /* How many prior objects have been updated during scanning. */
210 __u64 sf_items_updated_prior;
212 /* How many objects marked as LDISKFS_STATE_LUSTRE_NOSCRUB. */
213 __u64 sf_items_noscrub;
215 /* How many IGIF objects. */
218 /* How long the OI scrub has run. */
221 /* How many completed OI scrub ran on the device. */
222 __u32 sf_success_count;
224 /* How many OI files. */
227 /* Keep the flags after scrub reset. See 'enum scrub_internal_flags' */
228 __u16 sf_internal_flags;
231 __u64 sf_reserved_2[16];
233 /* Bitmap for OI files recreated case. */
234 __u8 sf_oi_bitmap[SCRUB_OI_BITMAP_SIZE];
237 struct lustre_scrub {
238 struct lu_object_header os_obj_header;
239 /* Object for the scrub file. */
240 struct dt_object *os_obj;
242 struct ptlrpc_thread os_thread;
243 struct list_head os_inconsistent_items;
245 /* write lock for scrub prep/update/post/checkpoint,
246 * read lock for scrub dump. */
247 struct rw_semaphore os_rwsem;
250 /* Scrub file in memory. */
251 struct scrub_file os_file;
253 /* Buffer for scrub file load/store. */
254 struct scrub_file os_file_disk;
258 /* The time for last checkpoint, jiffies */
259 cfs_time_t os_time_last_checkpoint;
261 /* The time for next checkpoint, jiffies */
262 cfs_time_t os_time_next_checkpoint;
264 /* How many objects have been checked since last checkpoint. */
265 __u64 os_new_checked;
266 __u64 os_pos_current;
267 __u32 os_start_flags;
268 unsigned int os_in_prior:1, /* process inconsistent item
269 * found by RPC prior */
270 os_waiting:1, /* Waiting for scan window. */
271 os_full_speed:1, /* run w/o speed limit */
272 os_paused:1, /* The scrub is paused. */
279 void scrub_file_init(struct lustre_scrub *scrub, __u8 *uuid);
280 void scrub_file_reset(struct lustre_scrub *scrub, __u8 *uuid, __u64 flags);
281 int scrub_file_load(const struct lu_env *env, struct lustre_scrub *scrub);
282 int scrub_file_store(const struct lu_env *env, struct lustre_scrub *scrub);
283 int scrub_checkpoint(const struct lu_env *env, struct lustre_scrub *scrub);
284 int scrub_start(int (*threadfn)(void *data), struct lustre_scrub *scrub,
285 void *data, __u32 flags);
286 void scrub_stop(struct lustre_scrub *scrub);
287 void scrub_dump(struct seq_file *m, struct lustre_scrub *scrub);
289 static inline const char *osd_scrub2name(struct lustre_scrub *scrub)
291 return scrub->os_name;
293 #endif /* _LUSTRE_SCRUB_H */