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, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2012, 2017, 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_LFSCK
40 #include <linux/kthread.h>
41 #include <uapi/linux/lustre/lustre_idl.h>
42 #include <lustre_disk.h>
43 #include <dt_object.h>
44 #include <linux/xattr.h>
45 #include <lustre_scrub.h>
46 #include <lustre_nodemap.h>
48 #include "osd_internal.h"
50 #include "osd_scrub.h"
52 #define OSD_OTABLE_MAX_HASH 0x00000000ffffffffULL
54 static inline int osd_scrub_has_window(struct lustre_scrub *scrub,
55 struct osd_otable_cache *ooc)
57 return scrub->os_pos_current < ooc->ooc_pos_preload + SCRUB_WINDOW_SIZE;
61 * update/insert/delete the specified OI mapping (@fid @id) according to the ops
63 * \retval 1, changed nothing
64 * \retval 0, changed successfully
65 * \retval -ve, on error
67 static int osd_scrub_refresh_mapping(struct osd_thread_info *info,
68 struct osd_device *dev,
69 const struct lu_fid *fid,
70 const struct osd_inode_id *id,
72 enum oi_check_flags flags, bool *exist)
78 if (dev->od_scrub.os_scrub.os_file.sf_param & SP_DRYRUN && !force)
81 /* DTO_INDEX_INSERT is enough for other two ops:
82 * delete/update, but save stack. */
83 th = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
84 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
87 CDEBUG(D_LFSCK, "%s: fail to start trans for scrub op %d "
88 DFID" => %u/%u: rc = %d\n", osd_name(dev), ops,
89 PFID(fid), id ? id->oii_ino : -1, id ? id->oii_gen : -1,
95 case DTO_INDEX_UPDATE:
96 rc = osd_oi_update(info, dev, fid, id, th, flags);
97 if (unlikely(rc == -ENOENT)) {
98 /* Some unlink thread may removed the OI mapping. */
102 case DTO_INDEX_INSERT:
103 rc = osd_oi_insert(info, dev, fid, id, th, flags, exist);
104 if (unlikely(rc == -EEXIST)) {
106 /* XXX: There are trouble things when adding OI
107 * mapping for IGIF object, which may cause
108 * multiple objects to be mapped to the same
109 * IGIF formatted FID. Consider the following
112 * 1) The MDT is upgrading from 1.8 device.
113 * The OI scrub generates IGIF FID1 for the
114 * OBJ1 and adds the OI mapping.
116 * 2) For some reason, the OI scrub does not
117 * process all the IGIF objects completely.
119 * 3) The MDT is backuped and restored against
122 * 4) When the MDT mounts up, the OI scrub will
123 * try to rebuild the OI files. For some IGIF
124 * object, OBJ2, which was not processed by the
125 * OI scrub before the backup/restore, and the
126 * new generated IGIF formatted FID may be just
127 * the FID1, the same as OBJ1.
129 * Under such case, the OI scrub cannot know how
130 * to generate new FID for the OBJ2.
132 * Currently, we do nothing for that. One possible
133 * solution is to generate new normal FID for the
136 * Anyway, it is rare, only exists in theory. */
139 case DTO_INDEX_DELETE:
140 rc = osd_oi_delete(info, dev, fid, th, flags);
142 /* It is normal that the unlink thread has removed the
143 * OI mapping already. */
148 LASSERTF(0, "Unexpected ops %d\n", ops);
152 ldiskfs_journal_stop(th);
154 CDEBUG(D_LFSCK, "%s: fail to refresh OI map for scrub op %d "
155 DFID" => %u/%u: rc = %d\n", osd_name(dev), ops,
156 PFID(fid), id ? id->oii_ino : -1, id ? id->oii_gen : -1,
163 osd_scrub_convert_ff(struct osd_thread_info *info, struct osd_device *dev,
164 struct inode *inode, const struct lu_fid *fid)
166 struct filter_fid_old *ff = &info->oti_ff;
167 struct dentry *dentry = &info->oti_obj_dentry;
168 struct lu_fid *tfid = &info->oti_fid;
175 if (dev->od_scrub.os_scrub.os_file.sf_param & SP_DRYRUN)
178 if (fid_is_idif(fid) && dev->od_index_in_idif == 0) {
179 struct ost_id *oi = &info->oti_ostid;
181 fid_to_ostid(fid, oi);
182 ostid_to_fid(tfid, oi, 0);
187 /* We want the LMA to fit into the 256-byte OST inode, so operate
189 * 1) read old XATTR_NAME_FID and save the parent FID;
190 * 2) delete the old XATTR_NAME_FID;
191 * 3) make new LMA and add it;
192 * 4) generate new XATTR_NAME_FID with the saved parent FID and add it.
194 * Making the LMA to fit into the 256-byte OST inode can save time for
195 * normal osd_check_lma() and for other OI scrub scanning in future.
196 * So it is worth to make some slow conversion here. */
197 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
198 osd_dto_credits_noquota[DTO_XATTR_SET] * 3);
201 CDEBUG(D_LFSCK, "%s: fail to start trans for convert ff "
202 DFID": rc = %d\n", osd_name(dev), PFID(tfid), rc);
206 /* 1) read old XATTR_NAME_FID and save the parent FID */
207 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_FID, ff, sizeof(*ff));
208 if (rc == sizeof(*ff)) {
209 /* 2) delete the old XATTR_NAME_FID */
210 ll_vfs_dq_init(inode);
211 rc = osd_removexattr(dentry, inode, XATTR_NAME_FID);
216 } else if (rc != -ENODATA && rc != sizeof(struct filter_fid)) {
217 GOTO(stop, rc = -EINVAL);
220 /* 3) make new LMA and add it */
221 rc = osd_ea_fid_set(info, inode, tfid, LMAC_FID_ON_OST, 0);
224 /* If failed, we should try to add the old back. */
227 /* The new PFID EA will only contains ::ff_parent */
228 size = sizeof(ff->ff_parent);
231 /* 4) generate new XATTR_NAME_FID with the saved parent FID and add it*/
235 rc1 = __osd_xattr_set(info, inode, XATTR_NAME_FID, ff, size,
237 if (rc1 != 0 && rc == 0)
244 ldiskfs_journal_stop(jh);
246 CDEBUG(D_LFSCK, "%s: fail to convert ff "DFID": rc = %d\n",
247 osd_name(dev), PFID(tfid), rc);
252 osd_scrub_check_update(struct osd_thread_info *info, struct osd_device *dev,
253 struct osd_idmap_cache *oic, int val)
255 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
256 struct scrub_file *sf = &scrub->os_file;
257 struct lu_fid *fid = &oic->oic_fid;
258 struct osd_inode_id *lid = &oic->oic_lid;
259 struct osd_inode_id *lid2 = &info->oti_id;
260 struct osd_inconsistent_item *oii = NULL;
261 struct inode *inode = NULL;
262 int ops = DTO_INDEX_UPDATE;
264 bool converted = false;
268 down_write(&scrub->os_rwsem);
269 scrub->os_new_checked++;
273 if (scrub->os_in_prior)
274 oii = list_entry(oic, struct osd_inconsistent_item,
277 if (lid->oii_ino < sf->sf_pos_latest_start && oii == NULL)
280 if (fid_is_igif(fid))
283 if (val == SCRUB_NEXT_OSTOBJ_OLD) {
284 inode = osd_iget(info, dev, lid);
287 /* Someone removed the inode. */
288 if (rc == -ENOENT || rc == -ESTALE)
293 /* The inode has been reused as EA inode, ignore it. */
294 if (unlikely(osd_is_ea_inode(inode)))
297 sf->sf_flags |= SF_UPGRADE;
298 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
299 dev->od_check_ff = 1;
300 rc = osd_scrub_convert_ff(info, dev, inode, fid);
307 if ((val == SCRUB_NEXT_NOLMA) &&
308 (!scrub->os_convert_igif || OBD_FAIL_CHECK(OBD_FAIL_FID_NOLMA)))
311 if ((oii != NULL && oii->oii_insert) || (val == SCRUB_NEXT_NOLMA)) {
312 ops = DTO_INDEX_INSERT;
317 rc = osd_oi_lookup(info, dev, fid, lid2,
318 (val == SCRUB_NEXT_OSTOBJ ||
319 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0);
322 ops = DTO_INDEX_INSERT;
323 else if (rc != -ESTALE)
328 inode = osd_iget(info, dev, lid);
331 /* Someone removed the inode. */
332 if (rc == -ENOENT || rc == -ESTALE)
337 /* The inode has been reused as EA inode, ignore it. */
338 if (unlikely(osd_is_ea_inode(inode)))
342 if (!scrub->os_partial_scan)
343 scrub->os_full_speed = 1;
346 case SCRUB_NEXT_NOLMA:
347 sf->sf_flags |= SF_UPGRADE;
348 if (!(sf->sf_param & SP_DRYRUN)) {
349 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
354 if (!(sf->sf_flags & SF_INCONSISTENT))
355 dev->od_igif_inoi = 0;
357 case SCRUB_NEXT_OSTOBJ:
358 sf->sf_flags |= SF_INCONSISTENT;
359 case SCRUB_NEXT_OSTOBJ_OLD:
364 } else if (osd_id_eq(lid, lid2)) {
366 sf->sf_items_updated++;
370 if (!scrub->os_partial_scan)
371 scrub->os_full_speed = 1;
373 sf->sf_flags |= SF_INCONSISTENT;
375 /* XXX: If the device is restored from file-level backup, then
376 * some IGIFs may have been already in OI files, and some
377 * may be not yet. Means upgrading from 1.8 may be partly
378 * processed, but some clients may hold some immobilized
379 * IGIFs, and use them to access related objects. Under
380 * such case, OSD does not know whether an given IGIF has
381 * been processed or to be processed, and it also cannot
382 * generate local ino#/gen# directly from the immobilized
383 * IGIF because of the backup/restore. Then force OSD to
384 * lookup the given IGIF in OI files, and if no entry,
385 * then ask the client to retry after upgrading completed.
386 * No better choice. */
387 dev->od_igif_inoi = 1;
390 rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops, false,
391 (val == SCRUB_NEXT_OSTOBJ ||
392 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0,
395 if (scrub->os_in_prior)
396 sf->sf_items_updated_prior++;
398 sf->sf_items_updated++;
400 if (ops == DTO_INDEX_INSERT && val == 0 && !exist) {
401 int idx = osd_oi_fid2idx(dev, fid);
403 sf->sf_flags |= SF_RECREATED;
404 if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
405 ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
413 sf->sf_items_failed++;
414 if (sf->sf_pos_first_inconsistent == 0 ||
415 sf->sf_pos_first_inconsistent > lid->oii_ino)
416 sf->sf_pos_first_inconsistent = lid->oii_ino;
421 /* There may be conflict unlink during the OI scrub,
422 * if happend, then remove the new added OI mapping. */
423 if (ops == DTO_INDEX_INSERT && inode != NULL && !IS_ERR(inode) &&
424 unlikely(ldiskfs_test_inode_state(inode,
425 LDISKFS_STATE_LUSTRE_DESTROY)))
426 osd_scrub_refresh_mapping(info, dev, fid, lid,
427 DTO_INDEX_DELETE, false,
428 (val == SCRUB_NEXT_OSTOBJ ||
429 val == SCRUB_NEXT_OSTOBJ_OLD) ?
430 OI_KNOWN_ON_OST : 0, NULL);
431 up_write(&scrub->os_rwsem);
433 if (inode != NULL && !IS_ERR(inode))
437 spin_lock(&scrub->os_lock);
438 if (likely(!list_empty(&oii->oii_list)))
439 list_del(&oii->oii_list);
440 spin_unlock(&scrub->os_lock);
445 RETURN(sf->sf_param & SP_FAILOUT ? rc : 0);
448 static int osd_scrub_prep(const struct lu_env *env, struct osd_device *dev)
450 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
451 struct ptlrpc_thread *thread = &scrub->os_thread;
452 struct scrub_file *sf = &scrub->os_file;
453 __u32 flags = scrub->os_start_flags;
455 bool drop_dryrun = false;
458 CDEBUG(D_LFSCK, "%s: OI scrub prep, flags = 0x%x\n",
459 osd_scrub2name(scrub), flags);
461 down_write(&scrub->os_rwsem);
462 if (flags & SS_SET_FAILOUT)
463 sf->sf_param |= SP_FAILOUT;
464 else if (flags & SS_CLEAR_FAILOUT)
465 sf->sf_param &= ~SP_FAILOUT;
467 if (flags & SS_SET_DRYRUN) {
468 sf->sf_param |= SP_DRYRUN;
469 } else if (flags & SS_CLEAR_DRYRUN && sf->sf_param & SP_DRYRUN) {
470 sf->sf_param &= ~SP_DRYRUN;
474 if (flags & SS_RESET)
475 scrub_file_reset(scrub,
476 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid, 0);
478 if (flags & SS_AUTO_FULL) {
479 scrub->os_full_speed = 1;
480 scrub->os_partial_scan = 0;
481 sf->sf_flags |= SF_AUTO;
482 } else if (flags & SS_AUTO_PARTIAL) {
483 scrub->os_full_speed = 0;
484 scrub->os_partial_scan = 1;
485 sf->sf_flags |= SF_AUTO;
486 } else if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
488 scrub->os_full_speed = 1;
489 scrub->os_partial_scan = 0;
491 scrub->os_full_speed = 0;
492 scrub->os_partial_scan = 0;
495 spin_lock(&scrub->os_lock);
496 scrub->os_in_prior = 0;
497 scrub->os_waiting = 0;
498 scrub->os_paused = 0;
499 scrub->os_in_join = 0;
500 scrub->os_full_scrub = 0;
501 spin_unlock(&scrub->os_lock);
502 scrub->os_new_checked = 0;
503 if (drop_dryrun && sf->sf_pos_first_inconsistent != 0)
504 sf->sf_pos_latest_start = sf->sf_pos_first_inconsistent;
505 else if (sf->sf_pos_last_checkpoint != 0)
506 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
508 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
510 scrub->os_pos_current = sf->sf_pos_latest_start;
511 sf->sf_status = SS_SCANNING;
512 sf->sf_time_latest_start = ktime_get_real_seconds();
513 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
514 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
515 rc = scrub_file_store(env, scrub);
517 spin_lock(&scrub->os_lock);
518 thread_set_flags(thread, SVC_RUNNING);
519 spin_unlock(&scrub->os_lock);
520 wake_up_all(&thread->t_ctl_waitq);
522 up_write(&scrub->os_rwsem);
527 static int osd_scrub_post(const struct lu_env *env, struct osd_device *dev,
530 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
531 struct scrub_file *sf = &scrub->os_file;
535 CDEBUG(D_LFSCK, "%s: OI scrub post with result = %d\n",
536 osd_scrub2name(scrub), result);
538 down_write(&scrub->os_rwsem);
539 spin_lock(&scrub->os_lock);
540 thread_set_flags(&scrub->os_thread, SVC_STOPPING);
541 spin_unlock(&scrub->os_lock);
542 if (scrub->os_new_checked > 0) {
543 sf->sf_items_checked += scrub->os_new_checked;
544 scrub->os_new_checked = 0;
545 sf->sf_pos_last_checkpoint = scrub->os_pos_current;
547 sf->sf_time_last_checkpoint = ktime_get_real_seconds();
549 dev->od_igif_inoi = 1;
550 dev->od_check_ff = 0;
551 sf->sf_status = SS_COMPLETED;
552 if (!(sf->sf_param & SP_DRYRUN)) {
553 memset(sf->sf_oi_bitmap, 0, SCRUB_OI_BITMAP_SIZE);
554 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
555 SF_UPGRADE | SF_AUTO);
557 sf->sf_time_last_complete = sf->sf_time_last_checkpoint;
558 sf->sf_success_count++;
559 } else if (result == 0) {
560 if (scrub->os_paused)
561 sf->sf_status = SS_PAUSED;
563 sf->sf_status = SS_STOPPED;
565 sf->sf_status = SS_FAILED;
567 sf->sf_run_time += ktime_get_seconds() -
568 scrub->os_time_last_checkpoint;
570 rc = scrub_file_store(env, scrub);
571 up_write(&scrub->os_rwsem);
573 RETURN(rc < 0 ? rc : result);
576 /* iteration engine */
578 typedef int (*osd_iit_next_policy)(struct osd_thread_info *info,
579 struct osd_device *dev,
580 struct osd_iit_param *param,
581 struct osd_idmap_cache **oic,
584 typedef int (*osd_iit_exec_policy)(struct osd_thread_info *info,
585 struct osd_device *dev,
586 struct osd_iit_param *param,
587 struct osd_idmap_cache *oic,
588 bool *noslot, int rc);
590 static int osd_iit_next(struct osd_iit_param *param, __u64 *pos)
595 param->offset = ldiskfs_find_next_bit(param->bitmap->b_data,
596 LDISKFS_INODES_PER_GROUP(param->sb), param->offset);
597 if (param->offset >= LDISKFS_INODES_PER_GROUP(param->sb)) {
598 *pos = 1 + (param->bg+1) * LDISKFS_INODES_PER_GROUP(param->sb);
599 return SCRUB_NEXT_BREAK;
602 offset = param->offset++;
603 if (unlikely(*pos == param->gbase + offset && *pos != param->start)) {
604 /* We should NOT find the same object more than once. */
605 CERROR("%s: scan the same object multiple times at the pos: "
606 "group = %u, base = %u, offset = %u, start = %u\n",
607 param->sb->s_id, (__u32)param->bg, param->gbase,
608 offset, param->start);
612 *pos = param->gbase + offset;
617 * \retval SCRUB_NEXT_OSTOBJ_OLD: FID-on-OST
618 * \retval 0: FID-on-MDT
620 static int osd_scrub_check_local_fldb(struct osd_thread_info *info,
621 struct osd_device *dev,
624 /* XXX: The initial OI scrub will scan the top level /O to generate
625 * a small local FLDB according to the <seq>. If the given FID
626 * is in the local FLDB, then it is FID-on-OST; otherwise it's
627 * quite possible for FID-on-MDT. */
629 return SCRUB_NEXT_OSTOBJ_OLD;
634 static int osd_scrub_get_fid(struct osd_thread_info *info,
635 struct osd_device *dev, struct inode *inode,
636 struct lu_fid *fid, bool scrub)
638 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
640 bool has_lma = false;
642 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
643 &info->oti_ost_attrs);
646 if (lma->lma_compat & LMAC_NOT_IN_OI ||
647 lma->lma_incompat & LMAI_AGENT)
648 return SCRUB_NEXT_CONTINUE;
650 *fid = lma->lma_self_fid;
654 if (lma->lma_compat & LMAC_FID_ON_OST)
655 return SCRUB_NEXT_OSTOBJ;
657 if (fid_is_idif(fid))
658 return SCRUB_NEXT_OSTOBJ_OLD;
660 /* For local object. */
661 if (fid_is_internal(fid))
664 /* For external visible MDT-object with non-normal FID. */
665 if (fid_is_namespace_visible(fid) && !fid_is_norm(fid))
668 /* For the object with normal FID, it may be MDT-object,
669 * or may be 2.4 OST-object, need further distinguish.
670 * Fall through to next section. */
673 if (rc == -ENODATA || rc == 0) {
674 rc = osd_get_idif(info, inode, &info->oti_obj_dentry, fid);
677 /* It is old 2.x (x <= 3) or 1.8 OST-object. */
678 rc = SCRUB_NEXT_OSTOBJ_OLD;
684 /* It is FID-on-OST, but we do not know how
685 * to generate its FID, ignore it directly. */
686 rc = SCRUB_NEXT_CONTINUE;
688 /* It is 2.4 OST-object. */
689 rc = SCRUB_NEXT_OSTOBJ_OLD;
697 if (dev->od_scrub.os_scrub.os_convert_igif) {
698 lu_igif_build(fid, inode->i_ino,
699 inode->i_generation);
701 rc = SCRUB_NEXT_NOLMA;
705 /* It may be FID-on-OST, or may be FID for
706 * non-MDT0, anyway, we do not know how to
707 * generate its FID, ignore it directly. */
708 rc = SCRUB_NEXT_CONTINUE;
713 /* For OI scrub case only: the object has LMA but has no ff
714 * (or ff crashed). It may be MDT-object, may be OST-object
715 * with crashed ff. The last check is local FLDB. */
716 rc = osd_scrub_check_local_fldb(info, dev, fid);
722 static int osd_iit_iget(struct osd_thread_info *info, struct osd_device *dev,
723 struct lu_fid *fid, struct osd_inode_id *lid, __u32 pos,
724 struct super_block *sb, bool scrub)
730 /* Not handle the backend root object and agent parent object.
731 * They are neither visible to namespace nor have OI mappings. */
732 if (unlikely(pos == osd_sb(dev)->s_root->d_inode->i_ino ||
733 is_remote_parent_ino(dev, pos)))
734 RETURN(SCRUB_NEXT_CONTINUE);
736 osd_id_gen(lid, pos, OSD_OII_NOGEN);
737 inode = osd_iget(info, dev, lid);
740 /* The inode may be removed after bitmap searching, or the
741 * file is new created without inode initialized yet. */
742 if (rc == -ENOENT || rc == -ESTALE)
743 RETURN(SCRUB_NEXT_CONTINUE);
745 CDEBUG(D_LFSCK, "%s: fail to read inode, ino# = %u: "
746 "rc = %d\n", osd_dev2name(dev), pos, rc);
750 /* It is an EA inode, no OI mapping for it, skip it. */
751 if (osd_is_ea_inode(inode))
752 GOTO(put, rc = SCRUB_NEXT_CONTINUE);
755 ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB)) {
756 /* Only skip it for the first OI scrub accessing. */
757 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
758 GOTO(put, rc = SCRUB_NEXT_NOSCRUB);
761 rc = osd_scrub_get_fid(info, dev, inode, fid, scrub);
770 static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
771 struct osd_iit_param *param,
772 struct osd_idmap_cache **oic, const bool noslot)
774 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
775 struct ptlrpc_thread *thread = &scrub->os_thread;
777 struct osd_inode_id *lid;
780 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0) {
781 struct l_wait_info lwi;
783 lwi = LWI_TIMEOUT(cfs_time_seconds(cfs_fail_val), NULL, NULL);
784 if (likely(lwi.lwi_timeout > 0))
785 l_wait_event(thread->t_ctl_waitq,
786 !list_empty(&scrub->os_inconsistent_items) ||
787 !thread_is_running(thread),
791 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_CRASH)) {
792 spin_lock(&scrub->os_lock);
793 thread_set_flags(thread, SVC_STOPPING);
794 spin_unlock(&scrub->os_lock);
795 return SCRUB_NEXT_CRASH;
798 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_FATAL))
799 return SCRUB_NEXT_FATAL;
801 if (unlikely(!thread_is_running(thread)))
802 return SCRUB_NEXT_EXIT;
804 if (!list_empty(&scrub->os_inconsistent_items)) {
805 spin_lock(&scrub->os_lock);
806 if (likely(!list_empty(&scrub->os_inconsistent_items))) {
807 struct osd_inconsistent_item *oii;
809 oii = list_entry(scrub->os_inconsistent_items.next,
810 struct osd_inconsistent_item, oii_list);
811 spin_unlock(&scrub->os_lock);
813 *oic = &oii->oii_cache;
814 scrub->os_in_prior = 1;
818 spin_unlock(&scrub->os_lock);
822 return SCRUB_NEXT_WAIT;
824 rc = osd_iit_next(param, &scrub->os_pos_current);
828 *oic = &dev->od_scrub.os_oic;
829 fid = &(*oic)->oic_fid;
830 lid = &(*oic)->oic_lid;
831 rc = osd_iit_iget(info, dev, fid, lid,
832 scrub->os_pos_current, param->sb, true);
836 static int osd_preload_next(struct osd_thread_info *info,
837 struct osd_device *dev, struct osd_iit_param *param,
838 struct osd_idmap_cache **oic, const bool noslot)
840 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
841 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
842 struct ptlrpc_thread *thread = &scrub->os_thread;
845 if (thread_is_running(thread) &&
846 ooc->ooc_pos_preload >= scrub->os_pos_current)
847 return SCRUB_NEXT_EXIT;
849 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
853 rc = osd_iit_iget(info, dev,
854 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
855 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
856 ooc->ooc_pos_preload, param->sb, false);
861 osd_scrub_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
863 spin_lock(&scrub->os_lock);
864 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
865 !list_empty(&scrub->os_inconsistent_items) ||
866 it->ooi_waiting || !thread_is_running(&scrub->os_thread))
867 scrub->os_waiting = 0;
869 scrub->os_waiting = 1;
870 spin_unlock(&scrub->os_lock);
872 return !scrub->os_waiting;
875 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
876 struct osd_iit_param *param,
877 struct osd_idmap_cache *oic, bool *noslot, int rc)
879 struct l_wait_info lwi = { 0 };
880 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
881 struct scrub_file *sf = &scrub->os_file;
882 struct ptlrpc_thread *thread = &scrub->os_thread;
883 struct osd_otable_it *it = dev->od_otable_it;
884 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
887 case SCRUB_NEXT_NOSCRUB:
888 down_write(&scrub->os_rwsem);
889 scrub->os_new_checked++;
890 sf->sf_items_noscrub++;
891 up_write(&scrub->os_rwsem);
892 case SCRUB_NEXT_CONTINUE:
893 case SCRUB_NEXT_WAIT:
897 rc = osd_scrub_check_update(info, dev, oic, rc);
899 scrub->os_in_prior = 0;
903 rc = scrub_checkpoint(info->oti_env, scrub);
905 CDEBUG(D_LFSCK, "%s: fail to checkpoint, pos = %llu: "
906 "rc = %d\n", osd_scrub2name(scrub),
907 scrub->os_pos_current, rc);
908 /* Continue, as long as the scrub itself can go ahead. */
911 if (scrub->os_in_prior) {
912 scrub->os_in_prior = 0;
917 if (it != NULL && it->ooi_waiting && ooc != NULL &&
918 ooc->ooc_pos_preload < scrub->os_pos_current) {
919 spin_lock(&scrub->os_lock);
921 wake_up_all(&thread->t_ctl_waitq);
922 spin_unlock(&scrub->os_lock);
925 if (rc == SCRUB_NEXT_CONTINUE)
928 if (scrub->os_full_speed || !ooc || osd_scrub_has_window(scrub, ooc)) {
934 l_wait_event(thread->t_ctl_waitq, osd_scrub_wakeup(scrub, it),
937 if (!ooc || osd_scrub_has_window(scrub, ooc))
944 static int osd_preload_exec(struct osd_thread_info *info,
945 struct osd_device *dev, struct osd_iit_param *param,
946 struct osd_idmap_cache *oic, bool *noslot, int rc)
948 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
951 ooc->ooc_cached_items++;
952 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
953 ~OSD_OTABLE_IT_CACHE_MASK;
955 return rc > 0 ? 0 : rc;
958 #define SCRUB_IT_ALL 1
959 #define SCRUB_IT_CRASH 2
961 static void osd_scrub_join(const struct lu_env *env, struct osd_device *dev,
962 __u32 flags, bool inconsistent)
964 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
965 struct ptlrpc_thread *thread = &scrub->os_thread;
966 struct scrub_file *sf = &scrub->os_file;
970 LASSERT(!(flags & SS_AUTO_PARTIAL));
972 down_write(&scrub->os_rwsem);
973 scrub->os_in_join = 1;
974 if (flags & SS_SET_FAILOUT)
975 sf->sf_param |= SP_FAILOUT;
976 else if (flags & SS_CLEAR_FAILOUT)
977 sf->sf_param &= ~SP_FAILOUT;
979 if (flags & SS_SET_DRYRUN)
980 sf->sf_param |= SP_DRYRUN;
981 else if (flags & SS_CLEAR_DRYRUN)
982 sf->sf_param &= ~SP_DRYRUN;
984 if (flags & SS_RESET) {
985 scrub_file_reset(scrub, LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
986 inconsistent ? SF_INCONSISTENT : 0);
987 sf->sf_status = SS_SCANNING;
990 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
991 scrub->os_full_speed = 1;
993 scrub->os_full_speed = 0;
995 if (flags & SS_AUTO_FULL) {
996 sf->sf_flags |= SF_AUTO;
997 scrub->os_full_speed = 1;
1000 scrub->os_new_checked = 0;
1001 if (sf->sf_pos_last_checkpoint != 0)
1002 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
1004 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
1006 scrub->os_pos_current = sf->sf_pos_latest_start;
1007 sf->sf_time_latest_start = ktime_get_real_seconds();
1008 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
1009 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
1010 rc = scrub_file_store(env, scrub);
1012 spin_lock(&scrub->os_lock);
1013 scrub->os_waiting = 0;
1014 scrub->os_paused = 0;
1015 scrub->os_partial_scan = 0;
1016 scrub->os_in_join = 0;
1017 scrub->os_full_scrub = 0;
1018 spin_unlock(&scrub->os_lock);
1019 wake_up_all(&thread->t_ctl_waitq);
1020 up_write(&scrub->os_rwsem);
1022 CDEBUG(D_LFSCK, "%s: joined in the OI scrub with flag %u: rc = %d\n",
1023 osd_scrub2name(scrub), flags, rc);
1028 static int osd_inode_iteration(struct osd_thread_info *info,
1029 struct osd_device *dev, __u32 max, bool preload)
1031 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1032 struct ptlrpc_thread *thread = &scrub->os_thread;
1033 struct scrub_file *sf = &scrub->os_file;
1034 osd_iit_next_policy next;
1035 osd_iit_exec_policy exec;
1038 struct osd_iit_param *param;
1039 struct l_wait_info lwi = { 0 };
1048 param = &dev->od_scrub.os_iit_param;
1049 memset(param, 0, sizeof(*param));
1050 param->sb = osd_sb(dev);
1052 while (scrub->os_partial_scan && !scrub->os_in_join) {
1053 struct osd_idmap_cache *oic = NULL;
1055 rc = osd_scrub_next(info, dev, param, &oic, noslot);
1057 case SCRUB_NEXT_EXIT:
1059 case SCRUB_NEXT_CRASH:
1060 RETURN(SCRUB_IT_CRASH);
1061 case SCRUB_NEXT_FATAL:
1063 case SCRUB_NEXT_WAIT: {
1064 struct kstatfs *ksfs = &info->oti_ksfs;
1067 if (dev->od_full_scrub_ratio == OFSR_NEVER ||
1068 unlikely(sf->sf_items_updated_prior == 0))
1071 if (dev->od_full_scrub_ratio == OFSR_DIRECTLY ||
1072 scrub->os_full_scrub) {
1073 osd_scrub_join(info->oti_env, dev,
1074 SS_AUTO_FULL | SS_RESET, true);
1078 rc = param->sb->s_op->statfs(param->sb->s_root, ksfs);
1080 __u64 used = ksfs->f_files - ksfs->f_ffree;
1082 do_div(used, sf->sf_items_updated_prior);
1083 /* If we hit too much inconsistent OI
1084 * mappings during the partial scan,
1085 * then scan the device completely. */
1086 if (used < dev->od_full_scrub_ratio) {
1087 osd_scrub_join(info->oti_env, dev,
1088 SS_AUTO_FULL | SS_RESET, true);
1094 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) &&
1098 saved_flags = sf->sf_flags;
1099 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
1100 SF_UPGRADE | SF_AUTO);
1101 sf->sf_status = SS_COMPLETED;
1102 l_wait_event(thread->t_ctl_waitq,
1103 !thread_is_running(thread) ||
1104 !scrub->os_partial_scan ||
1105 scrub->os_in_join ||
1106 !list_empty(&scrub->os_inconsistent_items),
1108 sf->sf_flags = saved_flags;
1109 sf->sf_status = SS_SCANNING;
1111 if (unlikely(!thread_is_running(thread)))
1114 if (!scrub->os_partial_scan || scrub->os_in_join)
1120 LASSERTF(rc == 0, "rc = %d\n", rc);
1122 osd_scrub_exec(info, dev, param, oic, &noslot, rc);
1129 l_wait_event(thread->t_ctl_waitq,
1130 !thread_is_running(thread) || !scrub->os_in_join,
1133 if (unlikely(!thread_is_running(thread)))
1139 next = osd_scrub_next;
1140 exec = osd_scrub_exec;
1141 pos = &scrub->os_pos_current;
1142 count = &scrub->os_new_checked;
1143 param->start = *pos;
1144 param->bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param->sb);
1146 (*pos - 1) % LDISKFS_INODES_PER_GROUP(param->sb);
1148 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1150 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1152 next = osd_preload_next;
1153 exec = osd_preload_exec;
1154 pos = &ooc->ooc_pos_preload;
1155 count = &ooc->ooc_cached_items;
1156 param = &dev->od_otable_it->ooi_iit_param;
1160 limit = le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count);
1161 while (*pos <= limit && *count < max) {
1162 struct ldiskfs_group_desc *desc;
1163 bool next_group = false;
1165 desc = ldiskfs_get_group_desc(param->sb, param->bg, NULL);
1169 if (desc->bg_flags & cpu_to_le16(LDISKFS_BG_INODE_UNINIT)) {
1174 param->bitmap = ldiskfs_read_inode_bitmap(param->sb, param->bg);
1175 if (!param->bitmap) {
1176 CERROR("%s: fail to read bitmap for %u, "
1177 "scrub will stop, urgent mode\n",
1178 osd_scrub2name(scrub), (__u32)param->bg);
1183 struct osd_idmap_cache *oic = NULL;
1186 ldiskfs_itable_unused_count(param->sb, desc) >=
1187 LDISKFS_INODES_PER_GROUP(param->sb)) {
1192 rc = next(info, dev, param, &oic, noslot);
1194 case SCRUB_NEXT_BREAK:
1197 case SCRUB_NEXT_EXIT:
1198 brelse(param->bitmap);
1200 case SCRUB_NEXT_CRASH:
1201 brelse(param->bitmap);
1202 RETURN(SCRUB_IT_CRASH);
1203 case SCRUB_NEXT_FATAL:
1204 brelse(param->bitmap);
1208 rc = exec(info, dev, param, oic, &noslot, rc);
1209 } while (!rc && *pos <= limit && *count < max);
1212 if (param->bitmap) {
1213 brelse(param->bitmap);
1214 param->bitmap = NULL;
1224 param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1225 *pos = param->gbase;
1226 param->start = *pos;
1231 RETURN(SCRUB_IT_ALL);
1237 static int osd_otable_it_preload(const struct lu_env *env,
1238 struct osd_otable_it *it)
1240 struct osd_device *dev = it->ooi_dev;
1241 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1242 struct osd_otable_cache *ooc = &it->ooi_cache;
1246 rc = osd_inode_iteration(osd_oti_get(env), dev,
1247 OSD_OTABLE_IT_CACHE_SIZE, true);
1248 if (rc == SCRUB_IT_ALL)
1249 it->ooi_all_cached = 1;
1251 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1252 spin_lock(&scrub->os_lock);
1253 scrub->os_waiting = 0;
1254 wake_up_all(&scrub->os_thread.t_ctl_waitq);
1255 spin_unlock(&scrub->os_lock);
1258 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1261 static int osd_scrub_main(void *args)
1264 struct osd_device *dev = (struct osd_device *)args;
1265 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1266 struct ptlrpc_thread *thread = &scrub->os_thread;
1270 rc = lu_env_init(&env, LCT_LOCAL | LCT_DT_THREAD);
1272 CDEBUG(D_LFSCK, "%s: OI scrub fail to init env: rc = %d\n",
1273 osd_scrub2name(scrub), rc);
1277 rc = osd_scrub_prep(&env, dev);
1279 CDEBUG(D_LFSCK, "%s: OI scrub fail to scrub prep: rc = %d\n",
1280 osd_scrub2name(scrub), rc);
1284 if (!scrub->os_full_speed && !scrub->os_partial_scan) {
1285 struct l_wait_info lwi = { 0 };
1286 struct osd_otable_it *it = dev->od_otable_it;
1287 struct osd_otable_cache *ooc = &it->ooi_cache;
1289 l_wait_event(thread->t_ctl_waitq,
1290 it->ooi_user_ready || !thread_is_running(thread),
1292 if (unlikely(!thread_is_running(thread)))
1295 scrub->os_pos_current = ooc->ooc_pos_preload;
1298 CDEBUG(D_LFSCK, "%s: OI scrub start, flags = 0x%x, pos = %llu\n",
1299 osd_scrub2name(scrub), scrub->os_start_flags,
1300 scrub->os_pos_current);
1302 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1303 if (unlikely(rc == SCRUB_IT_CRASH)) {
1304 spin_lock(&scrub->os_lock);
1305 thread_set_flags(&scrub->os_thread, SVC_STOPPING);
1306 spin_unlock(&scrub->os_lock);
1307 GOTO(out, rc = -EINVAL);
1313 rc = osd_scrub_post(&env, dev, rc);
1314 CDEBUG(D_LFSCK, "%s: OI scrub: stop, pos = %llu: rc = %d\n",
1315 osd_scrub2name(scrub), scrub->os_pos_current, rc);
1318 while (!list_empty(&scrub->os_inconsistent_items)) {
1319 struct osd_inconsistent_item *oii;
1321 oii = list_entry(scrub->os_inconsistent_items.next,
1322 struct osd_inconsistent_item, oii_list);
1323 list_del_init(&oii->oii_list);
1329 spin_lock(&scrub->os_lock);
1330 thread_set_flags(thread, SVC_STOPPED);
1331 wake_up_all(&thread->t_ctl_waitq);
1332 spin_unlock(&scrub->os_lock);
1336 /* initial OI scrub */
1338 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1339 struct dentry *, filldir_t filldir);
1341 #ifdef HAVE_FILLDIR_USE_CTX
1342 static int osd_ios_varfid_fill(struct dir_context *buf, const char *name,
1343 int namelen, loff_t offset, __u64 ino,
1345 static int osd_ios_lf_fill(struct dir_context *buf, const char *name,
1346 int namelen, loff_t offset, __u64 ino,
1348 static int osd_ios_dl_fill(struct dir_context *buf, const char *name,
1349 int namelen, loff_t offset, __u64 ino,
1351 static int osd_ios_uld_fill(struct dir_context *buf, const char *name,
1352 int namelen, loff_t offset, __u64 ino,
1355 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1356 loff_t offset, __u64 ino, unsigned d_type);
1357 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1358 loff_t offset, __u64 ino, unsigned d_type);
1359 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1360 loff_t offset, __u64 ino, unsigned d_type);
1361 static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
1362 loff_t offset, __u64 ino, unsigned d_type);
1366 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1367 struct dentry *dentry, filldir_t filldir);
1369 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1370 struct dentry *dentry, filldir_t filldir);
1373 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1374 struct dentry *dentry, filldir_t filldir);
1378 struct lu_fid olm_fid;
1381 scandir_t olm_scandir;
1382 filldir_t olm_filldir;
1385 /* Add the new introduced local files in the list in the future. */
1386 static const struct osd_lf_map osd_lf_maps[] = {
1389 .olm_name = CATLIST,
1391 .f_seq = FID_SEQ_LOCAL_FILE,
1392 .f_oid = LLOG_CATALOGS_OID,
1394 .olm_flags = OLF_SHOW_NAME,
1395 .olm_namelen = sizeof(CATLIST) - 1,
1400 .olm_name = MOUNT_CONFIGS_DIR,
1402 .f_seq = FID_SEQ_LOCAL_FILE,
1403 .f_oid = MGS_CONFIGS_OID,
1405 .olm_flags = OLF_SCAN_SUBITEMS,
1406 .olm_namelen = sizeof(MOUNT_CONFIGS_DIR) - 1,
1407 .olm_scandir = osd_ios_general_scan,
1408 .olm_filldir = osd_ios_varfid_fill,
1411 /* NIDTBL_VERSIONS */
1413 .olm_name = MGS_NIDTBL_DIR,
1414 .olm_flags = OLF_SCAN_SUBITEMS,
1415 .olm_namelen = sizeof(MGS_NIDTBL_DIR) - 1,
1416 .olm_scandir = osd_ios_general_scan,
1417 .olm_filldir = osd_ios_varfid_fill,
1422 .olm_name = "PENDING",
1423 .olm_namelen = sizeof("PENDING") - 1,
1430 .f_seq = FID_SEQ_ROOT,
1431 .f_oid = FID_OID_ROOT,
1433 .olm_flags = OLF_SCAN_SUBITEMS | OLF_HIDE_FID,
1434 .olm_namelen = sizeof("ROOT") - 1,
1435 .olm_scandir = osd_ios_ROOT_scan,
1438 /* changelog_catalog */
1440 .olm_name = CHANGELOG_CATALOG,
1441 .olm_namelen = sizeof(CHANGELOG_CATALOG) - 1,
1444 /* changelog_users */
1446 .olm_name = CHANGELOG_USERS,
1447 .olm_namelen = sizeof(CHANGELOG_USERS) - 1,
1454 .f_seq = FID_SEQ_LOCAL_FILE,
1455 .f_oid = FLD_INDEX_OID,
1457 .olm_flags = OLF_SHOW_NAME,
1458 .olm_namelen = sizeof("fld") - 1,
1463 .olm_name = LAST_RCVD,
1465 .f_seq = FID_SEQ_LOCAL_FILE,
1466 .f_oid = LAST_RECV_OID,
1468 .olm_flags = OLF_SHOW_NAME,
1469 .olm_namelen = sizeof(LAST_RCVD) - 1,
1474 .olm_name = REPLY_DATA,
1476 .f_seq = FID_SEQ_LOCAL_FILE,
1477 .f_oid = REPLY_DATA_OID,
1479 .olm_flags = OLF_SHOW_NAME,
1480 .olm_namelen = sizeof(REPLY_DATA) - 1,
1485 .olm_name = LOV_OBJID,
1487 .f_seq = FID_SEQ_LOCAL_FILE,
1488 .f_oid = MDD_LOV_OBJ_OID,
1490 .olm_flags = OLF_SHOW_NAME,
1491 .olm_namelen = sizeof(LOV_OBJID) - 1,
1496 .olm_name = LOV_OBJSEQ,
1498 .f_seq = FID_SEQ_LOCAL_FILE,
1499 .f_oid = MDD_LOV_OBJ_OSEQ,
1501 .olm_flags = OLF_SHOW_NAME,
1502 .olm_namelen = sizeof(LOV_OBJSEQ) - 1,
1507 .olm_name = QMT_DIR,
1508 .olm_flags = OLF_SCAN_SUBITEMS,
1509 .olm_namelen = sizeof(QMT_DIR) - 1,
1510 .olm_scandir = osd_ios_general_scan,
1511 .olm_filldir = osd_ios_varfid_fill,
1516 .olm_name = QSD_DIR,
1517 .olm_flags = OLF_SCAN_SUBITEMS,
1518 .olm_namelen = sizeof(QSD_DIR) - 1,
1519 .olm_scandir = osd_ios_general_scan,
1520 .olm_filldir = osd_ios_varfid_fill,
1525 .olm_name = "seq_ctl",
1527 .f_seq = FID_SEQ_LOCAL_FILE,
1528 .f_oid = FID_SEQ_CTL_OID,
1530 .olm_flags = OLF_SHOW_NAME,
1531 .olm_namelen = sizeof("seq_ctl") - 1,
1536 .olm_name = "seq_srv",
1538 .f_seq = FID_SEQ_LOCAL_FILE,
1539 .f_oid = FID_SEQ_SRV_OID,
1541 .olm_flags = OLF_SHOW_NAME,
1542 .olm_namelen = sizeof("seq_srv") - 1,
1547 .olm_name = HEALTH_CHECK,
1549 .f_seq = FID_SEQ_LOCAL_FILE,
1550 .f_oid = OFD_HEALTH_CHECK_OID,
1552 .olm_flags = OLF_SHOW_NAME,
1553 .olm_namelen = sizeof(HEALTH_CHECK) - 1,
1558 .olm_name = LFSCK_DIR,
1559 .olm_flags = OLF_SCAN_SUBITEMS,
1560 .olm_namelen = sizeof(LFSCK_DIR) - 1,
1561 .olm_scandir = osd_ios_general_scan,
1562 .olm_filldir = osd_ios_varfid_fill,
1565 /* lfsck_bookmark */
1567 .olm_name = LFSCK_BOOKMARK,
1568 .olm_namelen = sizeof(LFSCK_BOOKMARK) - 1,
1573 .olm_name = LFSCK_LAYOUT,
1574 .olm_namelen = sizeof(LFSCK_LAYOUT) - 1,
1577 /* lfsck_namespace */
1579 .olm_name = LFSCK_NAMESPACE,
1580 .olm_namelen = sizeof(LFSCK_NAMESPACE) - 1,
1583 /* OBJECTS, upgrade from old device */
1585 .olm_name = OBJECTS,
1586 .olm_flags = OLF_SCAN_SUBITEMS,
1587 .olm_namelen = sizeof(OBJECTS) - 1,
1588 .olm_scandir = osd_ios_OBJECTS_scan,
1591 /* lquota_v2.user, upgrade from old device */
1593 .olm_name = "lquota_v2.user",
1594 .olm_namelen = sizeof("lquota_v2.user") - 1,
1597 /* lquota_v2.group, upgrade from old device */
1599 .olm_name = "lquota_v2.group",
1600 .olm_namelen = sizeof("lquota_v2.group") - 1,
1603 /* LAST_GROUP, upgrade from old device */
1605 .olm_name = "LAST_GROUP",
1607 .f_seq = FID_SEQ_LOCAL_FILE,
1608 .f_oid = OFD_LAST_GROUP_OID,
1610 .olm_flags = OLF_SHOW_NAME,
1611 .olm_namelen = sizeof("LAST_GROUP") - 1,
1614 /* committed batchid for cross-MDT operation */
1616 .olm_name = "BATCHID",
1618 .f_seq = FID_SEQ_LOCAL_FILE,
1619 .f_oid = BATCHID_COMMITTED_OID,
1621 .olm_flags = OLF_SHOW_NAME,
1622 .olm_namelen = sizeof("BATCHID") - 1,
1625 /* OSP update logs update_log{_dir} use f_seq = FID_SEQ_UPDATE_LOG{_DIR}
1626 * and f_oid = index for their log files. See lu_update_log{_dir}_fid()
1627 * for more details. */
1631 .olm_name = "update_log",
1633 .f_seq = FID_SEQ_UPDATE_LOG,
1635 .olm_flags = OLF_SHOW_NAME | OLF_IDX_IN_FID,
1636 .olm_namelen = sizeof("update_log") - 1,
1639 /* update_log_dir */
1641 .olm_name = "update_log_dir",
1643 .f_seq = FID_SEQ_UPDATE_LOG_DIR,
1645 .olm_flags = OLF_SHOW_NAME | OLF_SCAN_SUBITEMS |
1647 .olm_namelen = sizeof("update_log_dir") - 1,
1648 .olm_scandir = osd_ios_general_scan,
1649 .olm_filldir = osd_ios_uld_fill,
1654 .olm_name = "lost+found",
1656 .f_seq = FID_SEQ_LOCAL_FILE,
1657 .f_oid = OSD_LPF_OID,
1659 .olm_flags = OLF_SCAN_SUBITEMS,
1660 .olm_namelen = sizeof("lost+found") - 1,
1661 .olm_scandir = osd_ios_general_scan,
1662 .olm_filldir = osd_ios_lf_fill,
1667 .olm_name = HSM_ACTIONS,
1672 .olm_name = LUSTRE_NODEMAP_NAME,
1677 .olm_name = INDEX_BACKUP_DIR,
1679 .f_seq = FID_SEQ_LOCAL_FILE,
1680 .f_oid = INDEX_BACKUP_OID,
1682 .olm_flags = OLF_SCAN_SUBITEMS | OLF_NOT_BACKUP,
1683 .olm_namelen = sizeof(INDEX_BACKUP_DIR) - 1,
1684 .olm_scandir = osd_ios_general_scan,
1685 .olm_filldir = osd_ios_varfid_fill,
1693 /* Add the new introduced files under .lustre/ in the list in the future. */
1694 static const struct osd_lf_map osd_dl_maps[] = {
1699 .f_seq = FID_SEQ_DOT_LUSTRE,
1700 .f_oid = FID_OID_DOT_LUSTRE_OBF,
1702 .olm_namelen = sizeof("fid") - 1,
1705 /* .lustre/lost+found */
1707 .olm_name = "lost+found",
1709 .f_seq = FID_SEQ_DOT_LUSTRE,
1710 .f_oid = FID_OID_DOT_LUSTRE_LPF,
1712 .olm_namelen = sizeof("lost+found") - 1,
1720 struct osd_ios_item {
1721 struct list_head oii_list;
1722 struct dentry *oii_dentry;
1723 scandir_t oii_scandir;
1724 filldir_t oii_filldir;
1727 struct osd_ios_filldir_buf {
1728 #ifdef HAVE_DIR_CONTEXT
1729 /* please keep it as first member */
1730 struct dir_context ctx;
1732 struct osd_thread_info *oifb_info;
1733 struct osd_device *oifb_dev;
1734 struct dentry *oifb_dentry;
1738 static inline struct dentry *
1739 osd_ios_lookup_one_len(const char *name, struct dentry *parent, int namelen)
1741 struct dentry *dentry;
1743 dentry = ll_lookup_one_len(name, parent, namelen);
1744 if (IS_ERR(dentry)) {
1745 int rc = PTR_ERR(dentry);
1748 CERROR("Fail to find %.*s in %.*s (%lu/%u): rc = %d\n",
1749 namelen, name, parent->d_name.len,
1750 parent->d_name.name, parent->d_inode->i_ino,
1751 parent->d_inode->i_generation, rc);
1756 if (dentry->d_inode == NULL) {
1758 return ERR_PTR(-ENOENT);
1765 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1766 scandir_t scandir, filldir_t filldir)
1768 struct osd_ios_item *item;
1771 OBD_ALLOC_PTR(item);
1775 INIT_LIST_HEAD(&item->oii_list);
1776 item->oii_dentry = dget(dentry);
1777 item->oii_scandir = scandir;
1778 item->oii_filldir = filldir;
1779 list_add_tail(&item->oii_list, &dev->od_ios_list);
1784 static bool osd_index_need_recreate(const struct lu_env *env,
1785 struct osd_device *dev, struct inode *inode)
1787 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1788 struct iam_container *bag = &iam->od_container;
1792 rc = iam_container_init(bag, &iam->od_descr, inode);
1796 rc = iam_container_setup(bag);
1797 iam_container_fini(bag);
1804 static void osd_ios_index_register(const struct lu_env *env,
1805 struct osd_device *osd,
1806 const struct lu_fid *fid,
1807 struct inode *inode)
1809 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1810 struct iam_container *bag = &iam->od_container;
1811 struct super_block *sb = osd_sb(osd);
1812 struct iam_descr *descr;
1818 /* Index must be a regular file. */
1819 if (!S_ISREG(inode->i_mode))
1822 /* Index's size must be block aligned. */
1823 if (inode->i_size < sb->s_blocksize ||
1824 (inode->i_size & (sb->s_blocksize - 1)) != 0)
1827 iam_container_init(bag, &iam->od_descr, inode);
1828 rc = iam_container_setup(bag);
1832 descr = bag->ic_descr;
1833 /* May be regular file with IAM_LFIX_ROOT_MAGIC matched
1834 * coincidentally, or corrupted index object, skip it. */
1835 if (descr->id_ptr_size != 4)
1838 keysize = descr->id_key_size;
1839 recsize = descr->id_rec_size;
1840 rc = osd_index_register(osd, fid, keysize, recsize);
1845 iam_container_fini(bag);
1847 CDEBUG(D_LFSCK, "%s: index object "DFID" (%u/%u) registered\n",
1848 osd_name(osd), PFID(fid), keysize, recsize);
1851 static void osd_index_restore(const struct lu_env *env, struct osd_device *dev,
1852 struct lustre_index_restore_unit *liru,
1853 void *buf, int bufsize)
1855 struct osd_thread_info *info = osd_oti_get(env);
1856 struct osd_inode_id *id = &info->oti_id;
1857 struct lu_fid *tgt_fid = &liru->liru_cfid;
1858 struct inode *bak_inode = NULL;
1859 struct ldiskfs_dir_entry_2 *de = NULL;
1860 struct buffer_head *bh = NULL;
1861 struct dentry *dentry;
1863 struct lu_fid bak_fid;
1867 lustre_fid2lbx(name, tgt_fid, bufsize);
1868 dentry = osd_child_dentry_by_inode(env, dev->od_index_backup_inode,
1869 name, strlen(name));
1870 bh = osd_ldiskfs_find_entry(dev->od_index_backup_inode,
1871 &dentry->d_name, &de, NULL, NULL);
1873 GOTO(log, rc = PTR_ERR(bh));
1875 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
1877 bak_inode = osd_iget_fid(info, dev, id, &bak_fid);
1878 if (IS_ERR(bak_inode))
1879 GOTO(log, rc = PTR_ERR(bak_inode));
1882 /* The OI mapping for index may be invalid, since it will be
1883 * re-created, not update the OI mapping, just cache it in RAM. */
1884 osd_id_gen(id, liru->liru_clid, OSD_OII_NOGEN);
1885 osd_add_oi_cache(info, dev, id, tgt_fid);
1886 rc = lustre_index_restore(env, &dev->od_dt_dev, &liru->liru_pfid,
1887 tgt_fid, &bak_fid, liru->liru_name,
1888 &dev->od_index_backup_list, &dev->od_lock,
1893 CDEBUG(D_WARNING, "%s: restore index '%s' with "DFID": rc = %d\n",
1894 osd_name(dev), liru->liru_name, PFID(tgt_fid), rc);
1898 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1900 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1901 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1902 * reference the inode, or fixed if it is missing or references another inode.
1905 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1906 struct inode *parent, struct inode *inode,
1907 const struct lu_fid *fid, const char *name,
1908 int namelen, int flags)
1910 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1911 struct osd_inode_id *id = &info->oti_id;
1912 struct osd_inode_id *id2 = &info->oti_id2;
1913 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1914 struct scrub_file *sf = &scrub->os_file;
1919 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
1920 &info->oti_ost_attrs);
1921 if (rc != 0 && rc != -ENODATA) {
1922 CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
1923 "rc = %d\n", osd_name(dev), rc);
1928 osd_id_gen(id, inode->i_ino, inode->i_generation);
1929 if (rc == -ENODATA) {
1930 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID) {
1931 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1934 if (flags & OLF_IDX_IN_FID) {
1935 LASSERT(dev->od_index >= 0);
1937 tfid.f_oid = dev->od_index;
1940 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1942 CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
1943 "scrub: rc = %d\n", osd_name(dev), rc);
1948 if (lma->lma_compat & LMAC_NOT_IN_OI)
1951 tfid = lma->lma_self_fid;
1952 if (lma->lma_compat & LMAC_IDX_BACKUP &&
1953 osd_index_need_recreate(info->oti_env, dev, inode)) {
1954 struct lu_fid *pfid = &info->oti_fid3;
1956 if (parent == osd_sb(dev)->s_root->d_inode) {
1957 lu_local_obj_fid(pfid, OSD_FS_ROOT_OID);
1959 rc = osd_scrub_get_fid(info, dev, parent, pfid,
1965 rc = lustre_liru_new(&dev->od_index_restore_list, pfid,
1966 &tfid, inode->i_ino, name, namelen);
1971 if (!(flags & OLF_NOT_BACKUP))
1972 osd_ios_index_register(info->oti_env, dev, &tfid,
1976 rc = osd_oi_lookup(info, dev, &tfid, id2, 0);
1981 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1982 DTO_INDEX_INSERT, true, 0, NULL);
1989 if (osd_id_eq_strict(id, id2))
1992 if (!(sf->sf_flags & SF_INCONSISTENT)) {
1993 scrub_file_reset(scrub, LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
1995 rc = scrub_file_store(info->oti_env, scrub);
2000 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
2001 DTO_INDEX_UPDATE, true, 0, NULL);
2009 * It scans the /lost+found, and for the OST-object (with filter_fid
2010 * or filter_fid_old), move them back to its proper /O/<seq>/d<x>.
2012 #ifdef HAVE_FILLDIR_USE_CTX
2013 static int osd_ios_lf_fill(struct dir_context *buf,
2015 static int osd_ios_lf_fill(void *buf,
2017 const char *name, int namelen,
2018 loff_t offset, __u64 ino, unsigned d_type)
2020 struct osd_ios_filldir_buf *fill_buf =
2021 (struct osd_ios_filldir_buf *)buf;
2022 struct osd_thread_info *info = fill_buf->oifb_info;
2023 struct osd_device *dev = fill_buf->oifb_dev;
2024 struct lu_fid *fid = &info->oti_fid;
2025 struct osd_scrub *scrub = &dev->od_scrub;
2026 struct dentry *parent = fill_buf->oifb_dentry;
2027 struct dentry *child;
2028 struct inode *dir = parent->d_inode;
2029 struct inode *inode;
2033 fill_buf->oifb_items++;
2035 /* skip any '.' started names */
2039 scrub->os_lf_scanned++;
2040 child = osd_ios_lookup_one_len(name, parent, namelen);
2041 if (IS_ERR(child)) {
2042 CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
2043 osd_name(dev), namelen, name, (int)PTR_ERR(child));
2047 inode = child->d_inode;
2048 if (S_ISDIR(inode->i_mode)) {
2049 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2052 CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
2053 "rc = %d\n", osd_name(dev), namelen, name, rc);
2057 if (!S_ISREG(inode->i_mode))
2060 rc = osd_scrub_get_fid(info, dev, inode, fid, true);
2061 if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
2062 rc = osd_obj_map_recover(info, dev, dir, child, fid);
2064 CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
2065 "/lost+found.\n", namelen, name, PFID(fid));
2066 scrub->os_lf_repaired++;
2068 CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
2070 osd_name(dev), namelen, name, PFID(fid), rc);
2074 /* XXX: For MDT-objects, we can move them from /lost+found to namespace
2075 * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
2076 * can process them in furtuer. */
2082 scrub->os_lf_failed++;
2084 /* skip the failure to make the scanning to continue. */
2088 #ifdef HAVE_FILLDIR_USE_CTX
2089 static int osd_ios_varfid_fill(struct dir_context *buf,
2091 static int osd_ios_varfid_fill(void *buf,
2093 const char *name, int namelen,
2094 loff_t offset, __u64 ino, unsigned d_type)
2096 struct osd_ios_filldir_buf *fill_buf =
2097 (struct osd_ios_filldir_buf *)buf;
2098 struct osd_device *dev = fill_buf->oifb_dev;
2099 struct dentry *child;
2103 fill_buf->oifb_items++;
2105 /* skip any '.' started names */
2109 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
2111 RETURN(PTR_ERR(child));
2113 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2114 fill_buf->oifb_dentry->d_inode, child->d_inode,
2115 NULL, name, namelen, 0);
2116 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
2117 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2118 osd_ios_varfid_fill);
2124 #ifdef HAVE_FILLDIR_USE_CTX
2125 static int osd_ios_dl_fill(struct dir_context *buf,
2127 static int osd_ios_dl_fill(void *buf,
2129 const char *name, int namelen,
2130 loff_t offset, __u64 ino, unsigned d_type)
2132 struct osd_ios_filldir_buf *fill_buf =
2133 (struct osd_ios_filldir_buf *)buf;
2134 struct osd_device *dev = fill_buf->oifb_dev;
2135 const struct osd_lf_map *map;
2136 struct dentry *child;
2140 fill_buf->oifb_items++;
2142 /* skip any '.' started names */
2146 for (map = osd_dl_maps; map->olm_name != NULL; map++) {
2147 if (map->olm_namelen != namelen)
2150 if (strncmp(map->olm_name, name, namelen) == 0)
2154 if (map->olm_name == NULL)
2157 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
2159 RETURN(PTR_ERR(child));
2161 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2162 fill_buf->oifb_dentry->d_inode, child->d_inode,
2163 &map->olm_fid, name, namelen, map->olm_flags);
2169 #ifdef HAVE_FILLDIR_USE_CTX
2170 static int osd_ios_uld_fill(struct dir_context *buf,
2172 static int osd_ios_uld_fill(void *buf,
2174 const char *name, int namelen,
2175 loff_t offset, __u64 ino, unsigned d_type)
2177 struct osd_ios_filldir_buf *fill_buf =
2178 (struct osd_ios_filldir_buf *)buf;
2179 struct dentry *child;
2184 fill_buf->oifb_items++;
2186 /* skip any non-DFID format name */
2190 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
2192 RETURN(PTR_ERR(child));
2194 /* skip the start '[' */
2195 sscanf(&name[1], SFID, RFID(&tfid));
2196 if (fid_is_sane(&tfid))
2197 rc = osd_ios_scan_one(fill_buf->oifb_info, fill_buf->oifb_dev,
2198 fill_buf->oifb_dentry->d_inode,
2199 child->d_inode, &tfid, name, namelen, 0);
2207 #ifdef HAVE_FILLDIR_USE_CTX
2208 static int osd_ios_root_fill(struct dir_context *buf,
2210 static int osd_ios_root_fill(void *buf,
2212 const char *name, int namelen,
2213 loff_t offset, __u64 ino, unsigned d_type)
2215 struct osd_ios_filldir_buf *fill_buf =
2216 (struct osd_ios_filldir_buf *)buf;
2217 struct osd_device *dev = fill_buf->oifb_dev;
2218 const struct osd_lf_map *map;
2219 struct dentry *child;
2223 fill_buf->oifb_items++;
2225 /* skip any '.' started names */
2229 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
2230 if (map->olm_namelen != namelen)
2233 if (strncmp(map->olm_name, name, namelen) == 0)
2237 if (map->olm_name == NULL)
2240 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
2242 RETURN(PTR_ERR(child));
2244 if (!(map->olm_flags & OLF_NO_OI))
2245 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2246 fill_buf->oifb_dentry->d_inode, child->d_inode,
2247 &map->olm_fid, name, namelen, map->olm_flags);
2248 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
2249 rc = osd_ios_new_item(dev, child, map->olm_scandir,
2257 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
2258 struct dentry *dentry, filldir_t filldir)
2260 struct osd_ios_filldir_buf buf = {
2261 #ifdef HAVE_DIR_CONTEXT
2262 .ctx.actor = filldir,
2266 .oifb_dentry = dentry };
2267 struct file *filp = &info->oti_file;
2268 struct inode *inode = dentry->d_inode;
2269 const struct file_operations *fops = inode->i_fop;
2273 LASSERT(filldir != NULL);
2276 filp->f_path.dentry = dentry;
2277 filp->f_mode = FMODE_64BITHASH;
2278 filp->f_mapping = inode->i_mapping;
2280 filp->private_data = NULL;
2281 set_file_inode(filp, inode);
2285 #ifdef HAVE_DIR_CONTEXT
2286 buf.ctx.pos = filp->f_pos;
2287 #ifdef HAVE_ITERATE_SHARED
2288 rc = fops->iterate_shared(filp, &buf.ctx);
2290 rc = fops->iterate(filp, &buf.ctx);
2292 filp->f_pos = buf.ctx.pos;
2294 rc = fops->readdir(filp, &buf, filldir);
2296 } while (rc >= 0 && buf.oifb_items > 0 &&
2297 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
2298 fops->release(inode, filp);
2304 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
2305 struct dentry *dentry, filldir_t filldir)
2307 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2308 struct scrub_file *sf = &scrub->os_file;
2309 struct dentry *child;
2313 /* It is existing MDT0 device. We only allow the case of object without
2314 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
2315 * can generate IGIF mode FID for the object and related OI mapping. If
2316 * it is on other MDTs, then becuase file-level backup/restore, related
2317 * OI mapping may be invalid already, we do not know which is the right
2318 * FID for the object. We only allow IGIF objects to reside on the MDT0.
2320 * XXX: For the case of object on non-MDT0 device with neither LMA nor
2321 * "fid" xattr, then something crashed. We cannot re-generate the
2322 * FID directly, instead, the OI scrub will scan the OI structure
2323 * and try to re-generate the LMA from the OI mapping. But if the
2324 * OI mapping crashed or lost also, then we have to give up under
2325 * double failure cases. */
2326 scrub->os_convert_igif = 1;
2327 child = osd_ios_lookup_one_len(dot_lustre_name, dentry,
2328 strlen(dot_lustre_name));
2329 if (IS_ERR(child)) {
2330 rc = PTR_ERR(child);
2331 if (rc == -ENOENT) {
2332 /* It is 1.8 MDT device. */
2333 if (!(sf->sf_flags & SF_UPGRADE)) {
2334 scrub_file_reset(scrub,
2335 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
2337 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2338 rc = scrub_file_store(info->oti_env, scrub);
2344 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
2345 * so the client will get IGIF for the ".lustre" object when
2348 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
2349 * it does not know whether there are some old clients cached
2350 * the ".lustre" IGIF during the upgrading. Two choices:
2352 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
2353 * It will allow the old connected clients to access the
2354 * ".lustre" with cached IGIF. But it will cause others
2355 * on the MDT failed to check "fid_is_dot_lustre()".
2357 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
2358 * for ".lustre" in spite of whether there are some clients
2359 * cached the ".lustre" IGIF or not. It enables the check
2360 * "fid_is_dot_lustre()" on the MDT, although it will cause
2361 * that the old connected clients cannot access the ".lustre"
2362 * with the cached IGIF.
2364 * Usually, it is rare case for the old connected clients
2365 * to access the ".lustre" with cached IGIF. So we prefer
2366 * to the solution 2). */
2367 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2368 child->d_inode, &LU_DOT_LUSTRE_FID,
2370 strlen(dot_lustre_name), 0);
2372 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2381 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
2382 struct dentry *dentry, filldir_t filldir)
2384 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2385 struct scrub_file *sf = &scrub->os_file;
2386 struct dentry *child;
2390 if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
2391 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2392 rc = scrub_file_store(info->oti_env, scrub);
2397 child = osd_ios_lookup_one_len(ADMIN_USR, dentry, strlen(ADMIN_USR));
2398 if (!IS_ERR(child)) {
2399 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2400 child->d_inode, NULL, ADMIN_USR,
2401 strlen(ADMIN_USR), 0);
2404 rc = PTR_ERR(child);
2407 if (rc != 0 && rc != -ENOENT)
2410 child = osd_ios_lookup_one_len(ADMIN_GRP, dentry, strlen(ADMIN_GRP));
2411 if (!IS_ERR(child)) {
2412 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2413 child->d_inode, NULL, ADMIN_GRP,
2414 strlen(ADMIN_GRP), 0);
2417 rc = PTR_ERR(child);
2426 static void osd_initial_OI_scrub(struct osd_thread_info *info,
2427 struct osd_device *dev)
2429 struct osd_ios_item *item = NULL;
2430 scandir_t scandir = osd_ios_general_scan;
2431 filldir_t filldir = osd_ios_root_fill;
2432 struct dentry *dentry = osd_sb(dev)->s_root;
2433 const struct osd_lf_map *map = osd_lf_maps;
2436 /* Lookup IGIF in OI by force for initial OI scrub. */
2437 dev->od_igif_inoi = 1;
2440 scandir(info, dev, dentry, filldir);
2442 dput(item->oii_dentry);
2446 if (list_empty(&dev->od_ios_list))
2449 item = list_entry(dev->od_ios_list.next,
2450 struct osd_ios_item, oii_list);
2451 list_del_init(&item->oii_list);
2453 LASSERT(item->oii_scandir != NULL);
2454 scandir = item->oii_scandir;
2455 filldir = item->oii_filldir;
2456 dentry = item->oii_dentry;
2459 /* There maybe the case that the object has been removed, but its OI
2460 * mapping is still in the OI file, such as the "CATALOGS" after MDT
2461 * file-level backup/restore. So here cleanup the stale OI mappings. */
2462 while (map->olm_name != NULL) {
2463 struct dentry *child;
2465 if (fid_is_zero(&map->olm_fid)) {
2470 child = osd_ios_lookup_one_len(map->olm_name,
2471 osd_sb(dev)->s_root,
2475 else if (PTR_ERR(child) == -ENOENT)
2476 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
2477 NULL, DTO_INDEX_DELETE,
2482 if (!list_empty(&dev->od_index_restore_list)) {
2485 OBD_ALLOC_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2487 CERROR("%s: not enough RAM for rebuild index\n",
2490 while (!list_empty(&dev->od_index_restore_list)) {
2491 struct lustre_index_restore_unit *liru;
2493 liru = list_entry(dev->od_index_restore_list.next,
2494 struct lustre_index_restore_unit,
2496 list_del(&liru->liru_link);
2498 osd_index_restore(info->oti_env, dev, liru,
2499 buf, INDEX_BACKUP_BUFSIZE);
2500 OBD_FREE(liru, liru->liru_len);
2504 OBD_FREE_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2510 char *osd_lf_fid2name(const struct lu_fid *fid)
2512 const struct osd_lf_map *map = osd_lf_maps;
2514 while (map->olm_name != NULL) {
2515 if (!lu_fid_eq(fid, &map->olm_fid)) {
2520 if (map->olm_flags & OLF_SHOW_NAME)
2521 return map->olm_name;
2529 /* OI scrub start/stop */
2531 int osd_scrub_start(const struct lu_env *env, struct osd_device *dev,
2534 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2538 if (dev->od_dt_dev.dd_rdonly)
2541 /* od_otable_mutex: prevent curcurrent start/stop */
2542 mutex_lock(&dev->od_otable_mutex);
2543 rc = scrub_start(osd_scrub_main, scrub, dev, flags);
2544 if (rc == -EALREADY) {
2546 if ((scrub->os_file.sf_flags & SF_AUTO ||
2547 scrub->os_partial_scan) &&
2548 !(flags & SS_AUTO_PARTIAL))
2549 osd_scrub_join(env, dev, flags, false);
2551 mutex_unlock(&dev->od_otable_mutex);
2556 void osd_scrub_stop(struct osd_device *dev)
2558 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2560 /* od_otable_mutex: prevent curcurrent start/stop */
2561 mutex_lock(&dev->od_otable_mutex);
2562 scrub->os_paused = 1;
2564 mutex_unlock(&dev->od_otable_mutex);
2567 /* OI scrub setup/cleanup */
2569 static const char osd_scrub_name[] = "OI_scrub";
2571 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
2573 struct osd_thread_info *info = osd_oti_get(env);
2574 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2575 struct lvfs_run_ctxt *ctxt = &dev->od_scrub.os_ctxt;
2576 struct scrub_file *sf = &scrub->os_file;
2577 struct super_block *sb = osd_sb(dev);
2578 struct ldiskfs_super_block *es = LDISKFS_SB(sb)->s_es;
2579 struct lvfs_run_ctxt saved;
2581 struct inode *inode;
2582 struct lu_fid *fid = &info->oti_fid;
2583 struct osd_inode_id *id = &info->oti_id;
2584 struct dt_object *obj;
2586 bool restored = false;
2590 memset(&dev->od_scrub, 0, sizeof(struct osd_scrub));
2591 OBD_SET_CTXT_MAGIC(ctxt);
2592 ctxt->pwdmnt = dev->od_mnt;
2593 ctxt->pwd = dev->od_mnt->mnt_root;
2594 ctxt->fs = get_ds();
2596 init_waitqueue_head(&scrub->os_thread.t_ctl_waitq);
2597 init_rwsem(&scrub->os_rwsem);
2598 spin_lock_init(&scrub->os_lock);
2599 INIT_LIST_HEAD(&scrub->os_inconsistent_items);
2600 scrub->os_name = osd_name(dev);
2602 push_ctxt(&saved, ctxt);
2603 filp = filp_open(osd_scrub_name, O_RDWR |
2604 (dev->od_dt_dev.dd_rdonly ? 0 : O_CREAT), 0644);
2606 pop_ctxt(&saved, ctxt);
2607 RETURN(PTR_ERR(filp));
2610 inode = file_inode(filp);
2611 if (!dev->od_dt_dev.dd_rdonly) {
2612 /* 'What the @fid is' is not imporatant, because the object
2613 * has no OI mapping, and only is visible inside the OSD.*/
2614 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2615 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
2617 filp_close(filp, NULL);
2618 pop_ctxt(&saved, ctxt);
2623 osd_id_gen(id, inode->i_ino, inode->i_generation);
2624 osd_add_oi_cache(info, dev, id, fid);
2625 filp_close(filp, NULL);
2626 pop_ctxt(&saved, ctxt);
2628 obj = lu2dt(lu_object_find_slice(env, osd2lu_dev(dev), fid, NULL));
2629 if (IS_ERR_OR_NULL(obj))
2630 RETURN(obj ? PTR_ERR(obj) : -ENOENT);
2632 scrub->os_obj = obj;
2633 rc = scrub_file_load(env, scrub);
2634 if (rc == -ENOENT || rc == -EFAULT) {
2635 scrub_file_init(scrub, es->s_uuid);
2636 /* If the "/O" dir does not exist when mount (indicated by
2637 * osd_device::od_maybe_new), neither for the "/OI_scrub",
2638 * then it is quite probably that the device is a new one,
2639 * under such case, mark it as SIF_NO_HANDLE_OLD_FID.
2641 * For the rare case that "/O" and "OI_scrub" both lost on
2642 * an old device, it can be found and cleared later.
2644 * For the system with "SIF_NO_HANDLE_OLD_FID", we do not
2645 * need to check "filter_fid_old" and to convert it to
2646 * "filter_fid" for each object, and all the IGIF should
2647 * have their FID mapping in OI files already. */
2648 if (dev->od_maybe_new && rc == -ENOENT)
2649 sf->sf_internal_flags = SIF_NO_HANDLE_OLD_FID;
2651 } else if (rc < 0) {
2652 GOTO(cleanup_obj, rc);
2654 if (memcmp(sf->sf_uuid, es->s_uuid, 16) != 0) {
2655 struct obd_uuid *old_uuid;
2656 struct obd_uuid *new_uuid;
2658 OBD_ALLOC_PTR(old_uuid);
2659 OBD_ALLOC_PTR(new_uuid);
2660 if (old_uuid == NULL || new_uuid == NULL) {
2661 CERROR("%s: UUID has been changed, but"
2662 "failed to allocate RAM for report\n",
2665 class_uuid_unparse(sf->sf_uuid, old_uuid);
2666 class_uuid_unparse(es->s_uuid, new_uuid);
2667 CDEBUG(D_LFSCK, "%s: UUID has been changed "
2668 "from %s to %s\n", osd_dev2name(dev),
2669 old_uuid->uuid, new_uuid->uuid);
2671 scrub_file_reset(scrub, es->s_uuid, SF_INCONSISTENT);
2674 if (old_uuid != NULL)
2675 OBD_FREE_PTR(old_uuid);
2676 if (new_uuid != NULL)
2677 OBD_FREE_PTR(new_uuid);
2678 } else if (sf->sf_status == SS_SCANNING) {
2679 sf->sf_status = SS_CRASHED;
2683 if ((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) {
2684 LCONSOLE_WARN("%s: invalid oi count %d, set it to %d\n",
2685 osd_dev2name(dev), sf->sf_oi_count,
2687 sf->sf_oi_count = osd_oi_count;
2692 if (sf->sf_pos_last_checkpoint != 0)
2693 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
2695 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
2698 rc = scrub_file_store(env, scrub);
2700 GOTO(cleanup_obj, rc);
2703 /* Initialize OI files. */
2704 rc = osd_oi_init(info, dev, restored);
2706 GOTO(cleanup_obj, rc);
2708 if (!dev->od_dt_dev.dd_rdonly)
2709 osd_initial_OI_scrub(info, dev);
2711 if (sf->sf_flags & SF_UPGRADE ||
2712 !(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID ||
2713 sf->sf_success_count > 0)) {
2714 dev->od_igif_inoi = 0;
2715 dev->od_check_ff = dev->od_is_ost;
2717 dev->od_igif_inoi = 1;
2718 dev->od_check_ff = 0;
2721 if (sf->sf_flags & SF_INCONSISTENT)
2722 /* The 'od_igif_inoi' will be set under the
2724 * 1) new created system, or
2725 * 2) restored from file-level backup, or
2726 * 3) the upgrading completed.
2728 * The 'od_igif_inoi' may be cleared by OI scrub
2729 * later if found that the system is upgrading. */
2730 dev->od_igif_inoi = 1;
2732 if (!dev->od_dt_dev.dd_rdonly &&
2733 dev->od_auto_scrub_interval != AS_NEVER &&
2734 ((sf->sf_status == SS_PAUSED) ||
2735 (sf->sf_status == SS_CRASHED &&
2736 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2737 SF_UPGRADE | SF_AUTO)) ||
2738 (sf->sf_status == SS_INIT &&
2739 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2741 rc = osd_scrub_start(env, dev, SS_AUTO_FULL);
2744 GOTO(cleanup_oi, rc);
2746 /* it is possible that dcache entries may keep objects after they are
2747 * deleted by OSD. While it looks safe this can cause object data to
2748 * stay until umount causing failures in tests calculating free space,
2749 * e.g. replay-ost-single. Since those dcache entries are not used
2750 * anymore let's just free them after use here */
2751 shrink_dcache_sb(sb);
2755 osd_oi_fini(info, dev);
2757 dt_object_put_nocache(env, scrub->os_obj);
2758 scrub->os_obj = NULL;
2763 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
2765 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2767 LASSERT(dev->od_otable_it == NULL);
2769 if (scrub->os_obj != NULL) {
2770 osd_scrub_stop(dev);
2771 dt_object_put_nocache(env, scrub->os_obj);
2772 scrub->os_obj = NULL;
2774 if (dev->od_oi_table != NULL)
2775 osd_oi_fini(osd_oti_get(env), dev);
2778 /* object table based iteration APIs */
2780 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
2781 struct dt_object *dt, __u32 attr)
2783 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
2784 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
2785 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
2786 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2787 struct osd_otable_it *it;
2792 /* od_otable_mutex: prevent curcurrent init/fini */
2793 mutex_lock(&dev->od_otable_mutex);
2794 if (dev->od_otable_it != NULL)
2795 GOTO(out, it = ERR_PTR(-EALREADY));
2799 GOTO(out, it = ERR_PTR(-ENOMEM));
2801 dev->od_otable_it = it;
2803 it->ooi_cache.ooc_consumer_idx = -1;
2804 if (flags & DOIF_OUTUSED)
2805 it->ooi_used_outside = 1;
2807 if (flags & DOIF_RESET)
2810 if (valid & DOIV_ERROR_HANDLE) {
2811 if (flags & DOIF_FAILOUT)
2812 start |= SS_SET_FAILOUT;
2814 start |= SS_CLEAR_FAILOUT;
2817 if (valid & DOIV_DRYRUN) {
2818 if (flags & DOIF_DRYRUN)
2819 start |= SS_SET_DRYRUN;
2821 start |= SS_CLEAR_DRYRUN;
2824 rc = scrub_start(osd_scrub_main, scrub, dev, start & ~SS_AUTO_PARTIAL);
2825 if (rc == -EALREADY) {
2826 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2827 } else if (rc < 0) {
2828 dev->od_otable_it = NULL;
2832 /* We have to start from the begining. */
2833 it->ooi_cache.ooc_pos_preload =
2834 LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2840 mutex_unlock(&dev->od_otable_mutex);
2841 return (struct dt_it *)it;
2844 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2846 struct osd_otable_it *it = (struct osd_otable_it *)di;
2847 struct osd_device *dev = it->ooi_dev;
2849 /* od_otable_mutex: prevent curcurrent init/fini */
2850 mutex_lock(&dev->od_otable_mutex);
2851 scrub_stop(&dev->od_scrub.os_scrub);
2852 LASSERT(dev->od_otable_it == it);
2854 dev->od_otable_it = NULL;
2855 mutex_unlock(&dev->od_otable_mutex);
2859 static int osd_otable_it_get(const struct lu_env *env,
2860 struct dt_it *di, const struct dt_key *key)
2865 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2870 osd_otable_it_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
2872 spin_lock(&scrub->os_lock);
2873 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2874 scrub->os_waiting ||
2875 !thread_is_running(&scrub->os_thread))
2876 it->ooi_waiting = 0;
2878 it->ooi_waiting = 1;
2879 spin_unlock(&scrub->os_lock);
2881 return !it->ooi_waiting;
2884 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2886 struct osd_otable_it *it = (struct osd_otable_it *)di;
2887 struct osd_device *dev = it->ooi_dev;
2888 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2889 struct osd_otable_cache *ooc = &it->ooi_cache;
2890 struct ptlrpc_thread *thread = &scrub->os_thread;
2891 struct l_wait_info lwi = { 0 };
2895 LASSERT(it->ooi_user_ready);
2898 if (!thread_is_running(thread) && !it->ooi_used_outside)
2901 if (ooc->ooc_cached_items > 0) {
2902 ooc->ooc_cached_items--;
2903 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2904 ~OSD_OTABLE_IT_CACHE_MASK;
2908 if (it->ooi_all_cached) {
2909 l_wait_event(thread->t_ctl_waitq,
2910 !thread_is_running(thread),
2915 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2916 spin_lock(&scrub->os_lock);
2917 scrub->os_waiting = 0;
2918 wake_up_all(&scrub->os_thread.t_ctl_waitq);
2919 spin_unlock(&scrub->os_lock);
2922 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2923 l_wait_event(thread->t_ctl_waitq,
2924 osd_otable_it_wakeup(scrub, it),
2927 if (!thread_is_running(thread) && !it->ooi_used_outside)
2930 rc = osd_otable_it_preload(env, it);
2937 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2938 const struct dt_it *di)
2943 static int osd_otable_it_key_size(const struct lu_env *env,
2944 const struct dt_it *di)
2946 return sizeof(__u64);
2949 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2950 struct dt_rec *rec, __u32 attr)
2952 struct osd_otable_it *it = (struct osd_otable_it *)di;
2953 struct osd_otable_cache *ooc = &it->ooi_cache;
2955 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2957 /* Filter out Invald FID already. */
2958 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2959 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2960 PFID((struct lu_fid *)rec),
2961 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2966 static __u64 osd_otable_it_store(const struct lu_env *env,
2967 const struct dt_it *di)
2969 struct osd_otable_it *it = (struct osd_otable_it *)di;
2970 struct osd_otable_cache *ooc = &it->ooi_cache;
2973 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2974 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2976 hash = ooc->ooc_pos_preload;
2981 * Set the OSD layer iteration start position as the specified hash.
2983 static int osd_otable_it_load(const struct lu_env *env,
2984 const struct dt_it *di, __u64 hash)
2986 struct osd_otable_it *it = (struct osd_otable_it *)di;
2987 struct osd_device *dev = it->ooi_dev;
2988 struct osd_otable_cache *ooc = &it->ooi_cache;
2989 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2990 struct osd_iit_param *param = &it->ooi_iit_param;
2994 /* Forbid to set iteration position after iteration started. */
2995 if (it->ooi_user_ready)
2998 LASSERT(!scrub->os_partial_scan);
3000 if (hash > OSD_OTABLE_MAX_HASH)
3001 hash = OSD_OTABLE_MAX_HASH;
3003 /* The hash is the last checkpoint position,
3004 * we will start from the next one. */
3005 ooc->ooc_pos_preload = hash + 1;
3006 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
3007 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
3009 it->ooi_user_ready = 1;
3010 if (!scrub->os_full_speed)
3011 wake_up_all(&scrub->os_thread.t_ctl_waitq);
3013 memset(param, 0, sizeof(*param));
3014 param->sb = osd_sb(dev);
3015 param->start = ooc->ooc_pos_preload;
3016 param->bg = (ooc->ooc_pos_preload - 1) /
3017 LDISKFS_INODES_PER_GROUP(param->sb);
3018 param->offset = (ooc->ooc_pos_preload - 1) %
3019 LDISKFS_INODES_PER_GROUP(param->sb);
3020 param->gbase = 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
3022 /* Unplug OSD layer iteration by the first next() call. */
3023 rc = osd_otable_it_next(env, (struct dt_it *)it);
3028 static int osd_otable_it_key_rec(const struct lu_env *env,
3029 const struct dt_it *di, void *key_rec)
3034 const struct dt_index_operations osd_otable_ops = {
3036 .init = osd_otable_it_init,
3037 .fini = osd_otable_it_fini,
3038 .get = osd_otable_it_get,
3039 .put = osd_otable_it_put,
3040 .next = osd_otable_it_next,
3041 .key = osd_otable_it_key,
3042 .key_size = osd_otable_it_key_size,
3043 .rec = osd_otable_it_rec,
3044 .store = osd_otable_it_store,
3045 .load = osd_otable_it_load,
3046 .key_rec = osd_otable_it_key_rec,
3050 /* high priority inconsistent items list APIs */
3052 #define SCRUB_BAD_OIMAP_DECAY_INTERVAL 60
3054 int osd_oii_insert(struct osd_device *dev, struct osd_idmap_cache *oic,
3057 struct osd_inconsistent_item *oii;
3058 struct osd_scrub *oscrub = &dev->od_scrub;
3059 struct lustre_scrub *lscrub = &oscrub->os_scrub;
3060 struct ptlrpc_thread *thread = &lscrub->os_thread;
3065 if (unlikely(oii == NULL))
3068 INIT_LIST_HEAD(&oii->oii_list);
3069 oii->oii_cache = *oic;
3070 oii->oii_insert = insert;
3072 if (lscrub->os_partial_scan) {
3073 __u64 now = ktime_get_real_seconds();
3075 /* If there haven't been errors in a long time,
3076 * decay old count until either the errors are
3077 * gone or we reach the current interval. */
3078 while (unlikely(oscrub->os_bad_oimap_count > 0 &&
3079 oscrub->os_bad_oimap_time +
3080 SCRUB_BAD_OIMAP_DECAY_INTERVAL < now)) {
3081 oscrub->os_bad_oimap_count >>= 1;
3082 oscrub->os_bad_oimap_time +=
3083 SCRUB_BAD_OIMAP_DECAY_INTERVAL;
3086 oscrub->os_bad_oimap_time = now;
3087 if (++oscrub->os_bad_oimap_count >
3088 dev->od_full_scrub_threshold_rate)
3089 lscrub->os_full_scrub = 1;
3092 spin_lock(&lscrub->os_lock);
3093 if (unlikely(!thread_is_running(thread))) {
3094 spin_unlock(&lscrub->os_lock);
3099 if (list_empty(&lscrub->os_inconsistent_items))
3101 list_add_tail(&oii->oii_list, &lscrub->os_inconsistent_items);
3102 spin_unlock(&lscrub->os_lock);
3105 wake_up_all(&thread->t_ctl_waitq);
3110 int osd_oii_lookup(struct osd_device *dev, const struct lu_fid *fid,
3111 struct osd_inode_id *id)
3113 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3114 struct osd_inconsistent_item *oii;
3117 spin_lock(&scrub->os_lock);
3118 list_for_each_entry(oii, &scrub->os_inconsistent_items, oii_list) {
3119 if (lu_fid_eq(fid, &oii->oii_cache.oic_fid)) {
3120 *id = oii->oii_cache.oic_lid;
3121 spin_unlock(&scrub->os_lock);
3125 spin_unlock(&scrub->os_lock);
3130 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
3132 struct osd_scrub *scrub = &dev->od_scrub;
3134 scrub_dump(m, &scrub->os_scrub);
3135 seq_printf(m, "lf_scanned: %llu\n"
3137 "lf_failed: %llu\n",
3138 scrub->os_lf_scanned,
3139 scrub->os_scrub.os_file.sf_param & SP_DRYRUN ?
3140 "inconsistent" : "repaired",
3141 scrub->os_lf_repaired,
3142 scrub->os_lf_failed);