Whamcloud - gitweb
LU-8955 nodemap: add SELinux policy info to nodemap
[fs/lustre-release.git] / lustre / include / lustre_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, 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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2017, Intel Corporation.
24  */
25 /*
26  * lustre/include/lustre_scrub.h
27  *
28  * Shared definitions and declarations for Lustre OI scrub.
29  *
30  * Author: Fan Yong <fan.yong@intel.com>
31  */
32
33 #ifndef _LUSTRE_SCRUB_H
34 # define _LUSTRE_SCRUB_H
35
36 #include <dt_object.h>
37 #include <lustre_net.h>
38
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)
42 #define PFID_STRIPE_IDX_BITS    16
43 #define PFID_STRIPE_COUNT_MASK  ((1 << PFID_STRIPE_IDX_BITS) - 1)
44
45 #define SCRUB_MAGIC_V1                  0x4C5FD252
46 #define SCRUB_CHECKPOINT_INTERVAL       60
47 #define SCRUB_WINDOW_SIZE               1024
48
49 enum scrub_next_status {
50         /* exit current loop and process next group */
51         SCRUB_NEXT_BREAK        = 1,
52
53         /* skip current object and process next bit */
54         SCRUB_NEXT_CONTINUE     = 2,
55
56         /* exit all the loops */
57         SCRUB_NEXT_EXIT         = 3,
58
59         /* wait for free cache slot */
60         SCRUB_NEXT_WAIT         = 4,
61
62         /* simulate system crash during OI scrub */
63         SCRUB_NEXT_CRASH        = 5,
64
65         /* simulate failure during OI scrub */
66         SCRUB_NEXT_FATAL        = 6,
67
68         /* new created object, no scrub on it */
69         SCRUB_NEXT_NOSCRUB      = 7,
70
71         /* the object has no FID-in-LMA */
72         SCRUB_NEXT_NOLMA        = 8,
73
74         /* for OST-object */
75         SCRUB_NEXT_OSTOBJ       = 9,
76
77         /* old OST-object, no LMA or no FID-on-OST flags in LMA */
78         SCRUB_NEXT_OSTOBJ_OLD   = 10,
79 };
80
81 enum scrub_local_file_flags {
82         SLFF_SCAN_SUBITEMS      = 0x0001,
83         SLFF_HIDE_FID           = 0x0002,
84         SLFF_SHOW_NAME          = 0x0004,
85         SLFF_NO_OI              = 0x0008,
86         SLFF_IDX_IN_FID         = 0x0010,
87 };
88
89 enum scrub_status {
90         /* The scrub file is new created, for new MDT, upgrading from old disk,
91          * or re-creating the scrub file manually. */
92         SS_INIT         = 0,
93
94         /* The scrub is checking/repairing the OI files. */
95         SS_SCANNING     = 1,
96
97         /* The scrub checked/repaired the OI files successfully. */
98         SS_COMPLETED    = 2,
99
100         /* The scrub failed to check/repair the OI files. */
101         SS_FAILED       = 3,
102
103         /* The scrub is stopped manually, the OI files may be inconsistent. */
104         SS_STOPPED      = 4,
105
106         /* The scrub is paused automatically when umount. */
107         SS_PAUSED       = 5,
108
109         /* The scrub crashed during the scanning, should be restarted. */
110         SS_CRASHED      = 6,
111 };
112
113 enum scrub_flags {
114         /* OI files have been recreated, OI mappings should be re-inserted. */
115         SF_RECREATED    = 0x0000000000000001ULL,
116
117         /* OI files are invalid, should be rebuild ASAP */
118         SF_INCONSISTENT = 0x0000000000000002ULL,
119
120         /* OI scrub is triggered automatically. */
121         SF_AUTO         = 0x0000000000000004ULL,
122
123         /* The device is upgraded from 1.8 format. */
124         SF_UPGRADE      = 0x0000000000000008ULL,
125 };
126
127 enum scrub_param {
128         /* Exit when fail. */
129         SP_FAILOUT      = 0x0001,
130
131         /* Check only without repairing. */
132         SP_DRYRUN       = 0x0002,
133 };
134
135 enum scrub_start {
136         /* Set failout flag. */
137         SS_SET_FAILOUT          = 0x00000001,
138
139         /* Clear failout flag. */
140         SS_CLEAR_FAILOUT        = 0x00000002,
141
142         /* Reset scrub start position. */
143         SS_RESET                = 0x00000004,
144
145         /* Trigger full scrub automatically. */
146         SS_AUTO_FULL            = 0x00000008,
147
148         /* Trigger partial scrub automatically. */
149         SS_AUTO_PARTIAL         = 0x00000010,
150
151         /* Set dryrun flag. */
152         SS_SET_DRYRUN           = 0x00000020,
153
154         /* Clear dryrun flag. */
155         SS_CLEAR_DRYRUN         = 0x00000040,
156 };
157
158 enum osd_lf_flags {
159         OLF_SCAN_SUBITEMS       = 0x0001,
160         OLF_HIDE_FID            = 0x0002,
161         OLF_SHOW_NAME           = 0x0004,
162         OLF_NO_OI               = 0x0008,
163         OLF_IDX_IN_FID          = 0x0010,
164         OLF_NOT_BACKUP          = 0x0020,
165 };
166
167 /* There are some overhead to detect OI inconsistency automatically
168  * during normal RPC handling. We do not want to always auto detect
169  * OI inconsistency especailly when OI scrub just done recently.
170  *
171  * The 'auto_scrub' defines the time (united as second) interval to
172  * enable auto detect OI inconsistency since last OI scurb done. */
173 enum auto_scrub {
174         /* Disable auto scrub. */
175         AS_NEVER        = 0,
176
177         /* 1 second is too short interval, it is almost equal to always auto
178          * detect inconsistent OI, usually used for test. */
179         AS_ALWAYS       = 1,
180
181         /* Enable auto detect OI inconsistency one month (60 * 60 * 24 * 30)
182          * after last OI scrub. */
183         AS_DEFAULT      = 2592000LL,
184 };
185
186 struct scrub_file {
187         /* 128-bit uuid for volume. */
188         __u8    sf_uuid[16];
189
190         /* See 'enum scrub_flags'. */
191         __u64   sf_flags;
192
193         /* The scrub magic. */
194         __u32   sf_magic;
195
196         /* See 'enum scrub_status'. */
197         __u16   sf_status;
198
199         /* See 'enum scrub_param'. */
200         __u16   sf_param;
201
202         /* The time for the last OI scrub completed. */
203         time64_t sf_time_last_complete;
204
205         /* The ttime for the latest OI scrub ran. */
206         time64_t sf_time_latest_start;
207
208         /* The time for the last OI scrub checkpoint. */
209         time64_t sf_time_last_checkpoint;
210
211         /* The position for the latest OI scrub started from. */
212         __u64   sf_pos_latest_start;
213
214         /* The position for the last OI scrub checkpoint. */
215         __u64   sf_pos_last_checkpoint;
216
217         /* The position for the first should be updated object. */
218         __u64   sf_pos_first_inconsistent;
219
220         /* How many objects have been checked. */
221         __u64   sf_items_checked;
222
223         /* How many objects have been updated. */
224         __u64   sf_items_updated;
225
226         /* How many objects failed to be processed. */
227         __u64   sf_items_failed;
228
229         /* How many prior objects have been updated during scanning. */
230         __u64   sf_items_updated_prior;
231
232         /* How many objects marked as LDISKFS_STATE_LUSTRE_NOSCRUB. */
233         __u64   sf_items_noscrub;
234
235         /* How many IGIF objects. */
236         __u64   sf_items_igif;
237
238         /* How long the OI scrub has run in seconds. Do NOT change
239          * to time64_t since this breaks backwards compatibility.
240          * It shouldn't take more than 136 years to complete :-)
241          */
242         time_t  sf_run_time;
243
244         /* How many completed OI scrub ran on the device. */
245         __u32   sf_success_count;
246
247         /* How many OI files. */
248         __u16   sf_oi_count;
249
250         /* Keep the flags after scrub reset. See 'enum scrub_internal_flags' */
251         __u16   sf_internal_flags;
252
253         __u32   sf_reserved_1;
254         __u64   sf_reserved_2[16];
255
256         /* Bitmap for OI files recreated case. */
257         __u8    sf_oi_bitmap[SCRUB_OI_BITMAP_SIZE];
258 };
259
260 struct lustre_scrub {
261         /* Object for the scrub file. */
262         struct dt_object       *os_obj;
263
264         struct ptlrpc_thread    os_thread;
265         struct list_head        os_inconsistent_items;
266
267         /* write lock for scrub prep/update/post/checkpoint,
268          * read lock for scrub dump. */
269         struct rw_semaphore     os_rwsem;
270         spinlock_t              os_lock;
271
272         /* Scrub file in memory. */
273         struct scrub_file       os_file;
274
275         /* Buffer for scrub file load/store. */
276         struct scrub_file       os_file_disk;
277
278         const char             *os_name;
279
280         /* The time for last checkpoint, seconds */
281         time64_t                os_time_last_checkpoint;
282
283         /* The time for next checkpoint, seconds */
284         time64_t                os_time_next_checkpoint;
285
286         /* How many objects have been checked since last checkpoint. */
287         __u64                   os_new_checked;
288         __u64                   os_pos_current;
289         __u32                   os_start_flags;
290         unsigned int            os_in_prior:1, /* process inconsistent item
291                                                 * found by RPC prior */
292                                 os_waiting:1, /* Waiting for scan window. */
293                                 os_full_speed:1, /* run w/o speed limit */
294                                 os_paused:1, /* The scrub is paused. */
295                                 os_convert_igif:1,
296                                 os_partial_scan:1,
297                                 os_in_join:1,
298                                 os_full_scrub:1;
299 };
300
301 #define INDEX_BACKUP_MAGIC_V1   0x1E41F208
302 #define INDEX_BACKUP_BUFSIZE    (4096 * 4)
303
304 enum lustre_index_backup_policy {
305         /* By default, do not backup the index */
306         LIBP_NONE       = 0,
307
308         /* Backup the dirty index objects when umount */
309         LIBP_AUTO       = 1,
310 };
311
312 struct lustre_index_backup_header {
313         __u32           libh_magic;
314         __u32           libh_count;
315         __u32           libh_keysize;
316         __u32           libh_recsize;
317         struct lu_fid   libh_owner;
318         __u64           libh_pad[60]; /* keep header 512 bytes aligned */
319 };
320
321 struct lustre_index_backup_unit {
322         struct list_head        libu_link;
323         struct lu_fid           libu_fid;
324         __u32                   libu_keysize;
325         __u32                   libu_recsize;
326 };
327
328 struct lustre_index_restore_unit {
329         struct list_head        liru_link;
330         struct lu_fid           liru_pfid;
331         struct lu_fid           liru_cfid;
332         __u64                   liru_clid;
333         int                     liru_len;
334         char                    liru_name[0];
335 };
336
337 void scrub_file_init(struct lustre_scrub *scrub, __u8 *uuid);
338 void scrub_file_reset(struct lustre_scrub *scrub, __u8 *uuid, __u64 flags);
339 int scrub_file_load(const struct lu_env *env, struct lustre_scrub *scrub);
340 int scrub_file_store(const struct lu_env *env, struct lustre_scrub *scrub);
341 int scrub_checkpoint(const struct lu_env *env, struct lustre_scrub *scrub);
342 int scrub_start(int (*threadfn)(void *data), struct lustre_scrub *scrub,
343                 void *data, __u32 flags);
344 void scrub_stop(struct lustre_scrub *scrub);
345 void scrub_dump(struct seq_file *m, struct lustre_scrub *scrub);
346
347 int lustre_liru_new(struct list_head *head, const struct lu_fid *pfid,
348                     const struct lu_fid *cfid, __u64 child,
349                     const char *name, int namelen);
350
351 int lustre_index_register(struct dt_device *dev, const char *devname,
352                           struct list_head *head, spinlock_t *lock, int *guard,
353                           const struct lu_fid *fid,
354                           __u32 keysize, __u32 recsize);
355
356 void lustre_index_backup(const struct lu_env *env, struct dt_device *dev,
357                          const char *devname, struct list_head *head,
358                          spinlock_t *lock, int *guard, bool backup);
359 int lustre_index_restore(const struct lu_env *env, struct dt_device *dev,
360                          const struct lu_fid *parent_fid,
361                          const struct lu_fid *tgt_fid,
362                          const struct lu_fid *bak_fid, const char *name,
363                          struct list_head *head, spinlock_t *lock,
364                          char *buf, int bufsize);
365
366 static inline void lustre_fid2lbx(char *buf, const struct lu_fid *fid, int len)
367 {
368         snprintf(buf, len, DFID_NOBRACE".lbx", PFID(fid));
369 }
370
371 static inline const char *osd_scrub2name(struct lustre_scrub *scrub)
372 {
373         return scrub->os_name;
374 }
375 #endif /* _LUSTRE_SCRUB_H */