Whamcloud - gitweb
LU-7268 scrub: NOT assign LMA for EA inode
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_scrub.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, 2014, Intel Corporation.
24  */
25 /*
26  * lustre/osd-ldiskfs/osd_scrub.h
27  *
28  * Shared definitions and declarations for OI scrub.
29  *
30  * Author: Fan Yong <yong.fan@whamcloud.com>
31  */
32
33 #ifndef _OSD_SCRUB_H
34 # define _OSD_SCRUB_H
35
36 #include "osd_oi.h"
37
38 #define SCRUB_MAGIC_V1                  0x4C5FD252
39 #define SCRUB_CHECKPOINT_INTERVAL       60
40 #define SCRUB_OI_BITMAP_SIZE            (OSD_OI_FID_NR_MAX >> 3)
41 #define SCRUB_WINDOW_SIZE               1024
42
43 enum scrub_status {
44         /* The scrub file is new created, for new MDT, upgrading from old disk,
45          * or re-creating the scrub file manually. */
46         SS_INIT         = 0,
47
48         /* The scrub is checking/repairing the OI files. */
49         SS_SCANNING     = 1,
50
51         /* The scrub checked/repaired the OI files successfully. */
52         SS_COMPLETED    = 2,
53
54         /* The scrub failed to check/repair the OI files. */
55         SS_FAILED       = 3,
56
57         /* The scrub is stopped manually, the OI files may be inconsistent. */
58         SS_STOPPED      = 4,
59
60         /* The scrub is paused automatically when umount. */
61         SS_PAUSED       = 5,
62
63         /* The scrub crashed during the scanning, should be restarted. */
64         SS_CRASHED      = 6,
65 };
66
67 enum scrub_flags {
68         /* OI files have been recreated, OI mappings should be re-inserted. */
69         SF_RECREATED    = 0x0000000000000001ULL,
70
71         /* OI files are invalid, should be rebuild ASAP */
72         SF_INCONSISTENT = 0x0000000000000002ULL,
73
74         /* OI scrub is triggered automatically. */
75         SF_AUTO         = 0x0000000000000004ULL,
76
77         /* The device is upgraded from 1.8 format. */
78         SF_UPGRADE      = 0x0000000000000008ULL,
79 };
80
81 enum scrub_param {
82         /* Exit when fail. */
83         SP_FAILOUT      = 0x0001,
84
85         /* Check only without repairing. */
86         SP_DRYRUN       = 0x0002,
87 };
88
89 enum scrub_start {
90         /* Set failout flag. */
91         SS_SET_FAILOUT          = 0x00000001,
92
93         /* Clear failout flag. */
94         SS_CLEAR_FAILOUT        = 0x00000002,
95
96         /* Reset scrub start position. */
97         SS_RESET                = 0x00000004,
98
99         /* Trigger full scrub automatically. */
100         SS_AUTO_FULL            = 0x00000008,
101
102         /* Trigger partial scrub automatically. */
103         SS_AUTO_PARTIAL         = 0x00000010,
104
105         /* Set dryrun flag. */
106         SS_SET_DRYRUN           = 0x00000020,
107
108         /* Clear dryrun flag. */
109         SS_CLEAR_DRYRUN         = 0x00000040,
110 };
111
112 /* The flags here are only used inside OSD, NOT be visible by dump(). */
113 enum scrub_internal_flags {
114         /* This is a new formatted device. */
115         SIF_NO_HANDLE_OLD_FID   = 0x0001,
116 };
117
118 struct scrub_file {
119         /* 128-bit uuid for volume. */
120         __u8    sf_uuid[16];
121
122         /* See 'enum scrub_flags'. */
123         __u64   sf_flags;
124
125         /* The scrub magic. */
126         __u32   sf_magic;
127
128         /* See 'enum scrub_status'. */
129         __u16   sf_status;
130
131         /* See 'enum scrub_param'. */
132         __u16   sf_param;
133
134         /* The time for the last OI scrub completed. */
135         __u64   sf_time_last_complete;
136
137         /* The time for the latest OI scrub ran. */
138         __u64   sf_time_latest_start;
139
140         /* The time for the last OI scrub checkpoint. */
141         __u64   sf_time_last_checkpoint;
142
143         /* The position for the latest OI scrub started from. */
144         __u64   sf_pos_latest_start;
145
146         /* The position for the last OI scrub checkpoint. */
147         __u64   sf_pos_last_checkpoint;
148
149         /* The position for the first should be updated object. */
150         __u64   sf_pos_first_inconsistent;
151
152         /* How many objects have been checked. */
153         __u64   sf_items_checked;
154
155         /* How many objects have been updated. */
156         __u64   sf_items_updated;
157
158         /* How many objects failed to be processed. */
159         __u64   sf_items_failed;
160
161         /* How many prior objects have been updated during scanning. */
162         __u64   sf_items_updated_prior;
163
164         /* How many objects marked as LDISKFS_STATE_LUSTRE_NOSCRUB. */
165         __u64   sf_items_noscrub;
166
167         /* How many IGIF objects. */
168         __u64   sf_items_igif;
169
170         /* How long the OI scrub has run. */
171         __u32   sf_run_time;
172
173         /* How many completed OI scrub ran on the device. */
174         __u32   sf_success_count;
175
176         /* How many OI files. */
177         __u16   sf_oi_count;
178
179         /* Keep the flags after scrub reset. See 'enum scrub_internal_flags' */
180         __u16   sf_internal_flags;
181
182         __u32   sf_reserved_1;
183         __u64   sf_reserved_2[16];
184
185         /* Bitmap for OI files recreated case. */
186         __u8    sf_oi_bitmap[SCRUB_OI_BITMAP_SIZE];
187 };
188
189 struct osd_scrub {
190         struct lvfs_run_ctxt    os_ctxt;
191         struct ptlrpc_thread    os_thread;
192         struct osd_idmap_cache  os_oic;
193         struct list_head        os_inconsistent_items;
194
195         /* write lock for scrub prep/update/post/checkpoint,
196          * read lock for scrub dump. */
197         struct rw_semaphore     os_rwsem;
198         spinlock_t              os_lock;
199
200         /* Scrub file in memory. */
201         struct scrub_file       os_file;
202
203         /* Buffer for scrub file load/store. */
204         struct scrub_file       os_file_disk;
205
206         /* Inode for the scrub file. */
207         struct inode           *os_inode;
208
209         /* The time for last checkpoint, jiffies */
210         cfs_time_t              os_time_last_checkpoint;
211
212         /* The time for next checkpoint, jiffies */
213         cfs_time_t              os_time_next_checkpoint;
214
215         /* statistics for /lost+found are in ram only, it will be reset
216          * when each time the device remount. */
217
218         /* How many objects have been scanned during initial OI scrub. */
219         __u64                   os_lf_scanned;
220         /* How many objects have been repaired during initial OI scrub. */
221         __u64                   os_lf_repaired;
222         /* How many objects failed to be processed during initial OI scrub. */
223         __u64                   os_lf_failed;
224
225         /* How many objects have been checked since last checkpoint. */
226         __u32                   os_new_checked;
227         __u32                   os_pos_current;
228         __u32                   os_start_flags;
229         unsigned int            os_in_prior:1, /* process inconsistent item
230                                                 * found by RPC prior */
231                                 os_waiting:1, /* Waiting for scan window. */
232                                 os_full_speed:1, /* run w/o speed limit */
233                                 os_paused:1, /* The scrub is paused. */
234                                 os_convert_igif:1,
235                                 os_partial_scan:1,
236                                 os_in_join:1,
237                                 os_full_scrub:1;
238         __u64                   os_bad_oimap_count;
239         __u64                   os_bad_oimap_time;
240 };
241
242 #endif /* _OSD_SCRUB_H */