Whamcloud - gitweb
LU-8288 lfsck: handle dangling LOV EA reference
[fs/lustre-release.git] / lustre / include / lustre / lustre_lfsck_user.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, 2016, Intel Corporation.
24  */
25 /*
26  * lustre/include/lustre/lustre_lfsck_user.h
27  *
28  * Lustre LFSCK userspace interfaces.
29  *
30  * Author: Fan, Yong <fan.yong@intel.com>
31  */
32
33 #ifndef _LUSTRE_LFSCK_USER_H
34 # define _LUSTRE_LFSCK_USER_H
35 # include <lustre/lustre_user.h>
36
37 /**
38  * state machine:
39  *
40  *                                      LS_INIT
41  *                                         |
42  *                                   (lfsck|start)
43  *                                         |
44  *                                         v
45  *                                 LS_SCANNING_PHASE1
46  *                                      |       ^
47  *                                      |       :
48  *                                      | (lfsck:restart)
49  *                                      |       :
50  *                                      v       :
51  *      -----------------------------------------------------------------
52  *      |                   |^          |^         |^         |^        |^
53  *      |                   |:          |:         |:         |:        |:
54  *      v                   v:          v:         v:         v:        v:
55  * LS_SCANNING_PHASE2   LS_FAILED  LS_STOPPED  LS_PAUSED LS_CRASHED LS_PARTIAL
56  *                        (CO_)       (CO_)      (CO_)
57  *      |       ^           ^:          ^:         ^:         ^:        ^:
58  *      |       :           |:          |:         |:         |:        |:
59  *      | (lfsck:restart)   |:          |:         |:         |:        |:
60  *      v       :           |v          |v         |v         |v        |v
61  *      -----------------------------------------------------------------
62  *          |
63  *          v
64  *    LS_COMPLETED
65  */
66 enum lfsck_status {
67         /* The lfsck file is new created, for new MDT, upgrading from old disk,
68          * or re-creating the lfsck file manually. */
69         LS_INIT                 = 0,
70
71         /* The first-step system scanning. The checked items during the phase1
72          * scanning depends on the LFSCK type. */
73         LS_SCANNING_PHASE1      = 1,
74
75         /* The second-step system scanning. The checked items during the phase2
76          * scanning depends on the LFSCK type. */
77         LS_SCANNING_PHASE2      = 2,
78
79         /* The LFSCK processing has completed for all objects. */
80         LS_COMPLETED            = 3,
81
82         /* The LFSCK exited automatically for failure, will not auto restart. */
83         LS_FAILED               = 4,
84
85         /* The LFSCK is stopped manually, will not auto restart. */
86         LS_STOPPED              = 5,
87
88         /* LFSCK is paused automatically when umount,
89          * will be restarted automatically when remount. */
90         LS_PAUSED               = 6,
91
92         /* System crashed during the LFSCK,
93          * will be restarted automatically after recovery. */
94         LS_CRASHED              = 7,
95
96         /* Some OST/MDT failed during the LFSCK, or not join the LFSCK. */
97         LS_PARTIAL              = 8,
98
99         /* The LFSCK is failed because its controller is failed. */
100         LS_CO_FAILED            = 9,
101
102         /* The LFSCK is stopped because its controller is stopped. */
103         LS_CO_STOPPED           = 10,
104
105         /* The LFSCK is paused because its controller is paused. */
106         LS_CO_PAUSED            = 11,
107
108         LS_MAX
109 };
110
111 static inline const char *lfsck_status2name(int status)
112 {
113         static const char * const lfsck_status_names[] = {
114                 [LS_INIT]               = "init",
115                 [LS_SCANNING_PHASE1]    = "scanning-phase1",
116                 [LS_SCANNING_PHASE2]    = "scanning-phase2",
117                 [LS_COMPLETED]          = "completed",
118                 [LS_FAILED]             = "failed",
119                 [LS_STOPPED]            = "stopped",
120                 [LS_PAUSED]             = "paused",
121                 [LS_CRASHED]            = "crashed",
122                 [LS_PARTIAL]            = "partial",
123                 [LS_CO_FAILED]          = "co-failed",
124                 [LS_CO_STOPPED]         = "co-stopped",
125                 [LS_CO_PAUSED]          = "co-paused"
126         };
127
128         if (status < 0 || status >= LS_MAX)
129                 return "unknown";
130
131         return lfsck_status_names[status];
132 }
133
134 enum lfsck_param_flags {
135         /* Reset LFSCK iterator position to the device beginning. */
136         LPF_RESET               = 0x0001,
137
138         /* Exit when fail. */
139         LPF_FAILOUT             = 0x0002,
140
141         /* Dryrun mode, only check without modification */
142         LPF_DRYRUN              = 0x0004,
143
144         /* LFSCK runs on all targets. */
145         LPF_ALL_TGT             = 0x0008,
146
147         /* Broadcast the command to other MDTs. Only valid on the sponsor MDT */
148         LPF_BROADCAST           = 0x0010,
149
150         /* Handle orphan OST-objects. */
151         LPF_OST_ORPHAN          = 0x0020,
152
153         /* Create OST-object for dangling LOV EA. */
154         LPF_CREATE_OSTOBJ       = 0x0040,
155
156         /* Create MDT-object for dangling name entry. */
157         LPF_CREATE_MDTOBJ       = 0x0080,
158
159         /* Do not return until the LFSCK not running. */
160         LPF_WAIT                = 0x0100,
161
162         /* Delay to create OST-object for dangling LOV EA. */
163         LPF_DELAY_CREATE_OSTOBJ = 0x0200,
164 };
165
166 enum lfsck_type {
167         /* For MDT and OST internal OSD consistency check/repair. */
168         LFSCK_TYPE_SCRUB        = 0x0000,
169
170         /* For MDT-OST (layout, object) consistency check/repair. */
171         LFSCK_TYPE_LAYOUT       = 0x0001,
172
173         /* For MDT (FID-in-dirent, linkEA) consistency check/repair. */
174         LFSCK_TYPE_NAMESPACE    = 0x0004,
175         LFSCK_TYPES_SUPPORTED   = (LFSCK_TYPE_SCRUB | LFSCK_TYPE_LAYOUT |
176                                    LFSCK_TYPE_NAMESPACE),
177         LFSCK_TYPES_DEF         = LFSCK_TYPES_SUPPORTED,
178         LFSCK_TYPES_ALL         = ((__u16)(~0))
179 };
180
181 #define LFSCK_VERSION_V1        1
182 #define LFSCK_VERSION_V2        2
183
184 #define LFSCK_SPEED_NO_LIMIT    0
185 #define LFSCK_SPEED_LIMIT_DEF   LFSCK_SPEED_NO_LIMIT
186 #define LFSCK_ASYNC_WIN_DEFAULT 1024
187 #define LFSCK_ASYNC_WIN_MAX     ((__u16)(~0))
188 #define LFSCK_TYPE_BITS         16
189
190 enum lfsck_start_valid {
191         LSV_SPEED_LIMIT         = 0x00000001,
192         LSV_ERROR_HANDLE        = 0x00000002,
193         LSV_DRYRUN              = 0x00000004,
194         LSV_ASYNC_WINDOWS       = 0x00000008,
195         LSV_CREATE_OSTOBJ       = 0x00000010,
196         LSV_CREATE_MDTOBJ       = 0x00000020,
197         LSV_DELAY_CREATE_OSTOBJ = 0x00000040,
198 };
199
200 /* Arguments for starting lfsck. */
201 struct lfsck_start {
202         /* Which arguments are valid, see 'enum lfsck_start_valid'. */
203         __u32   ls_valid;
204
205         /* How many items can be scanned at most per second. */
206         __u32   ls_speed_limit;
207
208         /* For compatibility between user space tools and kernel service. */
209         __u16   ls_version;
210
211         /* Which LFSCK components to be (have been) started. */
212         __u16   ls_active;
213
214         /* Flags for the LFSCK, see 'enum lfsck_param_flags'. */
215         __u16   ls_flags;
216
217         /* The windows size for async requests pipeline. */
218         __u16   ls_async_windows;
219 };
220
221 struct lfsck_stop {
222         __u32   ls_status;
223         __u16   ls_flags;
224         __u16   ls_padding_1; /* For 64-bits aligned. */
225         __u64   ls_padding_2;
226 };
227
228 struct lfsck_query {
229         __u16   lu_types;
230         __u16   lu_flags;
231         __u32   lu_mdts_count[LFSCK_TYPE_BITS][LS_MAX + 1];
232         __u32   lu_osts_count[LFSCK_TYPE_BITS][LS_MAX + 1];
233         __u64   lu_repaired[LFSCK_TYPE_BITS];
234 };
235
236 #endif /* _LUSTRE_LFSCK_USER_H */