Whamcloud - gitweb
e99234633de6cc0cb183015c7e5eb73eefe00d41
[fs/lustre-release.git] / lustre / include / lustre_lfsck.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) 2013, Intel Corporation.
24  */
25 /*
26  * lustre/include/lustre_lfsck.h
27  *
28  * Lustre LFSCK exported functions.
29  *
30  * Author: Fan, Yong <fan.yong@intel.com>
31  */
32
33 #ifndef _LUSTRE_LFSCK_H
34 # define _LUSTRE_LFSCK_H
35
36 #include <lustre/lustre_lfsck_user.h>
37 #include <lustre_dlm.h>
38 #include <lu_object.h>
39 #include <dt_object.h>
40
41 /**
42  * status machine:
43  *
44  *                                      LS_INIT
45  *                                         |
46  *                                   (lfsck|start)
47  *                                         |
48  *                                         v
49  *                                 LS_SCANNING_PHASE1
50  *                                      |       ^
51  *                                      |       :
52  *                                      | (lfsck:restart)
53  *                                      |       :
54  *                                      v       :
55  *      -----------------------------------------------------------------
56  *      |                   |^          |^         |^         |^        |^
57  *      |                   |:          |:         |:         |:        |:
58  *      v                   v:          v:         v:         v:        v:
59  * LS_SCANNING_PHASE2   LS_FAILED  LS_STOPPED  LS_PAUSED LS_CRASHED LS_PARTIAL
60  *                        (CO_)       (CO_)      (CO_)
61  *      |       ^           ^:          ^:         ^:         ^:        ^:
62  *      |       :           |:          |:         |:         |:        |:
63  *      | (lfsck:restart)   |:          |:         |:         |:        |:
64  *      v       :           |v          |v         |v         |v        |v
65  *      -----------------------------------------------------------------
66  *          |
67  *          v
68  *    LS_COMPLETED
69  */
70 enum lfsck_status {
71         /* The lfsck file is new created, for new MDT, upgrading from old disk,
72          * or re-creating the lfsck file manually. */
73         LS_INIT                 = 0,
74
75         /* The first-step system scanning. */
76         LS_SCANNING_PHASE1      = 1,
77
78         /* The second-step system scanning. */
79         LS_SCANNING_PHASE2      = 2,
80
81         /* The LFSCK processing has completed for all objects. */
82         LS_COMPLETED            = 3,
83
84         /* The LFSCK exited automatically for failure, will not auto restart. */
85         LS_FAILED               = 4,
86
87         /* The LFSCK is stopped manually, will not auto restart. */
88         LS_STOPPED              = 5,
89
90         /* LFSCK is paused automatically when umount,
91          * will be restarted automatically when remount. */
92         LS_PAUSED               = 6,
93
94         /* System crashed during the LFSCK,
95          * will be restarted automatically after recovery. */
96         LS_CRASHED              = 7,
97
98         /* Some OST/MDT failed during the LFSCK, or not join the LFSCK. */
99         LS_PARTIAL              = 8,
100
101         /* The LFSCK is failed because its controller is failed. */
102         LS_CO_FAILED            = 9,
103
104         /* The LFSCK is stopped because its controller is stopped. */
105         LS_CO_STOPPED           = 10,
106
107         /* The LFSCK is paused because its controller is paused. */
108         LS_CO_PAUSED            = 11,
109
110         LS_MAX
111 };
112
113 struct lfsck_start_param {
114         struct ldlm_namespace   *lsp_namespace;
115         struct lfsck_start      *lsp_start;
116         __u32                    lsp_index;
117         unsigned int             lsp_index_valid:1;
118 };
119
120 enum lfsck_events {
121         LE_LASTID_REBUILDING    = 1,
122         LE_LASTID_REBUILT       = 2,
123         LE_PHASE1_DONE          = 3,
124         LE_PHASE2_DONE          = 4,
125         LE_START                = 5,
126         LE_STOP                 = 6,
127         LE_QUERY                = 7,
128         LE_FID_ACCESSED         = 8,
129 };
130
131 enum lfsck_event_flags {
132         LEF_TO_OST              = 0x00000001,
133         LEF_FROM_OST            = 0x00000002,
134         LEF_FORCE_STOP          = 0x00000004,
135 };
136
137 typedef int (*lfsck_out_notify)(const struct lu_env *env, void *data,
138                                 enum lfsck_events event);
139
140 int lfsck_register(const struct lu_env *env, struct dt_device *key,
141                    struct dt_device *next, struct obd_device *obd,
142                    lfsck_out_notify notify, void *notify_data, bool master);
143 void lfsck_degister(const struct lu_env *env, struct dt_device *key);
144
145 int lfsck_add_target(const struct lu_env *env, struct dt_device *key,
146                      struct dt_device *tgt, struct obd_export *exp,
147                      __u32 index, bool for_ost);
148 void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
149                       struct dt_device *tgt, __u32 index, bool for_ost);
150
151 int lfsck_start(const struct lu_env *env, struct dt_device *key,
152                 struct lfsck_start_param *lsp);
153 int lfsck_stop(const struct lu_env *env, struct dt_device *key,
154                struct lfsck_stop *stop);
155 int lfsck_in_notify(const struct lu_env *env, struct dt_device *key,
156                     struct lfsck_request *lr);
157 int lfsck_query(const struct lu_env *env, struct dt_device *key,
158                 struct lfsck_request *lr);
159
160 int lfsck_get_speed(struct dt_device *key, void *buf, int len);
161 int lfsck_set_speed(struct dt_device *key, int val);
162 int lfsck_get_windows(struct dt_device *key, void *buf, int len);
163 int lfsck_set_windows(struct dt_device *key, int val);
164
165 int lfsck_dump(struct dt_device *key, void *buf, int len, enum lfsck_type type);
166
167 static inline void lfsck_pack_rfa(struct lfsck_request *lr,
168                                   const struct lu_fid *fid)
169 {
170         memset(lr, 0, sizeof(*lr));
171         lr->lr_event = LE_FID_ACCESSED;
172         lr->lr_active = LT_LAYOUT;
173         lr->lr_fid = *fid;
174 }
175
176 #endif /* _LUSTRE_LFSCK_H */