4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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.
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
23 * Copyright (c) 2012, 2013, Intel Corporation.
26 * lustre/osd-ldiskfs/osd_scrub.c
28 * Top-level entry points into osd module
30 * The OI scrub is used for rebuilding Object Index files when restores MDT from
33 * The otable based iterator scans ldiskfs inode table to feed up layer LFSCK.
35 * Author: Fan Yong <yong.fan@whamcloud.com>
38 #define DEBUG_SUBSYSTEM S_MDS
40 #include <lustre/lustre_idl.h>
41 #include <lustre_disk.h>
42 #include <dt_object.h>
44 #include "osd_internal.h"
46 #include "osd_scrub.h"
48 #define HALF_SEC (CFS_HZ >> 1)
50 #define OSD_OTABLE_MAX_HASH 0x00000000ffffffffULL
52 #define SCRUB_NEXT_BREAK 1 /* exit current loop and process next group */
53 #define SCRUB_NEXT_CONTINUE 2 /* skip current object and process next bit */
54 #define SCRUB_NEXT_EXIT 3 /* exit all the loops */
55 #define SCRUB_NEXT_WAIT 4 /* wait for free cache slot */
56 #define SCRUB_NEXT_CRASH 5 /* simulate system crash during OI scrub */
57 #define SCRUB_NEXT_FATAL 6 /* simulate failure during OI scrub */
58 #define SCRUB_NEXT_NOSCRUB 7 /* new created object, no scrub on it */
59 #define SCRUB_NEXT_NOLMA 8 /* the inode has no FID-in-LMA */
63 static inline struct osd_device *osd_scrub2dev(struct osd_scrub *scrub)
65 return container_of0(scrub, struct osd_device, od_scrub);
68 static inline struct super_block *osd_scrub2sb(struct osd_scrub *scrub)
70 return osd_sb(osd_scrub2dev(scrub));
73 static inline int osd_scrub_has_window(struct osd_scrub *scrub,
74 struct osd_otable_cache *ooc)
76 return scrub->os_pos_current < ooc->ooc_pos_preload + SCRUB_WINDOW_SIZE;
80 * update/insert/delete the specified OI mapping (@fid @id) according to the ops
82 * \retval 1, changed nothing
83 * \retval 0, changed successfully
84 * \retval -ve, on error
86 static int osd_scrub_refresh_mapping(struct osd_thread_info *info,
87 struct osd_device *dev,
88 const struct lu_fid *fid,
89 const struct osd_inode_id *id, int ops)
91 struct lu_fid *oi_fid = &info->oti_fid2;
92 struct osd_inode_id *oi_id = &info->oti_id2;
93 struct iam_container *bag;
94 struct iam_path_descr *ipd;
99 fid_cpu_to_be(oi_fid, fid);
101 osd_id_pack(oi_id, id);
102 jh = ldiskfs_journal_start_sb(osd_sb(dev),
103 osd_dto_credits_noquota[ops]);
106 CERROR("%.16s: fail to start trans for scrub store: rc = %d\n",
107 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, rc);
111 bag = &osd_fid2oi(dev, fid)->oi_dir.od_container;
112 ipd = osd_idx_ipd_get(info->oti_env, bag);
113 if (unlikely(ipd == NULL)) {
114 ldiskfs_journal_stop(jh);
115 CERROR("%.16s: fail to get ipd for scrub store\n",
116 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name);
121 case DTO_INDEX_UPDATE:
122 rc = iam_update(jh, bag, (const struct iam_key *)oi_fid,
123 (struct iam_rec *)oi_id, ipd);
124 if (unlikely(rc == -ENOENT)) {
125 /* Some unlink thread may removed the OI mapping. */
129 case DTO_INDEX_INSERT:
130 rc = iam_insert(jh, bag, (const struct iam_key *)oi_fid,
131 (struct iam_rec *)oi_id, ipd);
132 if (unlikely(rc == -EEXIST)) {
134 /* XXX: There are trouble things when adding OI
135 * mapping for IGIF object, which may cause
136 * multiple objects to be mapped to the same
137 * IGIF formatted FID. Consider the following
140 * 1) The MDT is upgrading from 1.8 device.
141 * The OI scrub generates IGIF FID1 for the
142 * OBJ1 and adds the OI mapping.
144 * 2) For some reason, the OI scrub does not
145 * process all the IGIF objects completely.
147 * 3) The MDT is backuped and restored against
150 * 4) When the MDT mounts up, the OI scrub will
151 * try to rebuild the OI files. For some IGIF
152 * object, OBJ2, which was not processed by the
153 * OI scrub before the backup/restore, and the
154 * new generated IGIF formatted FID may be just
155 * the FID1, the same as OBJ1.
157 * Under such case, the OI scrub cannot know how
158 * to generate new FID for the OBJ2.
160 * Currently, we do nothing for that. One possible
161 * solution is to generate new normal FID for the
164 * Anyway, it is rare, only exists in theory. */
167 case DTO_INDEX_DELETE:
168 rc = iam_delete(jh, bag, (const struct iam_key *)oi_fid, ipd);
170 /* It is normal that the unlink thread has removed the
171 * OI mapping already. */
176 LASSERTF(0, "Unexpected ops %d\n", ops);
179 osd_ipd_put(info->oti_env, bag, ipd);
180 ldiskfs_journal_stop(jh);
184 /* OI_scrub file ops */
186 static void osd_scrub_file_to_cpu(struct scrub_file *des,
187 struct scrub_file *src)
189 memcpy(des->sf_uuid, src->sf_uuid, 16);
190 des->sf_flags = le64_to_cpu(src->sf_flags);
191 des->sf_magic = le32_to_cpu(src->sf_magic);
192 des->sf_status = le16_to_cpu(src->sf_status);
193 des->sf_param = le16_to_cpu(src->sf_param);
194 des->sf_time_last_complete =
195 le64_to_cpu(src->sf_time_last_complete);
196 des->sf_time_latest_start =
197 le64_to_cpu(src->sf_time_latest_start);
198 des->sf_time_last_checkpoint =
199 le64_to_cpu(src->sf_time_last_checkpoint);
200 des->sf_pos_latest_start =
201 le64_to_cpu(src->sf_pos_latest_start);
202 des->sf_pos_last_checkpoint =
203 le64_to_cpu(src->sf_pos_last_checkpoint);
204 des->sf_pos_first_inconsistent =
205 le64_to_cpu(src->sf_pos_first_inconsistent);
206 des->sf_items_checked =
207 le64_to_cpu(src->sf_items_checked);
208 des->sf_items_updated =
209 le64_to_cpu(src->sf_items_updated);
210 des->sf_items_failed =
211 le64_to_cpu(src->sf_items_failed);
212 des->sf_items_updated_prior =
213 le64_to_cpu(src->sf_items_updated_prior);
214 des->sf_run_time = le32_to_cpu(src->sf_run_time);
215 des->sf_success_count = le32_to_cpu(src->sf_success_count);
216 des->sf_oi_count = le16_to_cpu(src->sf_oi_count);
217 memcpy(des->sf_oi_bitmap, src->sf_oi_bitmap, SCRUB_OI_BITMAP_SIZE);
220 static void osd_scrub_file_to_le(struct scrub_file *des,
221 struct scrub_file *src)
223 memcpy(des->sf_uuid, src->sf_uuid, 16);
224 des->sf_flags = cpu_to_le64(src->sf_flags);
225 des->sf_magic = cpu_to_le32(src->sf_magic);
226 des->sf_status = cpu_to_le16(src->sf_status);
227 des->sf_param = cpu_to_le16(src->sf_param);
228 des->sf_time_last_complete =
229 cpu_to_le64(src->sf_time_last_complete);
230 des->sf_time_latest_start =
231 cpu_to_le64(src->sf_time_latest_start);
232 des->sf_time_last_checkpoint =
233 cpu_to_le64(src->sf_time_last_checkpoint);
234 des->sf_pos_latest_start =
235 cpu_to_le64(src->sf_pos_latest_start);
236 des->sf_pos_last_checkpoint =
237 cpu_to_le64(src->sf_pos_last_checkpoint);
238 des->sf_pos_first_inconsistent =
239 cpu_to_le64(src->sf_pos_first_inconsistent);
240 des->sf_items_checked =
241 cpu_to_le64(src->sf_items_checked);
242 des->sf_items_updated =
243 cpu_to_le64(src->sf_items_updated);
244 des->sf_items_failed =
245 cpu_to_le64(src->sf_items_failed);
246 des->sf_items_updated_prior =
247 cpu_to_le64(src->sf_items_updated_prior);
248 des->sf_run_time = cpu_to_le32(src->sf_run_time);
249 des->sf_success_count = cpu_to_le32(src->sf_success_count);
250 des->sf_oi_count = cpu_to_le16(src->sf_oi_count);
251 memcpy(des->sf_oi_bitmap, src->sf_oi_bitmap, SCRUB_OI_BITMAP_SIZE);
254 static void osd_scrub_file_init(struct osd_scrub *scrub, __u8 *uuid)
256 struct scrub_file *sf = &scrub->os_file;
258 memset(sf, 0, sizeof(*sf));
259 memcpy(sf->sf_uuid, uuid, 16);
260 sf->sf_magic = SCRUB_MAGIC_V1;
261 sf->sf_status = SS_INIT;
264 void osd_scrub_file_reset(struct osd_scrub *scrub, __u8 *uuid, __u64 flags)
266 struct scrub_file *sf = &scrub->os_file;
268 CDEBUG(D_LFSCK, "Reset OI scrub file, flags = "LPX64"\n", flags);
269 memcpy(sf->sf_uuid, uuid, 16);
270 sf->sf_status = SS_INIT;
271 sf->sf_flags |= flags;
274 sf->sf_time_latest_start = 0;
275 sf->sf_time_last_checkpoint = 0;
276 sf->sf_pos_latest_start = 0;
277 sf->sf_pos_last_checkpoint = 0;
278 sf->sf_pos_first_inconsistent = 0;
279 sf->sf_items_checked = 0;
280 sf->sf_items_updated = 0;
281 sf->sf_items_failed = 0;
282 sf->sf_items_updated_prior = 0;
283 sf->sf_items_noscrub = 0;
284 sf->sf_items_igif = 0;
287 static int osd_scrub_file_load(struct osd_scrub *scrub)
290 char *name = LDISKFS_SB(osd_scrub2sb(scrub))->s_es->s_volume_name;
291 int len = sizeof(scrub->os_file_disk);
294 rc = osd_ldiskfs_read(scrub->os_inode, &scrub->os_file_disk, len, &pos);
296 struct scrub_file *sf = &scrub->os_file;
298 osd_scrub_file_to_cpu(sf, &scrub->os_file_disk);
299 if (sf->sf_magic != SCRUB_MAGIC_V1) {
300 CWARN("%.16s: invalid scrub magic 0x%x != 0x%x\n,",
301 name, sf->sf_magic, SCRUB_MAGIC_V1);
302 /* Process it as new scrub file. */
307 } else if (rc != 0) {
308 CERROR("%.16s: fail to load scrub file, expected = %d, "
309 "rc = %d\n", name, len, rc);
313 /* return -ENOENT for empty scrub file case. */
320 int osd_scrub_file_store(struct osd_scrub *scrub)
322 struct osd_device *dev;
325 int len = sizeof(scrub->os_file_disk);
329 dev = container_of0(scrub, struct osd_device, od_scrub);
330 credits = osd_dto_credits_noquota[DTO_WRITE_BASE] +
331 osd_dto_credits_noquota[DTO_WRITE_BLOCK];
332 jh = ldiskfs_journal_start_sb(osd_sb(dev), credits);
335 CERROR("%.16s: fail to start trans for scrub store, rc = %d\n",
336 LDISKFS_SB(osd_scrub2sb(scrub))->s_es->s_volume_name,rc);
340 osd_scrub_file_to_le(&scrub->os_file_disk, &scrub->os_file);
341 rc = osd_ldiskfs_write_record(scrub->os_inode, &scrub->os_file_disk,
343 ldiskfs_journal_stop(jh);
345 CERROR("%.16s: fail to store scrub file, expected = %d, "
347 LDISKFS_SB(osd_scrub2sb(scrub))->s_es->s_volume_name,
349 scrub->os_time_last_checkpoint = cfs_time_current();
350 scrub->os_time_next_checkpoint = scrub->os_time_last_checkpoint +
351 cfs_time_seconds(SCRUB_CHECKPOINT_INTERVAL);
357 static int osd_scrub_prep(struct osd_device *dev)
359 struct osd_scrub *scrub = &dev->od_scrub;
360 struct ptlrpc_thread *thread = &scrub->os_thread;
361 struct scrub_file *sf = &scrub->os_file;
362 __u32 flags = scrub->os_start_flags;
366 down_write(&scrub->os_rwsem);
367 if (flags & SS_SET_FAILOUT)
368 sf->sf_param |= SP_FAILOUT;
370 if (flags & SS_CLEAR_FAILOUT)
371 sf->sf_param &= ~SP_FAILOUT;
373 if (flags & SS_RESET)
374 osd_scrub_file_reset(scrub,
375 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid, 0);
377 if (flags & SS_AUTO) {
378 scrub->os_full_speed = 1;
379 sf->sf_flags |= SF_AUTO;
381 scrub->os_full_speed = 0;
384 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
385 scrub->os_full_speed = 1;
387 scrub->os_in_prior = 0;
388 scrub->os_waiting = 0;
389 scrub->os_paused = 0;
390 scrub->os_new_checked = 0;
391 if (sf->sf_pos_last_checkpoint != 0)
392 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
394 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
396 scrub->os_pos_current = sf->sf_pos_latest_start;
397 sf->sf_status = SS_SCANNING;
398 sf->sf_time_latest_start = cfs_time_current_sec();
399 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
400 rc = osd_scrub_file_store(scrub);
402 spin_lock(&scrub->os_lock);
403 thread_set_flags(thread, SVC_RUNNING);
404 spin_unlock(&scrub->os_lock);
405 cfs_waitq_broadcast(&thread->t_ctl_waitq);
407 up_write(&scrub->os_rwsem);
413 osd_scrub_check_update(struct osd_thread_info *info, struct osd_device *dev,
414 struct osd_idmap_cache *oic, int val)
416 struct osd_scrub *scrub = &dev->od_scrub;
417 struct scrub_file *sf = &scrub->os_file;
418 struct lu_fid *fid = &oic->oic_fid;
419 struct osd_inode_id *lid = &oic->oic_lid;
420 struct osd_inode_id *lid2 = &info->oti_id;
421 struct osd_inconsistent_item *oii = NULL;
422 struct inode *inode = NULL;
423 int ops = DTO_INDEX_UPDATE;
428 down_write(&scrub->os_rwsem);
429 scrub->os_new_checked++;
433 if (scrub->os_in_prior)
434 oii = cfs_list_entry(oic, struct osd_inconsistent_item,
437 if (lid->oii_ino < sf->sf_pos_latest_start && oii == NULL)
440 if (fid_is_igif(fid))
443 if ((val == SCRUB_NEXT_NOLMA) &&
444 (!dev->od_handle_nolma || OBD_FAIL_CHECK(OBD_FAIL_FID_NOLMA)))
447 if ((oii != NULL && oii->oii_insert) || (val == SCRUB_NEXT_NOLMA))
450 /* XXX: Currently, no FID-in-LMA for OST object, so osd_oi_lookup()
451 * without checking FLD is enough.
453 * It should be updated if FID-in-LMA for OSD object introduced
455 rc = osd_oi_lookup(info, dev, fid, lid2, false);
461 inode = osd_iget(info, dev, lid);
464 /* Someone removed the inode. */
465 if (rc == -ENOENT || rc == -ESTALE)
470 /* Check whether the inode to be unlinked during OI scrub. */
471 if (unlikely(inode->i_nlink == 0)) {
476 ops = DTO_INDEX_INSERT;
477 idx = osd_oi_fid2idx(dev, fid);
478 if (val == SCRUB_NEXT_NOLMA) {
479 sf->sf_flags |= SF_UPGRADE;
480 scrub->os_full_speed = 1;
481 rc = osd_ea_fid_set(info, inode, fid, 0);
485 if (!(sf->sf_flags & SF_INCONSISTENT))
486 dev->od_igif_inoi = 0;
488 sf->sf_flags |= SF_RECREATED;
489 scrub->os_full_speed = 1;
490 if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
491 ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
493 } else if (osd_id_eq(lid, lid2)) {
496 sf->sf_flags |= SF_INCONSISTENT;
497 scrub->os_full_speed = 1;
499 /* XXX: If the device is restored from file-level backup, then
500 * some IGIFs may have been already in OI files, and some
501 * may be not yet. Means upgrading from 1.8 may be partly
502 * processed, but some clients may hold some immobilized
503 * IGIFs, and use them to access related objects. Under
504 * such case, OSD does not know whether an given IGIF has
505 * been processed or to be processed, and it also cannot
506 * generate local ino#/gen# directly from the immobilized
507 * IGIF because of the backup/restore. Then force OSD to
508 * lookup the given IGIF in OI files, and if no entry,
509 * then ask the client to retry after upgrading completed.
510 * No better choice. */
511 dev->od_igif_inoi = 1;
514 rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops);
516 if (scrub->os_in_prior)
517 sf->sf_items_updated_prior++;
519 sf->sf_items_updated++;
521 /* The target has been changed, need to be re-loaded. */
522 lu_object_purge(info->oti_env, osd2lu_dev(dev), fid);
529 sf->sf_items_failed++;
530 if (sf->sf_pos_first_inconsistent == 0 ||
531 sf->sf_pos_first_inconsistent > lid->oii_ino)
532 sf->sf_pos_first_inconsistent = lid->oii_ino;
537 if (ops == DTO_INDEX_INSERT) {
538 /* There may be conflict unlink during the OI scrub,
539 * if happend, then remove the new added OI mapping. */
540 if (unlikely(inode->i_nlink == 0))
541 osd_scrub_refresh_mapping(info, dev, fid, lid,
545 up_write(&scrub->os_rwsem);
548 LASSERT(!cfs_list_empty(&oii->oii_list));
550 spin_lock(&scrub->os_lock);
551 cfs_list_del_init(&oii->oii_list);
552 spin_unlock(&scrub->os_lock);
555 RETURN(sf->sf_param & SP_FAILOUT ? rc : 0);
558 static int osd_scrub_checkpoint(struct osd_scrub *scrub)
560 struct scrub_file *sf = &scrub->os_file;
563 if (likely(cfs_time_before(cfs_time_current(),
564 scrub->os_time_next_checkpoint) ||
565 scrub->os_new_checked == 0))
568 down_write(&scrub->os_rwsem);
569 sf->sf_items_checked += scrub->os_new_checked;
570 scrub->os_new_checked = 0;
571 sf->sf_pos_last_checkpoint = scrub->os_pos_current;
572 sf->sf_time_last_checkpoint = cfs_time_current_sec();
573 sf->sf_run_time += cfs_duration_sec(cfs_time_current() + HALF_SEC -
574 scrub->os_time_last_checkpoint);
575 rc = osd_scrub_file_store(scrub);
576 up_write(&scrub->os_rwsem);
581 static void osd_scrub_post(struct osd_scrub *scrub, int result)
583 struct scrub_file *sf = &scrub->os_file;
586 down_write(&scrub->os_rwsem);
587 spin_lock(&scrub->os_lock);
588 thread_set_flags(&scrub->os_thread, SVC_STOPPING);
589 spin_unlock(&scrub->os_lock);
590 if (scrub->os_new_checked > 0) {
591 sf->sf_items_checked += scrub->os_new_checked;
592 scrub->os_new_checked = 0;
593 sf->sf_pos_last_checkpoint = scrub->os_pos_current;
595 sf->sf_time_last_checkpoint = cfs_time_current_sec();
597 struct osd_device *dev =
598 container_of0(scrub, struct osd_device, od_scrub);
600 dev->od_igif_inoi = 1;
601 sf->sf_status = SS_COMPLETED;
602 memset(sf->sf_oi_bitmap, 0, SCRUB_OI_BITMAP_SIZE);
603 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
604 SF_UPGRADE | SF_AUTO);
605 sf->sf_time_last_complete = sf->sf_time_last_checkpoint;
606 sf->sf_success_count++;
607 } else if (result == 0) {
608 if (scrub->os_paused)
609 sf->sf_status = SS_PAUSED;
611 sf->sf_status = SS_STOPPED;
613 sf->sf_status = SS_FAILED;
615 sf->sf_run_time += cfs_duration_sec(cfs_time_current() + HALF_SEC -
616 scrub->os_time_last_checkpoint);
617 result = osd_scrub_file_store(scrub);
619 CERROR("%.16s: fail to osd_scrub_post, rc = %d\n",
620 LDISKFS_SB(osd_scrub2sb(scrub))->s_es->s_volume_name,
622 up_write(&scrub->os_rwsem);
627 /* iteration engine */
629 struct osd_iit_param {
630 struct super_block *sb;
631 struct buffer_head *bitmap;
637 typedef int (*osd_iit_next_policy)(struct osd_thread_info *info,
638 struct osd_device *dev,
639 struct osd_iit_param *param,
640 struct osd_idmap_cache **oic,
643 typedef int (*osd_iit_exec_policy)(struct osd_thread_info *info,
644 struct osd_device *dev,
645 struct osd_iit_param *param,
646 struct osd_idmap_cache *oic,
647 int *noslot, int rc);
649 static int osd_iit_next(struct osd_iit_param *param, __u32 *pos)
651 param->offset = ldiskfs_find_next_bit(param->bitmap->b_data,
652 LDISKFS_INODES_PER_GROUP(param->sb), param->offset);
653 if (param->offset >= LDISKFS_INODES_PER_GROUP(param->sb)) {
654 *pos = 1 + (param->bg+1) * LDISKFS_INODES_PER_GROUP(param->sb);
655 return SCRUB_NEXT_BREAK;
657 *pos = param->gbase + param->offset;
662 static int osd_iit_iget(struct osd_thread_info *info, struct osd_device *dev,
663 struct lu_fid *fid, struct osd_inode_id *lid, __u32 pos,
664 struct super_block *sb, bool scrub)
666 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
670 osd_id_gen(lid, pos, OSD_OII_NOGEN);
671 inode = osd_iget(info, dev, lid);
674 /* The inode may be removed after bitmap searching, or the
675 * file is new created without inode initialized yet. */
676 if (rc == -ENOENT || rc == -ESTALE)
677 return SCRUB_NEXT_CONTINUE;
679 CERROR("%.16s: fail to read inode, ino# = %u, rc = %d\n",
680 LDISKFS_SB(sb)->s_es->s_volume_name, pos, rc);
684 /* If the inode has no OI mapping, then it is special locally used,
685 * should be invisible to OI scrub or up layer LFSCK. */
686 if (ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NO_OI)) {
688 return SCRUB_NEXT_CONTINUE;
692 ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB)) {
693 /* Only skip it for the first OI scrub accessing. */
694 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
696 return SCRUB_NEXT_NOSCRUB;
699 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
701 if (fid_is_llog(&lma->lma_self_fid) ||
702 (!scrub && fid_is_internal(&lma->lma_self_fid)) ||
703 (scrub && (lma->lma_incompat & LMAI_AGENT)))
704 rc = SCRUB_NEXT_CONTINUE;
706 *fid = lma->lma_self_fid;
707 } else if (rc == -ENODATA) {
708 lu_igif_build(fid, inode->i_ino, inode->i_generation);
710 rc = SCRUB_NEXT_NOLMA;
718 static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
719 struct osd_iit_param *param,
720 struct osd_idmap_cache **oic, int noslot)
722 struct osd_scrub *scrub = &dev->od_scrub;
723 struct ptlrpc_thread *thread = &scrub->os_thread;
725 struct osd_inode_id *lid;
728 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0) {
729 struct l_wait_info lwi;
731 lwi = LWI_TIMEOUT(cfs_time_seconds(cfs_fail_val), NULL, NULL);
732 l_wait_event(thread->t_ctl_waitq,
733 !cfs_list_empty(&scrub->os_inconsistent_items) ||
734 !thread_is_running(thread),
738 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_CRASH)) {
739 spin_lock(&scrub->os_lock);
740 thread_set_flags(thread, SVC_STOPPING);
741 spin_unlock(&scrub->os_lock);
742 return SCRUB_NEXT_CRASH;
745 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_FATAL))
746 return SCRUB_NEXT_FATAL;
748 if (unlikely(!thread_is_running(thread)))
749 return SCRUB_NEXT_EXIT;
751 if (!cfs_list_empty(&scrub->os_inconsistent_items)) {
752 struct osd_inconsistent_item *oii;
754 oii = cfs_list_entry(scrub->os_inconsistent_items.next,
755 struct osd_inconsistent_item, oii_list);
756 *oic = &oii->oii_cache;
757 scrub->os_in_prior = 1;
762 return SCRUB_NEXT_WAIT;
764 rc = osd_iit_next(param, &scrub->os_pos_current);
768 *oic = &scrub->os_oic;
769 fid = &(*oic)->oic_fid;
770 lid = &(*oic)->oic_lid;
771 rc = osd_iit_iget(info, dev, fid, lid,
772 scrub->os_pos_current, param->sb, true);
776 static int osd_preload_next(struct osd_thread_info *info,
777 struct osd_device *dev, struct osd_iit_param *param,
778 struct osd_idmap_cache **oic, int noslot)
780 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
781 struct osd_scrub *scrub;
782 struct ptlrpc_thread *thread;
785 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
789 scrub = &dev->od_scrub;
790 thread = &scrub->os_thread;
791 if (thread_is_running(thread) &&
792 ooc->ooc_pos_preload >= scrub->os_pos_current)
793 return SCRUB_NEXT_EXIT;
795 rc = osd_iit_iget(info, dev,
796 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
797 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
798 ooc->ooc_pos_preload, param->sb, false);
799 /* If succeed, it needs to move forward; otherwise up layer LFSCK may
800 * ignore the failure, so it still need to skip the inode next time. */
801 ooc->ooc_pos_preload = param->gbase + ++(param->offset);
806 osd_scrub_wakeup(struct osd_scrub *scrub, struct osd_otable_it *it)
808 spin_lock(&scrub->os_lock);
809 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
810 !cfs_list_empty(&scrub->os_inconsistent_items) ||
811 it->ooi_waiting || !thread_is_running(&scrub->os_thread))
812 scrub->os_waiting = 0;
814 scrub->os_waiting = 1;
815 spin_unlock(&scrub->os_lock);
817 return !scrub->os_waiting;
820 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
821 struct osd_iit_param *param,
822 struct osd_idmap_cache *oic, int *noslot, int rc)
824 struct l_wait_info lwi = { 0 };
825 struct osd_scrub *scrub = &dev->od_scrub;
826 struct scrub_file *sf = &scrub->os_file;
827 struct ptlrpc_thread *thread = &scrub->os_thread;
828 struct osd_otable_it *it = dev->od_otable_it;
829 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
832 case SCRUB_NEXT_CONTINUE:
834 case SCRUB_NEXT_WAIT:
836 case SCRUB_NEXT_NOSCRUB:
837 down_write(&scrub->os_rwsem);
838 scrub->os_new_checked++;
839 sf->sf_items_noscrub++;
840 up_write(&scrub->os_rwsem);
844 rc = osd_scrub_check_update(info, dev, oic, rc);
848 rc = osd_scrub_checkpoint(scrub);
850 CERROR("%.16s: fail to checkpoint, pos = %u, rc = %d\n",
851 LDISKFS_SB(param->sb)->s_es->s_volume_name,
852 scrub->os_pos_current, rc);
853 /* Continue, as long as the scrub itself can go ahead. */
856 if (scrub->os_in_prior) {
857 scrub->os_in_prior = 0;
862 scrub->os_pos_current = param->gbase + ++(param->offset);
865 if (it != NULL && it->ooi_waiting &&
866 ooc->ooc_pos_preload < scrub->os_pos_current) {
867 spin_lock(&scrub->os_lock);
869 cfs_waitq_broadcast(&thread->t_ctl_waitq);
870 spin_unlock(&scrub->os_lock);
873 if (scrub->os_full_speed || rc == SCRUB_NEXT_CONTINUE)
876 if (osd_scrub_has_window(scrub, ooc)) {
881 l_wait_event(thread->t_ctl_waitq,
882 osd_scrub_wakeup(scrub, it),
885 if (osd_scrub_has_window(scrub, ooc))
892 static int osd_preload_exec(struct osd_thread_info *info,
893 struct osd_device *dev, struct osd_iit_param *param,
894 struct osd_idmap_cache *oic, int *noslot, int rc)
896 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
899 ooc->ooc_cached_items++;
900 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
901 ~OSD_OTABLE_IT_CACHE_MASK;
903 return rc > 0 ? 0 : rc;
906 #define SCRUB_IT_ALL 1
907 #define SCRUB_IT_CRASH 2
909 static int osd_inode_iteration(struct osd_thread_info *info,
910 struct osd_device *dev, __u32 max, bool preload)
912 osd_iit_next_policy next;
913 osd_iit_exec_policy exec;
916 struct osd_iit_param param;
923 struct osd_scrub *scrub = &dev->od_scrub;
925 next = osd_scrub_next;
926 exec = osd_scrub_exec;
927 pos = &scrub->os_pos_current;
928 count = &scrub->os_new_checked;
930 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
932 next = osd_preload_next;
933 exec = osd_preload_exec;
934 pos = &ooc->ooc_pos_preload;
935 count = &ooc->ooc_cached_items;
937 param.sb = osd_sb(dev);
938 limit = le32_to_cpu(LDISKFS_SB(param.sb)->s_es->s_inodes_count);
940 while (*pos <= limit && *count < max) {
941 struct osd_idmap_cache *oic = NULL;
943 param.bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param.sb);
944 param.offset = (*pos - 1) % LDISKFS_INODES_PER_GROUP(param.sb);
945 param.gbase = 1 + param.bg * LDISKFS_INODES_PER_GROUP(param.sb);
946 param.bitmap = ldiskfs_read_inode_bitmap(param.sb, param.bg);
947 if (param.bitmap == NULL) {
948 CERROR("%.16s: fail to read bitmap for %u, "
949 "scrub will stop, urgent mode\n",
950 LDISKFS_SB(param.sb)->s_es->s_volume_name,
955 while (param.offset < LDISKFS_INODES_PER_GROUP(param.sb) &&
957 rc = next(info, dev, ¶m, &oic, noslot);
959 case SCRUB_NEXT_BREAK:
961 case SCRUB_NEXT_EXIT:
962 brelse(param.bitmap);
964 case SCRUB_NEXT_CRASH:
965 brelse(param.bitmap);
966 RETURN(SCRUB_IT_CRASH);
967 case SCRUB_NEXT_FATAL:
968 brelse(param.bitmap);
972 rc = exec(info, dev, ¶m, oic, &noslot, rc);
974 brelse(param.bitmap);
980 brelse(param.bitmap);
984 RETURN(SCRUB_IT_ALL);
988 static int osd_otable_it_preload(const struct lu_env *env,
989 struct osd_otable_it *it)
991 struct osd_device *dev = it->ooi_dev;
992 struct osd_scrub *scrub = &dev->od_scrub;
993 struct osd_otable_cache *ooc = &it->ooi_cache;
997 rc = osd_inode_iteration(osd_oti_get(env), dev,
998 OSD_OTABLE_IT_CACHE_SIZE, true);
999 if (rc == SCRUB_IT_ALL)
1000 it->ooi_all_cached = 1;
1002 CDEBUG(D_LFSCK, "OSD pre-loaded: max = %u, preload = %u, rc = %d\n",
1003 le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count),
1004 ooc->ooc_pos_preload, rc);
1006 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1007 scrub->os_waiting = 0;
1008 cfs_waitq_broadcast(&scrub->os_thread.t_ctl_waitq);
1011 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1014 static int osd_scrub_main(void *args)
1017 struct osd_device *dev = (struct osd_device *)args;
1018 struct osd_scrub *scrub = &dev->od_scrub;
1019 struct ptlrpc_thread *thread = &scrub->os_thread;
1020 struct super_block *sb = osd_sb(dev);
1024 rc = lu_env_init(&env, LCT_LOCAL);
1026 CERROR("%.16s: OI scrub, fail to init env, rc = %d\n",
1027 LDISKFS_SB(sb)->s_es->s_volume_name, rc);
1031 rc = osd_scrub_prep(dev);
1033 CERROR("%.16s: OI scrub, fail to scrub prep, rc = %d\n",
1034 LDISKFS_SB(sb)->s_es->s_volume_name, rc);
1038 if (!scrub->os_full_speed) {
1039 struct l_wait_info lwi = { 0 };
1040 struct osd_otable_it *it = dev->od_otable_it;
1041 struct osd_otable_cache *ooc = &it->ooi_cache;
1043 l_wait_event(thread->t_ctl_waitq,
1044 it->ooi_user_ready || !thread_is_running(thread),
1046 if (unlikely(!thread_is_running(thread)))
1049 scrub->os_pos_current = ooc->ooc_pos_preload;
1052 CDEBUG(D_LFSCK, "OI scrub: flags = 0x%x, pos = %u\n",
1053 scrub->os_start_flags, scrub->os_pos_current);
1055 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1056 if (unlikely(rc == SCRUB_IT_CRASH))
1057 GOTO(out, rc = -EINVAL);
1061 osd_scrub_post(scrub, rc);
1062 CDEBUG(D_LFSCK, "OI scrub: stop, rc = %d, pos = %u\n",
1063 rc, scrub->os_pos_current);
1066 while (!cfs_list_empty(&scrub->os_inconsistent_items)) {
1067 struct osd_inconsistent_item *oii;
1069 oii = cfs_list_entry(scrub->os_inconsistent_items.next,
1070 struct osd_inconsistent_item, oii_list);
1071 cfs_list_del_init(&oii->oii_list);
1077 spin_lock(&scrub->os_lock);
1078 thread_set_flags(thread, SVC_STOPPED);
1079 cfs_waitq_broadcast(&thread->t_ctl_waitq);
1080 spin_unlock(&scrub->os_lock);
1084 /* initial OI scrub */
1086 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1087 struct dentry *, filldir_t filldir);
1089 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1090 loff_t offset, __u64 ino, unsigned d_type);
1093 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1094 struct dentry *dentry, filldir_t filldir);
1096 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1097 struct dentry *dentry, filldir_t filldir);
1100 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1101 struct dentry *dentry, filldir_t filldir);
1104 OLF_SCAN_SUBITEMS = 0x0001,
1105 OLF_HIDE_FID = 0x0002,
1106 OLF_SHOW_NAME = 0x0004,
1111 struct lu_fid olm_fid;
1113 scandir_t olm_scandir;
1114 filldir_t olm_filldir;
1117 /* Add the new introduced local files in the list in the future. */
1118 static const struct osd_lf_map osd_lf_maps[] = {
1120 { CATLIST, { FID_SEQ_LOCAL_FILE, LLOG_CATALOGS_OID, 0 }, OLF_SHOW_NAME,
1124 { MOUNT_CONFIGS_DIR, { FID_SEQ_LOCAL_FILE, MGS_CONFIGS_OID, 0 },
1125 OLF_SCAN_SUBITEMS, osd_ios_general_scan,
1126 osd_ios_varfid_fill },
1128 /* NIDTBL_VERSIONS */
1129 { MGS_NIDTBL_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
1130 osd_ios_general_scan, osd_ios_varfid_fill },
1133 { "PENDING", { 0, 0, 0 }, 0, NULL, NULL },
1136 { "ROOT", { FID_SEQ_ROOT, 1, 0 },
1137 OLF_SCAN_SUBITEMS | OLF_HIDE_FID, osd_ios_ROOT_scan, NULL },
1139 /* changelog_catalog */
1140 { CHANGELOG_CATALOG, { 0, 0, 0 }, 0, NULL, NULL },
1142 /* changelog_users */
1143 { CHANGELOG_USERS, { 0, 0, 0 }, 0, NULL, NULL },
1146 { "fld", { FID_SEQ_LOCAL_FILE, FLD_INDEX_OID, 0 }, OLF_SHOW_NAME,
1150 { LAST_RCVD, { FID_SEQ_LOCAL_FILE, LAST_RECV_OID, 0 }, OLF_SHOW_NAME,
1153 /* lfsck_bookmark */
1154 { "lfsck_bookmark", { 0, 0, 0 }, 0, NULL, NULL },
1157 { LOV_OBJID, { FID_SEQ_LOCAL_FILE, MDD_LOV_OBJ_OID, 0 }, OLF_SHOW_NAME,
1161 { LOV_OBJSEQ, { FID_SEQ_LOCAL_FILE, MDD_LOV_OBJ_OSEQ, 0 },
1162 OLF_SHOW_NAME, NULL, NULL },
1165 { QMT_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
1166 osd_ios_general_scan, osd_ios_varfid_fill },
1169 { QSD_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
1170 osd_ios_general_scan, osd_ios_varfid_fill },
1173 { "seq_ctl", { FID_SEQ_LOCAL_FILE, FID_SEQ_CTL_OID, 0 },
1174 OLF_SHOW_NAME, NULL, NULL },
1177 { "seq_srv", { FID_SEQ_LOCAL_FILE, FID_SEQ_SRV_OID, 0 },
1178 OLF_SHOW_NAME, NULL, NULL },
1181 { HEALTH_CHECK, { FID_SEQ_LOCAL_FILE, OFD_HEALTH_CHECK_OID, 0 },
1182 OLF_SHOW_NAME, NULL, NULL },
1184 /* lfsck_namespace */
1185 { "lfsck_namespace", { 0, 0, 0 }, 0, NULL, NULL },
1187 /* OBJECTS, upgrade from old device */
1188 { OBJECTS, { 0, 0, 0 }, OLF_SCAN_SUBITEMS, osd_ios_OBJECTS_scan, NULL },
1190 /* lquota_v2.user, upgrade from old device */
1191 { "lquota_v2.user", { 0, 0, 0 }, 0, NULL, NULL },
1193 /* lquota_v2.group, upgrade from old device */
1194 { "lquota_v2.group", { 0, 0, 0 }, 0, NULL, NULL },
1196 /* LAST_GROUP, upgrade from old device */
1197 { "LAST_GROUP", { FID_SEQ_LOCAL_FILE, OFD_LAST_GROUP_OID, 0 },
1198 OLF_SHOW_NAME, NULL, NULL },
1200 { NULL, { 0, 0, 0 }, 0, NULL, NULL }
1203 struct osd_ios_item {
1204 cfs_list_t oii_list;
1205 struct dentry *oii_dentry;
1206 scandir_t oii_scandir;
1207 filldir_t oii_filldir;
1210 struct osd_ios_filldir_buf {
1211 struct osd_thread_info *oifb_info;
1212 struct osd_device *oifb_dev;
1213 struct dentry *oifb_dentry;
1216 static inline struct dentry *
1217 osd_ios_lookup_one_len(const char *name, struct dentry *parent, int namelen)
1219 struct dentry *dentry;
1221 dentry = ll_lookup_one_len(name, parent, namelen);
1222 if (!IS_ERR(dentry) && dentry->d_inode == NULL) {
1224 return ERR_PTR(-ENOENT);
1231 osd_ios_llogname2fid(struct lu_fid *fid, const char *name, int namelen)
1236 fid->f_seq = FID_SEQ_LLOG;
1238 id = id * 10 + name[i++] - '0';
1240 fid->f_oid = id & 0x00000000ffffffffULL;
1241 fid->f_ver = id >> 32;
1245 osd_ios_Oname2fid(struct lu_fid *fid, const char *name, int namelen)
1251 seq = seq * 10 + name[i++] - '0';
1253 lu_last_id_fid(fid, seq);
1257 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1258 scandir_t scandir, filldir_t filldir)
1260 struct osd_ios_item *item;
1262 OBD_ALLOC_PTR(item);
1266 CFS_INIT_LIST_HEAD(&item->oii_list);
1267 item->oii_dentry = dget(dentry);
1268 item->oii_scandir = scandir;
1269 item->oii_filldir = filldir;
1270 cfs_list_add_tail(&item->oii_list, &dev->od_ios_list);
1275 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1277 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1278 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1279 * reference the inode, or fixed if it is missing or references another inode.
1282 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1283 struct inode *inode, const struct lu_fid *fid, int flags)
1285 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
1286 struct osd_inode_id *id = &info->oti_id;
1287 struct osd_inode_id *id2 = &info->oti_id2;
1288 struct osd_scrub *scrub = &dev->od_scrub;
1289 struct scrub_file *sf = &scrub->os_file;
1294 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
1295 if (rc != 0 && rc != -ENODATA)
1298 osd_id_gen(id, inode->i_ino, inode->i_generation);
1299 if (rc == -ENODATA) {
1300 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID)
1301 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1304 rc = osd_ea_fid_set(info, inode, &tfid, 0);
1308 tfid = lma->lma_self_fid;
1311 rc = __osd_oi_lookup(info, dev, &tfid, id2);
1316 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1321 if (osd_id_eq_strict(id, id2))
1324 if (!(sf->sf_flags & SF_INCONSISTENT)) {
1325 osd_scrub_file_reset(scrub,
1326 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
1328 rc = osd_scrub_file_store(scrub);
1333 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id, DTO_INDEX_UPDATE);
1338 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1339 loff_t offset, __u64 ino, unsigned d_type)
1341 struct osd_ios_filldir_buf *fill_buf = buf;
1342 struct osd_device *dev = fill_buf->oifb_dev;
1343 struct dentry *child;
1347 /* skip any '.' started names */
1351 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
1353 RETURN(PTR_ERR(child));
1355 rc = osd_ios_scan_one(fill_buf->oifb_info, dev, child->d_inode,
1357 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
1358 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
1359 osd_ios_varfid_fill);
1365 static int osd_ios_root_fill(void *buf, const char *name, int namelen,
1366 loff_t offset, __u64 ino, unsigned d_type)
1368 struct osd_ios_filldir_buf *fill_buf = buf;
1369 struct osd_device *dev = fill_buf->oifb_dev;
1370 const struct osd_lf_map *map;
1371 struct dentry *child;
1375 /* skip any '.' started names */
1379 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
1380 if (strlen(map->olm_name) != namelen)
1383 if (strncmp(map->olm_name, name, namelen) == 0)
1387 if (map->olm_name == NULL)
1390 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
1392 RETURN(PTR_ERR(child));
1394 rc = osd_ios_scan_one(fill_buf->oifb_info, dev, child->d_inode,
1395 &map->olm_fid, map->olm_flags);
1396 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
1397 rc = osd_ios_new_item(dev, child, map->olm_scandir,
1405 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1406 struct dentry *dentry, filldir_t filldir)
1408 struct osd_ios_filldir_buf buf = { info, dev, dentry };
1409 struct file *filp = &info->oti_it_ea.oie_file;
1410 struct inode *inode = dentry->d_inode;
1411 const struct file_operations *fops = inode->i_fop;
1415 LASSERT(filldir != NULL);
1418 filp->f_dentry = dentry;
1419 filp->f_mode = FMODE_64BITHASH;
1420 filp->f_mapping = inode->i_mapping;
1422 filp->private_data = NULL;
1424 rc = fops->readdir(filp, &buf, filldir);
1425 fops->release(inode, filp);
1431 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1432 struct dentry *dentry, filldir_t filldir)
1434 struct osd_scrub *scrub = &dev->od_scrub;
1435 struct scrub_file *sf = &scrub->os_file;
1436 struct dentry *child;
1440 /* It is existing MDT device. */
1441 dev->od_handle_nolma = 1;
1442 child = osd_ios_lookup_one_len(dot_lustre_name, dentry,
1443 strlen(dot_lustre_name));
1444 if (IS_ERR(child)) {
1445 rc = PTR_ERR(child);
1446 if (rc == -ENOENT) {
1447 /* It is 1.8 MDT device. */
1448 if (!(sf->sf_flags & SF_UPGRADE)) {
1449 osd_scrub_file_reset(scrub,
1450 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
1452 rc = osd_scrub_file_store(scrub);
1458 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
1459 * so the client will get IGIF for the ".lustre" object when
1462 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
1463 * it does not know whether there are some old clients cached
1464 * the ".lustre" IGIF during the upgrading. Two choices:
1466 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
1467 * It will allow the old connected clients to access the
1468 * ".lustre" with cached IGIF. But it will cause others
1469 * on the MDT failed to check "fid_is_dot_lustre()".
1471 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
1472 * for ".lustre" in spite of whether there are some clients
1473 * cached the ".lustre" IGIF or not. It enables the check
1474 * "fid_is_dot_lustre()" on the MDT, although it will cause
1475 * that the old connected clients cannot access the ".lustre"
1476 * with the cached IGIF.
1478 * Usually, it is rare case for the old connected clients
1479 * to access the ".lustre" with cached IGIF. So we prefer
1480 * to the solution 2). */
1481 rc = osd_ios_scan_one(info, dev, child->d_inode,
1482 &LU_DOT_LUSTRE_FID, 0);
1490 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1491 struct dentry *dentry, filldir_t filldir)
1493 struct dentry *child;
1497 child = osd_ios_lookup_one_len(ADMIN_USR, dentry, strlen(ADMIN_USR));
1498 if (!IS_ERR(child)) {
1499 rc = osd_ios_scan_one(info, dev, child->d_inode, NULL, 0);
1502 rc = PTR_ERR(child);
1505 if (rc != 0 && rc != -ENOENT)
1508 child = osd_ios_lookup_one_len(ADMIN_GRP, dentry, strlen(ADMIN_GRP));
1509 if (!IS_ERR(child)) {
1510 rc = osd_ios_scan_one(info, dev, child->d_inode, NULL, 0);
1513 rc = PTR_ERR(child);
1522 static int osd_initial_OI_scrub(struct osd_thread_info *info,
1523 struct osd_device *dev)
1525 struct osd_ios_item *item = NULL;
1526 scandir_t scandir = osd_ios_general_scan;
1527 filldir_t filldir = osd_ios_root_fill;
1528 struct dentry *dentry = osd_sb(dev)->s_root;
1529 const struct osd_lf_map *map = osd_lf_maps;
1534 rc = scandir(info, dev, dentry, filldir);
1536 dput(item->oii_dentry);
1543 if (cfs_list_empty(&dev->od_ios_list))
1546 item = cfs_list_entry(dev->od_ios_list.next,
1547 struct osd_ios_item, oii_list);
1548 cfs_list_del_init(&item->oii_list);
1550 LASSERT(item->oii_scandir != NULL);
1551 scandir = item->oii_scandir;
1552 filldir = item->oii_filldir;
1553 dentry = item->oii_dentry;
1556 while (!cfs_list_empty(&dev->od_ios_list)) {
1557 item = cfs_list_entry(dev->od_ios_list.next,
1558 struct osd_ios_item, oii_list);
1559 cfs_list_del_init(&item->oii_list);
1560 dput(item->oii_dentry);
1567 /* There maybe the case that the object has been removed, but its OI
1568 * mapping is still in the OI file, such as the "CATALOGS" after MDT
1569 * file-level backup/restore. So here cleanup the stale OI mappings. */
1570 while (map->olm_name != NULL) {
1571 struct dentry *child;
1573 if (fid_is_zero(&map->olm_fid)) {
1578 child = osd_ios_lookup_one_len(map->olm_name,
1579 osd_sb(dev)->s_root,
1580 strlen(map->olm_name));
1583 else if (PTR_ERR(child) == -ENOENT)
1584 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
1585 NULL, DTO_INDEX_DELETE);
1592 char *osd_lf_fid2name(const struct lu_fid *fid)
1594 const struct osd_lf_map *map = osd_lf_maps;
1596 while (map->olm_name != NULL) {
1597 if (!lu_fid_eq(fid, &map->olm_fid)) {
1602 if (map->olm_flags & OLF_SHOW_NAME)
1603 return map->olm_name;
1611 /* OI scrub start/stop */
1613 static int do_osd_scrub_start(struct osd_device *dev, __u32 flags)
1615 struct osd_scrub *scrub = &dev->od_scrub;
1616 struct ptlrpc_thread *thread = &scrub->os_thread;
1617 struct l_wait_info lwi = { 0 };
1622 /* os_lock: sync status between stop and scrub thread */
1623 spin_lock(&scrub->os_lock);
1624 if (thread_is_running(thread)) {
1625 spin_unlock(&scrub->os_lock);
1627 } else if (unlikely(thread_is_stopping(thread))) {
1628 spin_unlock(&scrub->os_lock);
1629 l_wait_event(thread->t_ctl_waitq,
1630 thread_is_stopped(thread),
1634 spin_unlock(&scrub->os_lock);
1636 if (scrub->os_file.sf_status == SS_COMPLETED)
1639 scrub->os_start_flags = flags;
1640 thread_set_flags(thread, 0);
1641 rc = PTR_ERR(kthread_run(osd_scrub_main, dev, "OI_scrub"));
1642 if (IS_ERR_VALUE(rc)) {
1643 CERROR("%.16s: cannot start iteration thread, rc = %d\n",
1644 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, rc);
1648 l_wait_event(thread->t_ctl_waitq,
1649 thread_is_running(thread) || thread_is_stopped(thread),
1655 int osd_scrub_start(struct osd_device *dev)
1660 /* od_otable_mutex: prevent curcurrent start/stop */
1661 mutex_lock(&dev->od_otable_mutex);
1662 rc = do_osd_scrub_start(dev, SS_AUTO);
1663 mutex_unlock(&dev->od_otable_mutex);
1665 RETURN(rc == -EALREADY ? 0 : rc);
1668 static void do_osd_scrub_stop(struct osd_scrub *scrub)
1670 struct ptlrpc_thread *thread = &scrub->os_thread;
1671 struct l_wait_info lwi = { 0 };
1673 /* os_lock: sync status between stop and scrub thread */
1674 spin_lock(&scrub->os_lock);
1675 if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
1676 thread_set_flags(thread, SVC_STOPPING);
1677 spin_unlock(&scrub->os_lock);
1678 cfs_waitq_broadcast(&thread->t_ctl_waitq);
1679 l_wait_event(thread->t_ctl_waitq,
1680 thread_is_stopped(thread),
1682 /* Do not skip the last lock/unlock, which can guarantee that
1683 * the caller cannot return until the OI scrub thread exit. */
1684 spin_lock(&scrub->os_lock);
1686 spin_unlock(&scrub->os_lock);
1689 static void osd_scrub_stop(struct osd_device *dev)
1691 /* od_otable_mutex: prevent curcurrent start/stop */
1692 mutex_lock(&dev->od_otable_mutex);
1693 dev->od_scrub.os_paused = 1;
1694 do_osd_scrub_stop(&dev->od_scrub);
1695 mutex_unlock(&dev->od_otable_mutex);
1698 /* OI scrub setup/cleanup */
1700 static const char osd_scrub_name[] = "OI_scrub";
1702 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
1704 struct osd_thread_info *info = osd_oti_get(env);
1705 struct osd_scrub *scrub = &dev->od_scrub;
1706 struct lvfs_run_ctxt *ctxt = &scrub->os_ctxt;
1707 struct scrub_file *sf = &scrub->os_file;
1708 struct super_block *sb = osd_sb(dev);
1709 struct ldiskfs_super_block *es = LDISKFS_SB(sb)->s_es;
1710 struct lvfs_run_ctxt saved;
1716 memset(scrub, 0, sizeof(*scrub));
1717 OBD_SET_CTXT_MAGIC(ctxt);
1718 ctxt->pwdmnt = dev->od_mnt;
1719 ctxt->pwd = dev->od_mnt->mnt_root;
1720 ctxt->fs = get_ds();
1722 cfs_waitq_init(&scrub->os_thread.t_ctl_waitq);
1723 init_rwsem(&scrub->os_rwsem);
1724 spin_lock_init(&scrub->os_lock);
1725 CFS_INIT_LIST_HEAD(&scrub->os_inconsistent_items);
1727 push_ctxt(&saved, ctxt, NULL);
1728 filp = filp_open(osd_scrub_name, O_RDWR | O_CREAT, 0644);
1730 RETURN(PTR_ERR(filp));
1732 scrub->os_inode = igrab(filp->f_dentry->d_inode);
1733 filp_close(filp, 0);
1734 pop_ctxt(&saved, ctxt, NULL);
1735 ldiskfs_set_inode_state(scrub->os_inode,
1736 LDISKFS_STATE_LUSTRE_NO_OI);
1738 rc = osd_scrub_file_load(scrub);
1739 if (rc == -ENOENT) {
1740 osd_scrub_file_init(scrub, es->s_uuid);
1742 } else if (rc != 0) {
1745 if (memcmp(sf->sf_uuid, es->s_uuid, 16) != 0) {
1746 osd_scrub_file_reset(scrub, es->s_uuid,SF_INCONSISTENT);
1748 } else if (sf->sf_status == SS_SCANNING) {
1749 sf->sf_status = SS_CRASHED;
1754 if (sf->sf_pos_last_checkpoint != 0)
1755 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
1757 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
1760 rc = osd_scrub_file_store(scrub);
1765 /* Initialize OI files. */
1766 rc = osd_oi_init(info, dev);
1770 rc = osd_initial_OI_scrub(info, dev);
1772 if ((sf->sf_flags & SF_UPGRADE) &&
1773 !(sf->sf_flags & SF_INCONSISTENT))
1774 /* The 'od_igif_inoi' will be set after the
1775 * upgrading completed, needs NOT remount. */
1776 dev->od_igif_inoi = 0;
1778 /* The 'od_igif_inoi' will be set under the
1780 * 1) new created system, or
1781 * 2) restored from file-level backup, or
1782 * 3) the upgrading completed.
1784 * The 'od_igif_inoi' may be cleared by OI scrub
1785 * later if found that the system is upgrading. */
1786 dev->od_igif_inoi = 1;
1788 if (!dev->od_noscrub &&
1789 ((sf->sf_status == SS_PAUSED) ||
1790 (sf->sf_status == SS_CRASHED &&
1791 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
1792 SF_UPGRADE | SF_AUTO)) ||
1793 (sf->sf_status == SS_INIT &&
1794 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
1796 rc = osd_scrub_start(dev);
1799 /* it is possible that dcache entries may keep objects after they are
1800 * deleted by OSD. While it looks safe this can cause object data to
1801 * stay until umount causing failures in tests calculating free space,
1802 * e.g. replay-ost-single. Since those dcache entries are not used
1803 * anymore let's just free them after use here */
1804 shrink_dcache_sb(sb);
1809 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
1811 struct osd_scrub *scrub = &dev->od_scrub;
1813 LASSERT(dev->od_otable_it == NULL);
1815 if (scrub->os_inode != NULL) {
1816 osd_scrub_stop(dev);
1817 iput(scrub->os_inode);
1818 scrub->os_inode = NULL;
1820 if (dev->od_oi_table != NULL)
1821 osd_oi_fini(osd_oti_get(env), dev);
1824 /* object table based iteration APIs */
1826 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
1827 struct dt_object *dt, __u32 attr,
1828 struct lustre_capa *capa)
1830 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
1831 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
1832 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
1833 struct osd_scrub *scrub = &dev->od_scrub;
1834 struct osd_otable_it *it;
1839 /* od_otable_mutex: prevent curcurrent init/fini */
1840 mutex_lock(&dev->od_otable_mutex);
1841 if (dev->od_otable_it != NULL)
1842 GOTO(out, it = ERR_PTR(-EALREADY));
1846 GOTO(out, it = ERR_PTR(-ENOMEM));
1848 dev->od_otable_it = it;
1850 it->ooi_cache.ooc_consumer_idx = -1;
1851 if (flags & DOIF_OUTUSED)
1852 it->ooi_used_outside = 1;
1854 if (flags & DOIF_RESET)
1857 if (valid & DOIV_ERROR_HANDLE) {
1858 if (flags & DOIF_FAILOUT)
1859 start |= SS_SET_FAILOUT;
1861 start |= SS_CLEAR_FAILOUT;
1864 rc = do_osd_scrub_start(dev, start);
1865 if (rc < 0 && rc != -EALREADY) {
1866 dev->od_otable_it = NULL;
1868 GOTO(out, it = ERR_PTR(rc));
1871 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
1876 mutex_unlock(&dev->od_otable_mutex);
1877 return (struct dt_it *)it;
1880 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
1882 struct osd_otable_it *it = (struct osd_otable_it *)di;
1883 struct osd_device *dev = it->ooi_dev;
1885 /* od_otable_mutex: prevent curcurrent init/fini */
1886 mutex_lock(&dev->od_otable_mutex);
1887 do_osd_scrub_stop(&dev->od_scrub);
1888 LASSERT(dev->od_otable_it == it);
1890 dev->od_otable_it = NULL;
1891 mutex_unlock(&dev->od_otable_mutex);
1895 static int osd_otable_it_get(const struct lu_env *env,
1896 struct dt_it *di, const struct dt_key *key)
1901 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
1906 osd_otable_it_wakeup(struct osd_scrub *scrub, struct osd_otable_it *it)
1908 spin_lock(&scrub->os_lock);
1909 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
1910 scrub->os_waiting ||
1911 !thread_is_running(&scrub->os_thread))
1912 it->ooi_waiting = 0;
1914 it->ooi_waiting = 1;
1915 spin_unlock(&scrub->os_lock);
1917 return !it->ooi_waiting;
1920 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
1922 struct osd_otable_it *it = (struct osd_otable_it *)di;
1923 struct osd_device *dev = it->ooi_dev;
1924 struct osd_scrub *scrub = &dev->od_scrub;
1925 struct osd_otable_cache *ooc = &it->ooi_cache;
1926 struct ptlrpc_thread *thread = &scrub->os_thread;
1927 struct l_wait_info lwi = { 0 };
1931 LASSERT(it->ooi_user_ready);
1934 if (!thread_is_running(thread) && !it->ooi_used_outside)
1937 if (ooc->ooc_cached_items > 0) {
1938 ooc->ooc_cached_items--;
1939 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
1940 ~OSD_OTABLE_IT_CACHE_MASK;
1944 if (it->ooi_all_cached) {
1945 l_wait_event(thread->t_ctl_waitq,
1946 !thread_is_running(thread),
1951 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1952 spin_lock(&scrub->os_lock);
1953 scrub->os_waiting = 0;
1954 cfs_waitq_broadcast(&scrub->os_thread.t_ctl_waitq);
1955 spin_unlock(&scrub->os_lock);
1958 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
1959 l_wait_event(thread->t_ctl_waitq,
1960 osd_otable_it_wakeup(scrub, it),
1963 if (!thread_is_running(thread) && !it->ooi_used_outside)
1966 rc = osd_otable_it_preload(env, it);
1973 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
1974 const struct dt_it *di)
1979 static int osd_otable_it_key_size(const struct lu_env *env,
1980 const struct dt_it *di)
1982 return sizeof(__u64);
1985 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
1986 struct dt_rec *rec, __u32 attr)
1988 struct osd_otable_it *it = (struct osd_otable_it *)di;
1989 struct osd_otable_cache *ooc = &it->ooi_cache;
1991 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
1993 /* Filter out Invald FID already. */
1994 LASSERTF(fid_is_sane((struct lu_fid *)rec),
1995 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
1996 PFID((struct lu_fid *)rec),
1997 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2002 static __u64 osd_otable_it_store(const struct lu_env *env,
2003 const struct dt_it *di)
2005 struct osd_otable_it *it = (struct osd_otable_it *)di;
2006 struct osd_otable_cache *ooc = &it->ooi_cache;
2009 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2010 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2012 hash = ooc->ooc_pos_preload;
2017 * Set the OSD layer iteration start position as the specified hash.
2019 static int osd_otable_it_load(const struct lu_env *env,
2020 const struct dt_it *di, __u64 hash)
2022 struct osd_otable_it *it = (struct osd_otable_it *)di;
2023 struct osd_device *dev = it->ooi_dev;
2024 struct osd_otable_cache *ooc = &it->ooi_cache;
2025 struct osd_scrub *scrub = &dev->od_scrub;
2029 /* Forbid to set iteration position after iteration started. */
2030 if (it->ooi_user_ready)
2033 if (hash > OSD_OTABLE_MAX_HASH)
2034 hash = OSD_OTABLE_MAX_HASH;
2036 ooc->ooc_pos_preload = hash;
2037 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
2038 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2040 it->ooi_user_ready = 1;
2041 if (!scrub->os_full_speed)
2042 cfs_waitq_broadcast(&scrub->os_thread.t_ctl_waitq);
2044 /* Unplug OSD layer iteration by the first next() call. */
2045 rc = osd_otable_it_next(env, (struct dt_it *)it);
2050 static int osd_otable_it_key_rec(const struct lu_env *env,
2051 const struct dt_it *di, void *key_rec)
2056 const struct dt_index_operations osd_otable_ops = {
2058 .init = osd_otable_it_init,
2059 .fini = osd_otable_it_fini,
2060 .get = osd_otable_it_get,
2061 .put = osd_otable_it_put,
2062 .next = osd_otable_it_next,
2063 .key = osd_otable_it_key,
2064 .key_size = osd_otable_it_key_size,
2065 .rec = osd_otable_it_rec,
2066 .store = osd_otable_it_store,
2067 .load = osd_otable_it_load,
2068 .key_rec = osd_otable_it_key_rec,
2072 /* high priority inconsistent items list APIs */
2074 int osd_oii_insert(struct osd_device *dev, struct osd_idmap_cache *oic,
2077 struct osd_inconsistent_item *oii;
2078 struct osd_scrub *scrub = &dev->od_scrub;
2079 struct ptlrpc_thread *thread = &scrub->os_thread;
2084 if (unlikely(oii == NULL))
2087 CFS_INIT_LIST_HEAD(&oii->oii_list);
2088 oii->oii_cache = *oic;
2089 oii->oii_insert = insert;
2091 spin_lock(&scrub->os_lock);
2092 if (unlikely(!thread_is_running(thread))) {
2093 spin_unlock(&scrub->os_lock);
2098 if (cfs_list_empty(&scrub->os_inconsistent_items))
2100 cfs_list_add_tail(&oii->oii_list, &scrub->os_inconsistent_items);
2101 spin_unlock(&scrub->os_lock);
2104 cfs_waitq_broadcast(&thread->t_ctl_waitq);
2109 int osd_oii_lookup(struct osd_device *dev, const struct lu_fid *fid,
2110 struct osd_inode_id *id)
2112 struct osd_scrub *scrub = &dev->od_scrub;
2113 struct osd_inconsistent_item *oii;
2116 spin_lock(&scrub->os_lock);
2117 cfs_list_for_each_entry(oii, &scrub->os_inconsistent_items, oii_list) {
2118 if (lu_fid_eq(fid, &oii->oii_cache.oic_fid)) {
2119 *id = oii->oii_cache.oic_lid;
2120 spin_unlock(&scrub->os_lock);
2124 spin_unlock(&scrub->os_lock);
2131 static const char *scrub_status_names[] = {
2142 static const char *scrub_flags_names[] = {
2150 static const char *scrub_param_names[] = {
2155 static int scrub_bits_dump(char **buf, int *len, int bits, const char *names[],
2163 rc = snprintf(*buf, *len, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
2169 for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
2172 rc = snprintf(*buf, *len, "%s%c", names[i],
2173 bits != 0 ? ',' : '\n');
2184 static int scrub_time_dump(char **buf, int *len, __u64 time, const char *prefix)
2189 rc = snprintf(*buf, *len, "%s: "LPU64" seconds\n", prefix,
2190 cfs_time_current_sec() - time);
2192 rc = snprintf(*buf, *len, "%s: N/A\n", prefix);
2201 static int scrub_pos_dump(char **buf, int *len, __u64 pos, const char *prefix)
2206 rc = snprintf(*buf, *len, "%s: "LPU64"\n", prefix, pos);
2208 rc = snprintf(*buf, *len, "%s: N/A\n", prefix);
2217 int osd_scrub_dump(struct osd_device *dev, char *buf, int len)
2219 struct osd_scrub *scrub = &dev->od_scrub;
2220 struct scrub_file *sf = &scrub->os_file;
2227 down_read(&scrub->os_rwsem);
2228 rc = snprintf(buf, len,
2233 sf->sf_magic, (int)sf->sf_oi_count,
2234 scrub_status_names[sf->sf_status]);
2240 rc = scrub_bits_dump(&buf, &len, sf->sf_flags, scrub_flags_names,
2245 rc = scrub_bits_dump(&buf, &len, sf->sf_param, scrub_param_names,
2250 rc = scrub_time_dump(&buf, &len, sf->sf_time_last_complete,
2251 "time_since_last_completed");
2255 rc = scrub_time_dump(&buf, &len, sf->sf_time_latest_start,
2256 "time_since_latest_start");
2260 rc = scrub_time_dump(&buf, &len, sf->sf_time_last_checkpoint,
2261 "time_since_last_checkpoint");
2265 rc = scrub_pos_dump(&buf, &len, sf->sf_pos_latest_start,
2266 "latest_start_position");
2270 rc = scrub_pos_dump(&buf, &len, sf->sf_pos_last_checkpoint,
2271 "last_checkpoint_position");
2275 rc = scrub_pos_dump(&buf, &len, sf->sf_pos_first_inconsistent,
2276 "first_failure_position");
2280 checked = sf->sf_items_checked + scrub->os_new_checked;
2281 rc = snprintf(buf, len,
2282 "checked: "LPU64"\n"
2283 "updated: "LPU64"\n"
2285 "prior_updated: "LPU64"\n"
2286 "noscrub: "LPU64"\n"
2288 "success_count: %u\n",
2289 checked, sf->sf_items_updated, sf->sf_items_failed,
2290 sf->sf_items_updated_prior, sf->sf_items_noscrub,
2291 sf->sf_items_igif, sf->sf_success_count);
2298 if (thread_is_running(&scrub->os_thread)) {
2299 cfs_duration_t duration = cfs_time_current() -
2300 scrub->os_time_last_checkpoint;
2301 __u64 new_checked = scrub->os_new_checked * CFS_HZ;
2302 __u32 rtime = sf->sf_run_time +
2303 cfs_duration_sec(duration + HALF_SEC);
2306 do_div(new_checked, duration);
2308 do_div(speed, rtime);
2309 rc = snprintf(buf, len,
2310 "run_time: %u seconds\n"
2311 "average_speed: "LPU64" objects/sec\n"
2312 "real-time_speed: "LPU64" objects/sec\n"
2313 "current_position: %u\n",
2314 rtime, speed, new_checked, scrub->os_pos_current);
2316 if (sf->sf_run_time != 0)
2317 do_div(speed, sf->sf_run_time);
2318 rc = snprintf(buf, len,
2319 "run_time: %u seconds\n"
2320 "average_speed: "LPU64" objects/sec\n"
2321 "real-time_speed: N/A\n"
2322 "current_position: N/A\n",
2323 sf->sf_run_time, speed);
2333 up_read(&scrub->os_rwsem);