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