Whamcloud - gitweb
LU-6142 misc: Fix style issues for files under lustre/include/
[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 <linux/uuid.h>
37 #include <dt_object.h>
38 #include <lustre_net.h>
39 #include <uapi/linux/lustre/lustre_disk.h>
40
41 #define SCRUB_CHECKPOINT_INTERVAL       60
42 #define SCRUB_WINDOW_SIZE               1024
43
44 enum scrub_next_status {
45         /* exit current loop and process next group */
46         SCRUB_NEXT_BREAK        = 1,
47
48         /* skip current object and process next bit */
49         SCRUB_NEXT_CONTINUE     = 2,
50
51         /* exit all the loops */
52         SCRUB_NEXT_EXIT         = 3,
53
54         /* wait for free cache slot */
55         SCRUB_NEXT_WAIT         = 4,
56
57         /* simulate system crash during OI scrub */
58         SCRUB_NEXT_CRASH        = 5,
59
60         /* simulate failure during OI scrub */
61         SCRUB_NEXT_FATAL        = 6,
62
63         /* new created object, no scrub on it */
64         SCRUB_NEXT_NOSCRUB      = 7,
65
66         /* the object has no FID-in-LMA */
67         SCRUB_NEXT_NOLMA        = 8,
68
69         /* for OST-object */
70         SCRUB_NEXT_OSTOBJ       = 9,
71
72         /* old OST-object, no LMA or no FID-on-OST flags in LMA */
73         SCRUB_NEXT_OSTOBJ_OLD   = 10,
74 };
75
76 enum scrub_local_file_flags {
77         SLFF_SCAN_SUBITEMS      = 0x0001,
78         SLFF_HIDE_FID           = 0x0002,
79         SLFF_SHOW_NAME          = 0x0004,
80         SLFF_NO_OI              = 0x0008,
81         SLFF_IDX_IN_FID         = 0x0010,
82 };
83
84 enum scrub_start {
85         /* Set failout flag. */
86         SS_SET_FAILOUT          = 0x00000001,
87
88         /* Clear failout flag. */
89         SS_CLEAR_FAILOUT        = 0x00000002,
90
91         /* Reset scrub start position. */
92         SS_RESET                = 0x00000004,
93
94         /* Trigger full scrub automatically. */
95         SS_AUTO_FULL            = 0x00000008,
96
97         /* Trigger partial scrub automatically. */
98         SS_AUTO_PARTIAL         = 0x00000010,
99
100         /* Set dryrun flag. */
101         SS_SET_DRYRUN           = 0x00000020,
102
103         /* Clear dryrun flag. */
104         SS_CLEAR_DRYRUN         = 0x00000040,
105 };
106
107 enum osd_lf_flags {
108         OLF_SCAN_SUBITEMS       = 0x0001,
109         OLF_HIDE_FID            = 0x0002,
110         OLF_SHOW_NAME           = 0x0004,
111         OLF_NO_OI               = 0x0008,
112         OLF_IDX_IN_FID          = 0x0010,
113         OLF_NOT_BACKUP          = 0x0020,
114 };
115
116 /* There are some overhead to detect OI inconsistency automatically
117  * during normal RPC handling. We do not want to always auto detect
118  * OI inconsistency especailly when OI scrub just done recently.
119  *
120  * The 'auto_scrub' defines the time (united as second) interval to
121  * enable auto detect OI inconsistency since last OI scurb done.
122  */
123 enum auto_scrub {
124         /* Disable auto scrub. */
125         AS_NEVER        = 0,
126
127         /* 1 second is too short interval, it is almost equal to always auto
128          * detect inconsistent OI, usually used for test.
129          */
130         AS_ALWAYS       = 1,
131
132         /* Enable auto detect OI inconsistency one month (60 * 60 * 24 * 30)
133          * after last OI scrub.
134          */
135         AS_DEFAULT      = 2592000LL,
136 };
137
138 struct lustre_scrub {
139         /* Object for the scrub file. */
140         struct dt_object       *os_obj;
141
142         struct task_struct     *os_task;
143         struct list_head        os_inconsistent_items;
144         /* once inconsistent mapping can't be fixed, put into this list */
145         struct list_head        os_stale_items;
146
147         /* write lock for scrub prep/update/post/checkpoint,
148          * read lock for scrub dump.
149          */
150         struct rw_semaphore     os_rwsem;
151         spinlock_t              os_lock;
152
153         /* Scrub file in memory. */
154         struct scrub_file       os_file;
155
156         /* Buffer for scrub file load/store. */
157         struct scrub_file       os_file_disk;
158
159         const char             *os_name;
160
161         /* The time for last checkpoint, seconds */
162         time64_t                os_time_last_checkpoint;
163
164         /* The time for next checkpoint, seconds */
165         time64_t                os_time_next_checkpoint;
166
167         /* How long to wait to start scrubbing */
168         time64_t                os_auto_scrub_interval;
169
170         /* How many objects have been checked since last checkpoint. */
171         __u64                   os_new_checked;
172         __u64                   os_pos_current;
173         __u32                   os_start_flags;
174         /* Some of these bits can be set by different threads so
175          * all updates must be protected by ->os_lock to avoid
176          * racing read-modify-write cycles causing corruption.
177          */
178         /* process inconsistent item found by RPC prior */
179         unsigned int            os_in_prior:1,
180                                 os_waiting:1, /* Waiting for scan window. */
181                                 os_full_speed:1, /* run w/o speed limit */
182                                 os_paused:1, /* The scrub is paused. */
183                                 os_convert_igif:1,
184                                 os_partial_scan:1,
185                                 os_in_join:1,
186                                 os_running:1,   /* scrub thread is running */
187                                 os_full_scrub:1,
188                                 os_has_ml_file:1;
189 };
190
191 #define INDEX_BACKUP_MAGIC_V1   0x1E41F208
192 #define INDEX_BACKUP_BUFSIZE    (4096 * 4)
193
194 enum lustre_index_backup_policy {
195         /* By default, do not backup the index */
196         LIBP_NONE       = 0,
197
198         /* Backup the dirty index objects when umount */
199         LIBP_AUTO       = 1,
200 };
201
202 struct lustre_index_backup_header {
203         __u32           libh_magic;
204         __u32           libh_count;
205         __u32           libh_keysize;
206         __u32           libh_recsize;
207         struct lu_fid   libh_owner;
208         __u64           libh_pad[60]; /* keep header 512 bytes aligned */
209 };
210
211 struct lustre_index_backup_unit {
212         struct list_head        libu_link;
213         struct lu_fid           libu_fid;
214         __u32                   libu_keysize;
215         __u32                   libu_recsize;
216 };
217
218 struct lustre_index_restore_unit {
219         struct list_head        liru_link;
220         struct lu_fid           liru_pfid;
221         struct lu_fid           liru_cfid;
222         __u64                   liru_clid;
223         int                     liru_len;
224         char                    liru_name[0];
225 };
226
227 void scrub_file_init(struct lustre_scrub *scrub, guid_t uuid);
228 void scrub_file_reset(struct lustre_scrub *scrub, guid_t uuid, u64 flags);
229 int scrub_file_load(const struct lu_env *env, struct lustre_scrub *scrub);
230 int scrub_file_store(const struct lu_env *env, struct lustre_scrub *scrub);
231 bool scrub_needs_check(struct lustre_scrub *scrub, const struct lu_fid *fid,
232                        u64 index);
233 int scrub_checkpoint(const struct lu_env *env, struct lustre_scrub *scrub);
234 int scrub_thread_prep(const struct lu_env *env, struct lustre_scrub *scrub,
235                       guid_t uuid, u64 start);
236 int scrub_thread_post(const struct lu_env *env, struct lustre_scrub *scrub,
237                       int result);
238 int scrub_start(int (*threadfn)(void *data), struct lustre_scrub *scrub,
239                 void *data, __u32 flags);
240 void scrub_stop(struct lustre_scrub *scrub);
241 void scrub_dump(struct seq_file *m, struct lustre_scrub *scrub);
242
243 int lustre_liru_new(struct list_head *head, const struct lu_fid *pfid,
244                     const struct lu_fid *cfid, __u64 child,
245                     const char *name, int namelen);
246
247 int lustre_index_register(struct dt_device *dev, const char *devname,
248                           struct list_head *head, spinlock_t *lock, int *guard,
249                           const struct lu_fid *fid,
250                           __u32 keysize, __u32 recsize);
251
252 void lustre_index_backup(const struct lu_env *env, struct dt_device *dev,
253                          const char *devname, struct list_head *head,
254                          spinlock_t *lock, int *guard, bool backup);
255 int lustre_index_restore(const struct lu_env *env, struct dt_device *dev,
256                          const struct lu_fid *parent_fid,
257                          const struct lu_fid *tgt_fid,
258                          const struct lu_fid *bak_fid, const char *name,
259                          struct list_head *head, spinlock_t *lock,
260                          char *buf, int bufsize);
261
262 static inline void lustre_fid2lbx(char *buf, const struct lu_fid *fid, int len)
263 {
264         snprintf(buf, len, DFID_NOBRACE".lbx", PFID(fid));
265 }
266
267 static inline const char *osd_scrub2name(struct lustre_scrub *scrub)
268 {
269         return scrub->os_name;
270 }
271 #endif /* _LUSTRE_SCRUB_H */