Whamcloud - gitweb
5c9df6ddb64a79fc750f4c6aa6f29fb564c13207
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_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,
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 Whamcloud, Inc.
24  */
25 /*
26  * lustre/osd-ldiskfs/osd_scrub.h
27  *
28  * Shared definitions and declarations for OI scrub.
29  *
30  * Author: Fan Yong <yong.fan@whamcloud.com>
31  */
32
33 #ifndef _OSD_SCRUB_H
34 # define _OSD_SCRUB_H
35
36 #include "osd_oi.h"
37
38 #define SCRUB_MAGIC_V1                  0x4C5FD252
39 #define SCRUB_CHECKPOINT_INTERVAL       60
40 #define SCRUB_OI_BITMAP_SIZE            (OSD_OI_FID_NR_MAX >> 3)
41 #define SCRUB_WINDOW_SIZE               1024
42
43 enum scrub_status {
44         /* The scrub file is new created, for new MDT, upgrading from old disk,
45          * or re-creating the scrub file manually. */
46         SS_INIT         = 0,
47
48         /* The scrub is checking/repairing the OI files. */
49         SS_SCANNING     = 1,
50
51         /* The scrub checked/repaired the OI files successfully. */
52         SS_COMPLETED    = 2,
53
54         /* The scrub failed to check/repair the OI files. */
55         SS_FAILED       = 3,
56
57         /* The scrub is stopped manually, the OI files may be inconsistent. */
58         SS_PAUSED       = 4,
59
60         /* The scrub crashed during the scanning, should be restarted. */
61         SS_CRASHED      = 5,
62 };
63
64 enum scrub_flags {
65         /* OI files have been recreated, OI mappings should be re-inserted. */
66         SF_RECREATED    = 0x0000000000000001ULL,
67
68         /* OI files are invalid, should be rebuild ASAP */
69         SF_INCONSISTENT = 0x0000000000000002ULL,
70
71         /* OI scrub is triggered automatically. */
72         SF_AUTO         = 0x0000000000000004ULL,
73 };
74
75 enum scrub_param {
76         /* Exit when fail. */
77         SP_FAILOUT      = 0x0001,
78 };
79
80 enum scrub_start {
81         /* Set failout flag. */
82         SS_SET_FAILOUT          = 0x00000001,
83
84         /* Clear failout flag. */
85         SS_CLEAR_FAILOUT        = 0x00000002,
86
87         /* Reset scrub start position. */
88         SS_RESET                = 0x00000004,
89
90         /* Trigger scrub automatically. */
91         SS_AUTO                 = 0x00000008,
92 };
93
94 struct scrub_file {
95         /* 128-bit uuid for volume. */
96         __u8    sf_uuid[16];
97
98         /* See 'enum scrub_flags'. */
99         __u64   sf_flags;
100
101         /* The scrub magic. */
102         __u32   sf_magic;
103
104         /* See 'enum scrub_status'. */
105         __u16   sf_status;
106
107         /* See 'enum scrub_param'. */
108         __u16   sf_param;
109
110         /* The time for the last OI scrub completed. */
111         __u64   sf_time_last_complete;
112
113         /* The time for the latest OI scrub ran. */
114         __u64   sf_time_latest_start;
115
116         /* The time for the last OI scrub checkpoint. */
117         __u64   sf_time_last_checkpoint;
118
119         /* The position for the latest OI scrub started from. */
120         __u64   sf_pos_latest_start;
121
122         /* The position for the last OI scrub checkpoint. */
123         __u64   sf_pos_last_checkpoint;
124
125         /* The position for the first should be updated object. */
126         __u64   sf_pos_first_inconsistent;
127
128         /* How many objects have been checked. */
129         __u64   sf_items_checked;
130
131         /* How many objects have been updated. */
132         __u64   sf_items_updated;
133
134         /* How many objects failed to be processed. */
135         __u64   sf_items_failed;
136
137         /* How many prior objects have been updated during scanning. */
138         __u64   sf_items_updated_prior;
139
140         /* How long the OI scrub has run. */
141         __u32   sf_run_time;
142
143         /* How many completed OI scrub ran on the device. */
144         __u32   sf_success_count;
145
146         /* How many OI files. */
147         __u16   sf_oi_count;
148
149         /* Update the magic or flags if want to use the reserved fields. */
150         __u16   sf_reserved_0;
151         __u32   sf_reserved_1;
152         __u64   sf_reserved_2[16];
153
154         /* Bitmap for OI files recreated case. */
155         __u8    sf_oi_bitmap[SCRUB_OI_BITMAP_SIZE];
156 };
157
158 struct osd_scrub {
159         struct lvfs_run_ctxt    os_ctxt;
160         struct ptlrpc_thread    os_thread;
161         struct osd_idmap_cache  os_oic;
162         cfs_list_t              os_inconsistent_items;
163
164         /* write lock for scrub prep/update/post/checkpoint,
165          * read lock for scrub dump. */
166         cfs_rw_semaphore_t      os_rwsem;
167         cfs_spinlock_t          os_lock;
168
169         /* Scrub file in memory. */
170         struct scrub_file       os_file;
171
172         /* Buffer for scrub file load/store. */
173         struct scrub_file       os_file_disk;
174
175         /* Inode for the scrub file. */
176         struct inode           *os_inode;
177
178         /* The time for last checkpoint, jiffies */
179         cfs_time_t              os_time_last_checkpoint;
180
181         /* The time for next checkpoint, jiffies */
182         cfs_time_t              os_time_next_checkpoint;
183
184         /* How many objects have been checked since last checkpoint. */
185         __u32                   os_new_checked;
186         __u32                   os_pos_current;
187         __u32                   os_start_flags;
188         unsigned int            os_in_prior:1, /* process inconsistent item
189                                                 * found by RPC prior */
190                                 os_waiting:1, /* Waiting for scan window. */
191                                 os_full_speed:1, /* run w/o speed limit */
192                                 os_no_scrub:1; /* NOT auto trigger OI scrub*/
193 };
194
195 #endif /* _OSD_SCRUB_H */