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 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_18_23 *ff = &info->oti_ff_old;
167 struct dentry *dentry = &info->oti_obj_dentry;
168 struct lu_fid *tfid = &info->oti_fid;
169 bool fid_18_23 = false;
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 dquot_initialize(inode);
211 rc = ll_vfs_removexattr(dentry, inode, XATTR_NAME_FID);
216 } else if (rc != -ENODATA && rc < (int)sizeof(struct filter_fid_24_29)) {
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)))
343 case SCRUB_NEXT_NOLMA:
344 sf->sf_flags |= SF_UPGRADE;
345 if (!(sf->sf_param & SP_DRYRUN)) {
346 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
351 if (!(sf->sf_flags & SF_INCONSISTENT))
352 dev->od_igif_inoi = 0;
354 case SCRUB_NEXT_OSTOBJ:
355 sf->sf_flags |= SF_INCONSISTENT;
356 case SCRUB_NEXT_OSTOBJ_OLD:
361 } else if (osd_id_eq(lid, lid2)) {
363 sf->sf_items_updated++;
367 if (!scrub->os_partial_scan) {
368 spin_lock(&scrub->os_lock);
369 scrub->os_full_speed = 1;
370 spin_unlock(&scrub->os_lock);
372 sf->sf_flags |= SF_INCONSISTENT;
374 /* XXX: If the device is restored from file-level backup, then
375 * some IGIFs may have been already in OI files, and some
376 * may be not yet. Means upgrading from 1.8 may be partly
377 * processed, but some clients may hold some immobilized
378 * IGIFs, and use them to access related objects. Under
379 * such case, OSD does not know whether an given IGIF has
380 * been processed or to be processed, and it also cannot
381 * generate local ino#/gen# directly from the immobilized
382 * IGIF because of the backup/restore. Then force OSD to
383 * lookup the given IGIF in OI files, and if no entry,
384 * then ask the client to retry after upgrading completed.
385 * No better choice. */
386 dev->od_igif_inoi = 1;
389 rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops, false,
390 (val == SCRUB_NEXT_OSTOBJ ||
391 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0,
394 if (scrub->os_in_prior)
395 sf->sf_items_updated_prior++;
397 sf->sf_items_updated++;
399 if (ops == DTO_INDEX_INSERT && val == 0 && !exist) {
400 int idx = osd_oi_fid2idx(dev, fid);
402 sf->sf_flags |= SF_RECREATED;
403 if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
404 ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
412 sf->sf_items_failed++;
413 if (sf->sf_pos_first_inconsistent == 0 ||
414 sf->sf_pos_first_inconsistent > lid->oii_ino)
415 sf->sf_pos_first_inconsistent = lid->oii_ino;
420 /* There may be conflict unlink during the OI scrub,
421 * if happend, then remove the new added OI mapping. */
422 if (ops == DTO_INDEX_INSERT && inode != NULL && !IS_ERR(inode) &&
423 unlikely(ldiskfs_test_inode_state(inode,
424 LDISKFS_STATE_LUSTRE_DESTROY)))
425 osd_scrub_refresh_mapping(info, dev, fid, lid,
426 DTO_INDEX_DELETE, false,
427 (val == SCRUB_NEXT_OSTOBJ ||
428 val == SCRUB_NEXT_OSTOBJ_OLD) ?
429 OI_KNOWN_ON_OST : 0, NULL);
430 up_write(&scrub->os_rwsem);
436 spin_lock(&scrub->os_lock);
437 if (likely(!list_empty(&oii->oii_list)))
438 list_del(&oii->oii_list);
439 spin_unlock(&scrub->os_lock);
444 RETURN(sf->sf_param & SP_FAILOUT ? rc : 0);
447 /* iteration engine */
449 typedef int (*osd_iit_next_policy)(struct osd_thread_info *info,
450 struct osd_device *dev,
451 struct osd_iit_param *param,
452 struct osd_idmap_cache **oic,
455 typedef int (*osd_iit_exec_policy)(struct osd_thread_info *info,
456 struct osd_device *dev,
457 struct osd_iit_param *param,
458 struct osd_idmap_cache *oic,
459 bool *noslot, int rc);
461 static int osd_iit_next(struct osd_iit_param *param, __u64 *pos)
466 param->offset = ldiskfs_find_next_bit(param->bitmap->b_data,
467 LDISKFS_INODES_PER_GROUP(param->sb), param->offset);
468 if (param->offset >= LDISKFS_INODES_PER_GROUP(param->sb)) {
469 *pos = 1 + (param->bg+1) * LDISKFS_INODES_PER_GROUP(param->sb);
470 return SCRUB_NEXT_BREAK;
473 offset = param->offset++;
474 if (unlikely(*pos == param->gbase + offset && *pos != param->start)) {
475 /* We should NOT find the same object more than once. */
476 CERROR("%s: scan the same object multiple times at the pos: "
477 "group = %u, base = %u, offset = %u, start = %u\n",
478 osd_sb2name(param->sb), (__u32)param->bg, param->gbase,
479 offset, param->start);
483 *pos = param->gbase + offset;
488 * \retval SCRUB_NEXT_OSTOBJ_OLD: FID-on-OST
489 * \retval 0: FID-on-MDT
491 static int osd_scrub_check_local_fldb(struct osd_thread_info *info,
492 struct osd_device *dev,
495 /* XXX: The initial OI scrub will scan the top level /O to generate
496 * a small local FLDB according to the <seq>. If the given FID
497 * is in the local FLDB, then it is FID-on-OST; otherwise it's
498 * quite possible for FID-on-MDT. */
500 return SCRUB_NEXT_OSTOBJ_OLD;
505 static int osd_scrub_get_fid(struct osd_thread_info *info,
506 struct osd_device *dev, struct inode *inode,
507 struct lu_fid *fid, bool scrub)
509 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
510 bool has_lma = false;
513 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
514 &info->oti_ost_attrs);
517 if (lma->lma_compat & LMAC_NOT_IN_OI ||
518 lma->lma_incompat & LMAI_AGENT)
519 return SCRUB_NEXT_CONTINUE;
521 *fid = lma->lma_self_fid;
525 if (lma->lma_compat & LMAC_FID_ON_OST)
526 return SCRUB_NEXT_OSTOBJ;
528 if (fid_is_idif(fid))
529 return SCRUB_NEXT_OSTOBJ_OLD;
531 /* For local object. */
532 if (fid_is_internal(fid))
535 /* For external visible MDT-object with non-normal FID. */
536 if (fid_is_namespace_visible(fid) && !fid_is_norm(fid))
539 /* For the object with normal FID, it may be MDT-object,
540 * or may be 2.4 OST-object, need further distinguish.
541 * Fall through to next section. */
544 if (rc == -ENODATA || rc == 0) {
545 rc = osd_get_idif(info, inode, &info->oti_obj_dentry, fid);
548 /* It is 2.3 or older OST-object. */
549 rc = SCRUB_NEXT_OSTOBJ_OLD;
555 /* It is FID-on-OST, but we do not know how
556 * to generate its FID, ignore it directly. */
557 rc = SCRUB_NEXT_CONTINUE;
559 /* It is 2.4 or newer OST-object. */
560 rc = SCRUB_NEXT_OSTOBJ_OLD;
568 if (dev->od_scrub.os_scrub.os_convert_igif) {
569 lu_igif_build(fid, inode->i_ino,
570 inode->i_generation);
572 rc = SCRUB_NEXT_NOLMA;
576 /* It may be FID-on-OST, or may be FID for
577 * non-MDT0, anyway, we do not know how to
578 * generate its FID, ignore it directly. */
579 rc = SCRUB_NEXT_CONTINUE;
584 /* For OI scrub case only: the object has LMA but has no ff
585 * (or ff crashed). It may be MDT-object, may be OST-object
586 * with crashed ff. The last check is local FLDB. */
587 rc = osd_scrub_check_local_fldb(info, dev, fid);
593 static int osd_iit_iget(struct osd_thread_info *info, struct osd_device *dev,
594 struct lu_fid *fid, struct osd_inode_id *lid, __u32 pos,
595 struct super_block *sb, bool scrub)
601 /* Not handle the backend root object and agent parent object.
602 * They are neither visible to namespace nor have OI mappings. */
603 if (unlikely(pos == osd_sb(dev)->s_root->d_inode->i_ino ||
604 is_remote_parent_ino(dev, pos)))
605 RETURN(SCRUB_NEXT_CONTINUE);
607 /* Skip project quota inode since it is greater than s_first_ino. */
608 #ifdef HAVE_PROJECT_QUOTA
609 if (ldiskfs_has_feature_project(sb) &&
610 pos == le32_to_cpu(LDISKFS_SB(sb)->s_es->s_prj_quota_inum))
611 RETURN(SCRUB_NEXT_CONTINUE);
614 osd_id_gen(lid, pos, OSD_OII_NOGEN);
615 inode = osd_iget(info, dev, lid);
618 /* The inode may be removed after bitmap searching, or the
619 * file is new created without inode initialized yet. */
620 if (rc == -ENOENT || rc == -ESTALE)
621 RETURN(SCRUB_NEXT_CONTINUE);
623 CDEBUG(D_LFSCK, "%s: fail to read inode, ino# = %u: "
624 "rc = %d\n", osd_dev2name(dev), pos, rc);
628 if (dev->od_is_ost && S_ISREG(inode->i_mode) && inode->i_nlink > 1)
629 dev->od_scrub.os_scrub.os_has_ml_file = 1;
631 /* It is an EA inode, no OI mapping for it, skip it. */
632 if (osd_is_ea_inode(inode))
633 GOTO(put, rc = SCRUB_NEXT_CONTINUE);
636 ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB)) {
637 /* Only skip it for the first OI scrub accessing. */
638 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
639 GOTO(put, rc = SCRUB_NEXT_NOSCRUB);
642 rc = osd_scrub_get_fid(info, dev, inode, fid, scrub);
651 static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
652 struct osd_iit_param *param,
653 struct osd_idmap_cache **oic, const bool noslot)
655 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
657 struct osd_inode_id *lid;
660 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0)
661 wait_var_event_timeout(
663 !list_empty(&scrub->os_inconsistent_items) ||
664 kthread_should_stop(),
665 cfs_time_seconds(cfs_fail_val));
667 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_CRASH)) {
668 spin_lock(&scrub->os_lock);
669 scrub->os_running = 0;
670 spin_unlock(&scrub->os_lock);
671 return SCRUB_NEXT_CRASH;
674 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_FATAL))
675 return SCRUB_NEXT_FATAL;
677 if (kthread_should_stop())
678 return SCRUB_NEXT_EXIT;
680 if (!list_empty(&scrub->os_inconsistent_items)) {
681 spin_lock(&scrub->os_lock);
682 if (likely(!list_empty(&scrub->os_inconsistent_items))) {
683 struct osd_inconsistent_item *oii;
685 oii = list_entry(scrub->os_inconsistent_items.next,
686 struct osd_inconsistent_item, oii_list);
688 *oic = &oii->oii_cache;
689 scrub->os_in_prior = 1;
690 spin_unlock(&scrub->os_lock);
694 spin_unlock(&scrub->os_lock);
698 return SCRUB_NEXT_WAIT;
700 rc = osd_iit_next(param, &scrub->os_pos_current);
704 *oic = &dev->od_scrub.os_oic;
705 fid = &(*oic)->oic_fid;
706 lid = &(*oic)->oic_lid;
707 rc = osd_iit_iget(info, dev, fid, lid,
708 scrub->os_pos_current, param->sb, true);
712 static int osd_preload_next(struct osd_thread_info *info,
713 struct osd_device *dev, struct osd_iit_param *param,
714 struct osd_idmap_cache **oic, const bool noslot)
716 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
717 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
720 if (scrub->os_running &&
721 ooc->ooc_pos_preload >= scrub->os_pos_current)
722 return SCRUB_NEXT_EXIT;
724 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
728 rc = osd_iit_iget(info, dev,
729 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
730 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
731 ooc->ooc_pos_preload, param->sb, false);
736 osd_scrub_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
738 spin_lock(&scrub->os_lock);
739 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
740 !list_empty(&scrub->os_inconsistent_items) ||
741 it->ooi_waiting || kthread_should_stop())
742 scrub->os_waiting = 0;
744 scrub->os_waiting = 1;
745 spin_unlock(&scrub->os_lock);
747 return !scrub->os_waiting;
750 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
751 struct osd_iit_param *param,
752 struct osd_idmap_cache *oic, bool *noslot, int rc)
754 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
755 struct scrub_file *sf = &scrub->os_file;
756 struct osd_otable_it *it = dev->od_otable_it;
757 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
760 case SCRUB_NEXT_NOSCRUB:
761 down_write(&scrub->os_rwsem);
762 scrub->os_new_checked++;
763 sf->sf_items_noscrub++;
764 up_write(&scrub->os_rwsem);
765 case SCRUB_NEXT_CONTINUE:
766 case SCRUB_NEXT_WAIT:
770 rc = osd_scrub_check_update(info, dev, oic, rc);
772 spin_lock(&scrub->os_lock);
773 scrub->os_in_prior = 0;
774 spin_unlock(&scrub->os_lock);
778 rc = scrub_checkpoint(info->oti_env, scrub);
780 CDEBUG(D_LFSCK, "%s: fail to checkpoint, pos = %llu: "
781 "rc = %d\n", osd_scrub2name(scrub),
782 scrub->os_pos_current, rc);
783 /* Continue, as long as the scrub itself can go ahead. */
786 if (scrub->os_in_prior) {
787 spin_lock(&scrub->os_lock);
788 scrub->os_in_prior = 0;
789 spin_unlock(&scrub->os_lock);
794 if (it != NULL && it->ooi_waiting && ooc != NULL &&
795 ooc->ooc_pos_preload < scrub->os_pos_current) {
796 spin_lock(&scrub->os_lock);
799 spin_unlock(&scrub->os_lock);
802 if (rc == SCRUB_NEXT_CONTINUE)
805 if (scrub->os_full_speed || !ooc || osd_scrub_has_window(scrub, ooc)) {
811 wait_var_event(scrub, osd_scrub_wakeup(scrub, it));
813 if (!ooc || osd_scrub_has_window(scrub, ooc))
820 static int osd_preload_exec(struct osd_thread_info *info,
821 struct osd_device *dev, struct osd_iit_param *param,
822 struct osd_idmap_cache *oic, bool *noslot, int rc)
824 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
827 ooc->ooc_cached_items++;
828 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
829 ~OSD_OTABLE_IT_CACHE_MASK;
831 return rc > 0 ? 0 : rc;
834 #define SCRUB_IT_ALL 1
835 #define SCRUB_IT_CRASH 2
837 static void osd_scrub_join(const struct lu_env *env, struct osd_device *dev,
838 __u32 flags, bool inconsistent)
840 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
841 struct scrub_file *sf = &scrub->os_file;
845 LASSERT(!(flags & SS_AUTO_PARTIAL));
847 down_write(&scrub->os_rwsem);
848 spin_lock(&scrub->os_lock);
849 scrub->os_in_join = 1;
850 if (flags & SS_SET_FAILOUT)
851 sf->sf_param |= SP_FAILOUT;
852 else if (flags & SS_CLEAR_FAILOUT)
853 sf->sf_param &= ~SP_FAILOUT;
855 if (flags & SS_SET_DRYRUN)
856 sf->sf_param |= SP_DRYRUN;
857 else if (flags & SS_CLEAR_DRYRUN)
858 sf->sf_param &= ~SP_DRYRUN;
860 if (flags & SS_RESET) {
861 scrub_file_reset(scrub, dev->od_uuid,
862 inconsistent ? SF_INCONSISTENT : 0);
863 sf->sf_status = SS_SCANNING;
866 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
867 scrub->os_full_speed = 1;
869 scrub->os_full_speed = 0;
871 if (flags & SS_AUTO_FULL) {
872 sf->sf_flags |= SF_AUTO;
873 scrub->os_full_speed = 1;
875 spin_unlock(&scrub->os_lock);
877 scrub->os_new_checked = 0;
878 if (sf->sf_pos_last_checkpoint != 0)
879 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
881 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
883 scrub->os_pos_current = sf->sf_pos_latest_start;
884 sf->sf_time_latest_start = ktime_get_real_seconds();
885 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
886 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
887 rc = scrub_file_store(env, scrub);
889 spin_lock(&scrub->os_lock);
890 scrub->os_waiting = 0;
891 scrub->os_paused = 0;
892 scrub->os_partial_scan = 0;
893 scrub->os_in_join = 0;
894 scrub->os_full_scrub = 0;
895 spin_unlock(&scrub->os_lock);
897 up_write(&scrub->os_rwsem);
899 CDEBUG(D_LFSCK, "%s: joined in the OI scrub with flag %u: rc = %d\n",
900 osd_scrub2name(scrub), flags, rc);
905 static int osd_inode_iteration(struct osd_thread_info *info,
906 struct osd_device *dev, __u32 max, bool preload)
908 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
909 struct scrub_file *sf = &scrub->os_file;
910 osd_iit_next_policy next;
911 osd_iit_exec_policy exec;
914 struct osd_iit_param *param;
923 param = &dev->od_scrub.os_iit_param;
924 memset(param, 0, sizeof(*param));
925 param->sb = osd_sb(dev);
927 while (scrub->os_partial_scan && !scrub->os_in_join) {
928 struct osd_idmap_cache *oic = NULL;
930 rc = osd_scrub_next(info, dev, param, &oic, noslot);
932 case SCRUB_NEXT_EXIT:
934 case SCRUB_NEXT_CRASH:
935 RETURN(SCRUB_IT_CRASH);
936 case SCRUB_NEXT_FATAL:
938 case SCRUB_NEXT_WAIT: {
939 struct kstatfs *ksfs = &info->oti_ksfs;
942 if (dev->od_full_scrub_ratio == OFSR_NEVER ||
943 unlikely(sf->sf_items_updated_prior == 0))
946 if (dev->od_full_scrub_ratio == OFSR_DIRECTLY ||
947 scrub->os_full_scrub) {
948 osd_scrub_join(info->oti_env, dev,
949 SS_AUTO_FULL | SS_RESET, true);
953 rc = param->sb->s_op->statfs(param->sb->s_root, ksfs);
955 __u64 used = ksfs->f_files - ksfs->f_ffree;
957 used = div64_u64(used, sf->sf_items_updated_prior);
958 /* If we hit too much inconsistent OI
959 * mappings during the partial scan,
960 * then scan the device completely. */
961 if (used < dev->od_full_scrub_ratio) {
962 osd_scrub_join(info->oti_env, dev,
963 SS_AUTO_FULL | SS_RESET, true);
969 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) &&
973 saved_flags = sf->sf_flags;
974 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
975 SF_UPGRADE | SF_AUTO);
976 sf->sf_status = SS_COMPLETED;
979 kthread_should_stop() ||
980 !scrub->os_partial_scan ||
982 !list_empty(&scrub->os_inconsistent_items));
983 sf->sf_flags = saved_flags;
984 sf->sf_status = SS_SCANNING;
986 if (kthread_should_stop())
989 if (!scrub->os_partial_scan || scrub->os_in_join)
995 LASSERTF(rc == 0, "rc = %d\n", rc);
997 osd_scrub_exec(info, dev, param, oic, &noslot, rc);
1004 wait_var_event(scrub,
1005 kthread_should_stop() ||
1006 !scrub->os_in_join);
1008 if (kthread_should_stop())
1014 next = osd_scrub_next;
1015 exec = osd_scrub_exec;
1016 pos = &scrub->os_pos_current;
1017 count = &scrub->os_new_checked;
1018 param->start = *pos;
1019 param->bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param->sb);
1021 (*pos - 1) % LDISKFS_INODES_PER_GROUP(param->sb);
1023 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1025 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1027 next = osd_preload_next;
1028 exec = osd_preload_exec;
1029 pos = &ooc->ooc_pos_preload;
1030 count = &ooc->ooc_cached_items;
1031 param = &dev->od_otable_it->ooi_iit_param;
1035 limit = le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count);
1036 while (*pos <= limit && *count < max) {
1037 struct ldiskfs_group_desc *desc;
1038 bool next_group = false;
1040 desc = ldiskfs_get_group_desc(param->sb, param->bg, NULL);
1044 if (desc->bg_flags & cpu_to_le16(LDISKFS_BG_INODE_UNINIT)) {
1049 param->bitmap = ldiskfs_read_inode_bitmap(param->sb, param->bg);
1050 if (!param->bitmap) {
1051 CERROR("%s: fail to read bitmap for %u, "
1052 "scrub will stop, urgent mode\n",
1053 osd_scrub2name(scrub), (__u32)param->bg);
1058 struct osd_idmap_cache *oic = NULL;
1061 ldiskfs_itable_unused_count(param->sb, desc) >=
1062 LDISKFS_INODES_PER_GROUP(param->sb)) {
1067 rc = next(info, dev, param, &oic, noslot);
1069 case SCRUB_NEXT_BREAK:
1072 case SCRUB_NEXT_EXIT:
1073 brelse(param->bitmap);
1075 case SCRUB_NEXT_CRASH:
1076 brelse(param->bitmap);
1077 RETURN(SCRUB_IT_CRASH);
1078 case SCRUB_NEXT_FATAL:
1079 brelse(param->bitmap);
1083 rc = exec(info, dev, param, oic, &noslot, rc);
1084 } while (!rc && *pos <= limit && *count < max);
1087 if (param->bitmap) {
1088 brelse(param->bitmap);
1089 param->bitmap = NULL;
1099 param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1100 *pos = param->gbase;
1101 param->start = *pos;
1106 RETURN(SCRUB_IT_ALL);
1112 static int osd_otable_it_preload(const struct lu_env *env,
1113 struct osd_otable_it *it)
1115 struct osd_device *dev = it->ooi_dev;
1116 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1117 struct osd_otable_cache *ooc = &it->ooi_cache;
1121 rc = osd_inode_iteration(osd_oti_get(env), dev,
1122 OSD_OTABLE_IT_CACHE_SIZE, true);
1123 if (rc == SCRUB_IT_ALL)
1124 it->ooi_all_cached = 1;
1126 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1127 spin_lock(&scrub->os_lock);
1128 scrub->os_waiting = 0;
1130 spin_unlock(&scrub->os_lock);
1133 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1136 static int osd_scan_ml_file_main(const struct lu_env *env,
1137 struct osd_device *dev);
1139 static int osd_scrub_main(void *args)
1142 struct osd_device *dev = (struct osd_device *)args;
1143 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1147 rc = lu_env_init(&env, LCT_LOCAL | LCT_DT_THREAD);
1149 CDEBUG(D_LFSCK, "%s: OI scrub fail to init env: rc = %d\n",
1150 osd_scrub2name(scrub), rc);
1154 rc = scrub_thread_prep(&env, scrub, dev->od_uuid,
1155 LDISKFS_FIRST_INO(osd_sb(dev)) + 1);
1157 CDEBUG(D_LFSCK, "%s: OI scrub fail to scrub prep: rc = %d\n",
1158 osd_scrub2name(scrub), rc);
1162 if (!scrub->os_full_speed && !scrub->os_partial_scan) {
1163 struct osd_otable_it *it = dev->od_otable_it;
1164 struct osd_otable_cache *ooc = &it->ooi_cache;
1166 wait_var_event(scrub,
1167 it->ooi_user_ready || kthread_should_stop());
1168 if (kthread_should_stop())
1171 scrub->os_pos_current = ooc->ooc_pos_preload;
1174 CDEBUG(D_LFSCK, "%s: OI scrub start, flags = 0x%x, pos = %llu\n",
1175 osd_scrub2name(scrub), scrub->os_start_flags,
1176 scrub->os_pos_current);
1178 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1179 if (unlikely(rc == SCRUB_IT_CRASH)) {
1180 spin_lock(&scrub->os_lock);
1181 scrub->os_running = 0;
1182 spin_unlock(&scrub->os_lock);
1183 GOTO(out, rc = -EINVAL);
1186 if (scrub->os_has_ml_file) {
1187 ret = osd_scan_ml_file_main(&env, dev);
1196 dev->od_igif_inoi = 1;
1197 dev->od_check_ff = 0;
1199 rc = scrub_thread_post(&env, &dev->od_scrub.os_scrub, rc);
1200 CDEBUG(D_LFSCK, "%s: OI scrub: stop, pos = %llu: rc = %d\n",
1201 osd_scrub2name(scrub), scrub->os_pos_current, rc);
1204 while (!list_empty(&scrub->os_inconsistent_items)) {
1205 struct osd_inconsistent_item *oii;
1207 oii = list_entry(scrub->os_inconsistent_items.next,
1208 struct osd_inconsistent_item, oii_list);
1209 list_del_init(&oii->oii_list);
1216 spin_lock(&scrub->os_lock);
1217 scrub->os_running = 0;
1218 spin_unlock(&scrub->os_lock);
1219 if (xchg(&scrub->os_task, NULL) == NULL)
1220 /* scrub_stop() is waiting, we need to synchronize */
1221 wait_var_event(scrub, kthread_should_stop());
1226 /* initial OI scrub */
1228 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1229 struct dentry *, filldir_t filldir);
1231 #ifdef HAVE_FILLDIR_USE_CTX
1232 static int osd_ios_varfid_fill(struct dir_context *buf, const char *name,
1233 int namelen, loff_t offset, __u64 ino,
1235 static int osd_ios_lf_fill(struct dir_context *buf, const char *name,
1236 int namelen, loff_t offset, __u64 ino,
1238 static int osd_ios_dl_fill(struct dir_context *buf, const char *name,
1239 int namelen, loff_t offset, __u64 ino,
1241 static int osd_ios_uld_fill(struct dir_context *buf, const char *name,
1242 int namelen, loff_t offset, __u64 ino,
1245 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1246 loff_t offset, __u64 ino, unsigned d_type);
1247 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1248 loff_t offset, __u64 ino, unsigned d_type);
1249 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1250 loff_t offset, __u64 ino, unsigned d_type);
1251 static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
1252 loff_t offset, __u64 ino, unsigned d_type);
1256 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1257 struct dentry *dentry, filldir_t filldir);
1259 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1260 struct dentry *dentry, filldir_t filldir);
1263 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1264 struct dentry *dentry, filldir_t filldir);
1268 struct lu_fid olm_fid;
1271 scandir_t olm_scandir;
1272 filldir_t olm_filldir;
1275 /* Add the new introduced local files in the list in the future. */
1276 static const struct osd_lf_map osd_lf_maps[] = {
1279 .olm_name = CATLIST,
1281 .f_seq = FID_SEQ_LOCAL_FILE,
1282 .f_oid = LLOG_CATALOGS_OID,
1284 .olm_flags = OLF_SHOW_NAME,
1285 .olm_namelen = sizeof(CATLIST) - 1,
1290 .olm_name = MOUNT_CONFIGS_DIR,
1292 .f_seq = FID_SEQ_LOCAL_FILE,
1293 .f_oid = MGS_CONFIGS_OID,
1295 .olm_flags = OLF_SCAN_SUBITEMS,
1296 .olm_namelen = sizeof(MOUNT_CONFIGS_DIR) - 1,
1297 .olm_scandir = osd_ios_general_scan,
1298 .olm_filldir = osd_ios_varfid_fill,
1301 /* NIDTBL_VERSIONS */
1303 .olm_name = MGS_NIDTBL_DIR,
1304 .olm_flags = OLF_SCAN_SUBITEMS,
1305 .olm_namelen = sizeof(MGS_NIDTBL_DIR) - 1,
1306 .olm_scandir = osd_ios_general_scan,
1307 .olm_filldir = osd_ios_varfid_fill,
1312 .olm_name = MDT_ORPHAN_DIR,
1313 .olm_namelen = sizeof(MDT_ORPHAN_DIR) - 1,
1320 .f_seq = FID_SEQ_ROOT,
1321 .f_oid = FID_OID_ROOT,
1323 .olm_flags = OLF_SCAN_SUBITEMS | OLF_HIDE_FID,
1324 .olm_namelen = sizeof("ROOT") - 1,
1325 .olm_scandir = osd_ios_ROOT_scan,
1328 /* changelog_catalog */
1330 .olm_name = CHANGELOG_CATALOG,
1331 .olm_namelen = sizeof(CHANGELOG_CATALOG) - 1,
1334 /* changelog_users */
1336 .olm_name = CHANGELOG_USERS,
1337 .olm_namelen = sizeof(CHANGELOG_USERS) - 1,
1344 .f_seq = FID_SEQ_LOCAL_FILE,
1345 .f_oid = FLD_INDEX_OID,
1347 .olm_flags = OLF_SHOW_NAME,
1348 .olm_namelen = sizeof("fld") - 1,
1353 .olm_name = LAST_RCVD,
1355 .f_seq = FID_SEQ_LOCAL_FILE,
1356 .f_oid = LAST_RECV_OID,
1358 .olm_flags = OLF_SHOW_NAME,
1359 .olm_namelen = sizeof(LAST_RCVD) - 1,
1364 .olm_name = REPLY_DATA,
1366 .f_seq = FID_SEQ_LOCAL_FILE,
1367 .f_oid = REPLY_DATA_OID,
1369 .olm_flags = OLF_SHOW_NAME,
1370 .olm_namelen = sizeof(REPLY_DATA) - 1,
1375 .olm_name = LOV_OBJID,
1377 .f_seq = FID_SEQ_LOCAL_FILE,
1378 .f_oid = MDD_LOV_OBJ_OID,
1380 .olm_flags = OLF_SHOW_NAME,
1381 .olm_namelen = sizeof(LOV_OBJID) - 1,
1386 .olm_name = LOV_OBJSEQ,
1388 .f_seq = FID_SEQ_LOCAL_FILE,
1389 .f_oid = MDD_LOV_OBJ_OSEQ,
1391 .olm_flags = OLF_SHOW_NAME,
1392 .olm_namelen = sizeof(LOV_OBJSEQ) - 1,
1397 .olm_name = QMT_DIR,
1398 .olm_flags = OLF_SCAN_SUBITEMS,
1399 .olm_namelen = sizeof(QMT_DIR) - 1,
1400 .olm_scandir = osd_ios_general_scan,
1401 .olm_filldir = osd_ios_varfid_fill,
1406 .olm_name = QSD_DIR,
1407 .olm_flags = OLF_SCAN_SUBITEMS,
1408 .olm_namelen = sizeof(QSD_DIR) - 1,
1409 .olm_scandir = osd_ios_general_scan,
1410 .olm_filldir = osd_ios_varfid_fill,
1415 .olm_name = "seq_ctl",
1417 .f_seq = FID_SEQ_LOCAL_FILE,
1418 .f_oid = FID_SEQ_CTL_OID,
1420 .olm_flags = OLF_SHOW_NAME,
1421 .olm_namelen = sizeof("seq_ctl") - 1,
1426 .olm_name = "seq_srv",
1428 .f_seq = FID_SEQ_LOCAL_FILE,
1429 .f_oid = FID_SEQ_SRV_OID,
1431 .olm_flags = OLF_SHOW_NAME,
1432 .olm_namelen = sizeof("seq_srv") - 1,
1437 .olm_name = HEALTH_CHECK,
1439 .f_seq = FID_SEQ_LOCAL_FILE,
1440 .f_oid = OFD_HEALTH_CHECK_OID,
1442 .olm_flags = OLF_SHOW_NAME,
1443 .olm_namelen = sizeof(HEALTH_CHECK) - 1,
1448 .olm_name = LFSCK_DIR,
1449 .olm_flags = OLF_SCAN_SUBITEMS,
1450 .olm_namelen = sizeof(LFSCK_DIR) - 1,
1451 .olm_scandir = osd_ios_general_scan,
1452 .olm_filldir = osd_ios_varfid_fill,
1455 /* lfsck_bookmark */
1457 .olm_name = LFSCK_BOOKMARK,
1458 .olm_namelen = sizeof(LFSCK_BOOKMARK) - 1,
1463 .olm_name = LFSCK_LAYOUT,
1464 .olm_namelen = sizeof(LFSCK_LAYOUT) - 1,
1467 /* lfsck_namespace */
1469 .olm_name = LFSCK_NAMESPACE,
1470 .olm_namelen = sizeof(LFSCK_NAMESPACE) - 1,
1473 /* OBJECTS, upgrade from old device */
1475 .olm_name = OBJECTS,
1476 .olm_flags = OLF_SCAN_SUBITEMS,
1477 .olm_namelen = sizeof(OBJECTS) - 1,
1478 .olm_scandir = osd_ios_OBJECTS_scan,
1481 /* lquota_v2.user, upgrade from old device */
1483 .olm_name = "lquota_v2.user",
1484 .olm_namelen = sizeof("lquota_v2.user") - 1,
1487 /* lquota_v2.group, upgrade from old device */
1489 .olm_name = "lquota_v2.group",
1490 .olm_namelen = sizeof("lquota_v2.group") - 1,
1493 /* LAST_GROUP, upgrade from old device */
1495 .olm_name = "LAST_GROUP",
1497 .f_seq = FID_SEQ_LOCAL_FILE,
1498 .f_oid = OFD_LAST_GROUP_OID,
1500 .olm_flags = OLF_SHOW_NAME,
1501 .olm_namelen = sizeof("LAST_GROUP") - 1,
1504 /* committed batchid for cross-MDT operation */
1506 .olm_name = "BATCHID",
1508 .f_seq = FID_SEQ_LOCAL_FILE,
1509 .f_oid = BATCHID_COMMITTED_OID,
1511 .olm_flags = OLF_SHOW_NAME,
1512 .olm_namelen = sizeof("BATCHID") - 1,
1515 /* OSP update logs update_log{_dir} use f_seq = FID_SEQ_UPDATE_LOG{_DIR}
1516 * and f_oid = index for their log files. See lu_update_log{_dir}_fid()
1517 * for more details. */
1521 .olm_name = "update_log",
1523 .f_seq = FID_SEQ_UPDATE_LOG,
1525 .olm_flags = OLF_SHOW_NAME | OLF_IDX_IN_FID,
1526 .olm_namelen = sizeof("update_log") - 1,
1529 /* update_log_dir */
1531 .olm_name = "update_log_dir",
1533 .f_seq = FID_SEQ_UPDATE_LOG_DIR,
1535 .olm_flags = OLF_SHOW_NAME | OLF_SCAN_SUBITEMS |
1537 .olm_namelen = sizeof("update_log_dir") - 1,
1538 .olm_scandir = osd_ios_general_scan,
1539 .olm_filldir = osd_ios_uld_fill,
1544 .olm_name = "lost+found",
1546 .f_seq = FID_SEQ_LOCAL_FILE,
1547 .f_oid = OSD_LPF_OID,
1549 .olm_flags = OLF_SCAN_SUBITEMS,
1550 .olm_namelen = sizeof("lost+found") - 1,
1551 .olm_scandir = osd_ios_general_scan,
1552 .olm_filldir = osd_ios_lf_fill,
1557 .olm_name = HSM_ACTIONS,
1562 .olm_name = LUSTRE_NODEMAP_NAME,
1567 .olm_name = INDEX_BACKUP_DIR,
1569 .f_seq = FID_SEQ_LOCAL_FILE,
1570 .f_oid = INDEX_BACKUP_OID,
1572 .olm_flags = OLF_SCAN_SUBITEMS | OLF_NOT_BACKUP,
1573 .olm_namelen = sizeof(INDEX_BACKUP_DIR) - 1,
1574 .olm_scandir = osd_ios_general_scan,
1575 .olm_filldir = osd_ios_varfid_fill,
1583 /* Add the new introduced files under .lustre/ in the list in the future. */
1584 static const struct osd_lf_map osd_dl_maps[] = {
1589 .f_seq = FID_SEQ_DOT_LUSTRE,
1590 .f_oid = FID_OID_DOT_LUSTRE_OBF,
1592 .olm_namelen = sizeof("fid") - 1,
1595 /* .lustre/lost+found */
1597 .olm_name = "lost+found",
1599 .f_seq = FID_SEQ_DOT_LUSTRE,
1600 .f_oid = FID_OID_DOT_LUSTRE_LPF,
1602 .olm_namelen = sizeof("lost+found") - 1,
1610 struct osd_ios_item {
1611 struct list_head oii_list;
1612 struct dentry *oii_dentry;
1613 scandir_t oii_scandir;
1614 filldir_t oii_filldir;
1617 struct osd_ios_filldir_buf {
1618 /* please keep it as first member */
1619 struct dir_context ctx;
1620 struct osd_thread_info *oifb_info;
1621 struct osd_device *oifb_dev;
1622 struct dentry *oifb_dentry;
1627 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1628 scandir_t scandir, filldir_t filldir)
1630 struct osd_ios_item *item;
1633 OBD_ALLOC_PTR(item);
1637 INIT_LIST_HEAD(&item->oii_list);
1638 item->oii_dentry = dget(dentry);
1639 item->oii_scandir = scandir;
1640 item->oii_filldir = filldir;
1641 list_add_tail(&item->oii_list, &dev->od_ios_list);
1646 static bool osd_index_need_recreate(const struct lu_env *env,
1647 struct osd_device *dev, struct inode *inode)
1649 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1650 struct iam_container *bag = &iam->od_container;
1654 rc = iam_container_init(bag, &iam->od_descr, inode);
1658 rc = iam_container_setup(bag);
1659 iam_container_fini(bag);
1666 static void osd_ios_index_register(const struct lu_env *env,
1667 struct osd_device *osd,
1668 const struct lu_fid *fid,
1669 struct inode *inode)
1671 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1672 struct iam_container *bag = &iam->od_container;
1673 struct super_block *sb = osd_sb(osd);
1674 struct iam_descr *descr;
1680 /* Index must be a regular file. */
1681 if (!S_ISREG(inode->i_mode))
1684 /* Index's size must be block aligned. */
1685 if (inode->i_size < sb->s_blocksize ||
1686 (inode->i_size & (sb->s_blocksize - 1)) != 0)
1689 iam_container_init(bag, &iam->od_descr, inode);
1690 rc = iam_container_setup(bag);
1694 descr = bag->ic_descr;
1695 /* May be regular file with IAM_LFIX_ROOT_MAGIC matched
1696 * coincidentally, or corrupted index object, skip it. */
1697 if (descr->id_ptr_size != 4)
1700 keysize = descr->id_key_size;
1701 recsize = descr->id_rec_size;
1702 rc = osd_index_register(osd, fid, keysize, recsize);
1707 iam_container_fini(bag);
1709 CDEBUG(D_LFSCK, "%s: index object "DFID" (%u/%u) registered\n",
1710 osd_name(osd), PFID(fid), keysize, recsize);
1713 static void osd_index_restore(const struct lu_env *env, struct osd_device *dev,
1714 struct lustre_index_restore_unit *liru,
1715 void *buf, int bufsize)
1717 struct osd_thread_info *info = osd_oti_get(env);
1718 struct osd_inode_id *id = &info->oti_id;
1719 struct lu_fid *tgt_fid = &liru->liru_cfid;
1720 struct inode *bak_inode = NULL;
1721 struct ldiskfs_dir_entry_2 *de = NULL;
1722 struct buffer_head *bh = NULL;
1723 struct dentry *dentry;
1725 struct lu_fid bak_fid;
1729 lustre_fid2lbx(name, tgt_fid, bufsize);
1730 dentry = osd_child_dentry_by_inode(env, dev->od_index_backup_inode,
1731 name, strlen(name));
1732 bh = osd_ldiskfs_find_entry(dev->od_index_backup_inode,
1733 &dentry->d_name, &de, NULL, NULL);
1735 GOTO(log, rc = PTR_ERR(bh));
1737 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
1739 bak_inode = osd_iget_fid(info, dev, id, &bak_fid);
1740 if (IS_ERR(bak_inode))
1741 GOTO(log, rc = PTR_ERR(bak_inode));
1744 /* The OI mapping for index may be invalid, since it will be
1745 * re-created, not update the OI mapping, just cache it in RAM. */
1746 osd_id_gen(id, liru->liru_clid, OSD_OII_NOGEN);
1747 osd_add_oi_cache(info, dev, id, tgt_fid);
1748 rc = lustre_index_restore(env, &dev->od_dt_dev, &liru->liru_pfid,
1749 tgt_fid, &bak_fid, liru->liru_name,
1750 &dev->od_index_backup_list, &dev->od_lock,
1755 CDEBUG(D_WARNING, "%s: restore index '%s' with "DFID": rc = %d\n",
1756 osd_name(dev), liru->liru_name, PFID(tgt_fid), rc);
1760 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1762 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1763 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1764 * reference the inode, or fixed if it is missing or references another inode.
1767 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1768 struct inode *parent, struct inode *inode,
1769 const struct lu_fid *fid, const char *name,
1770 int namelen, int flags)
1772 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1773 struct osd_inode_id *id = &info->oti_id;
1774 struct osd_inode_id *id2 = &info->oti_id2;
1775 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1776 struct scrub_file *sf = &scrub->os_file;
1782 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode: rc = -2\n",
1783 osd_name(dev), namelen, name);
1787 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
1788 &info->oti_ost_attrs);
1789 if (rc != 0 && rc != -ENODATA) {
1790 CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
1791 "rc = %d\n", osd_name(dev), rc);
1796 osd_id_gen(id, inode->i_ino, inode->i_generation);
1797 if (rc == -ENODATA) {
1798 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID) {
1799 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1802 if (flags & OLF_IDX_IN_FID) {
1803 LASSERT(dev->od_index >= 0);
1805 tfid.f_oid = dev->od_index;
1808 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1810 CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
1811 "scrub: rc = %d\n", osd_name(dev), rc);
1816 if (lma->lma_compat & LMAC_NOT_IN_OI)
1819 tfid = lma->lma_self_fid;
1820 if (lma->lma_compat & LMAC_IDX_BACKUP &&
1821 osd_index_need_recreate(info->oti_env, dev, inode)) {
1822 struct lu_fid *pfid = &info->oti_fid3;
1824 if (is_root_inode(parent)) {
1825 lu_local_obj_fid(pfid, OSD_FS_ROOT_OID);
1827 rc = osd_scrub_get_fid(info, dev, parent, pfid,
1833 rc = lustre_liru_new(&dev->od_index_restore_list, pfid,
1834 &tfid, inode->i_ino, name, namelen);
1839 if (!(flags & OLF_NOT_BACKUP))
1840 osd_ios_index_register(info->oti_env, dev, &tfid,
1844 /* Since this called from iterate_dir() the inode lock will be taken */
1845 rc = osd_oi_lookup(info, dev, &tfid, id2, OI_LOCKED);
1850 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1851 DTO_INDEX_INSERT, true, 0, NULL);
1858 if (osd_id_eq_strict(id, id2))
1861 if (!(sf->sf_flags & SF_INCONSISTENT)) {
1862 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
1863 rc = scrub_file_store(info->oti_env, scrub);
1868 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1869 DTO_INDEX_UPDATE, true, 0, NULL);
1877 * It scans the /lost+found, and for the OST-object (with filter_fid
1878 * or filter_fid_18_23), move them back to its proper /O/<seq>/d<x>.
1880 #ifdef HAVE_FILLDIR_USE_CTX
1881 static int osd_ios_lf_fill(struct dir_context *buf,
1883 static int osd_ios_lf_fill(void *buf,
1885 const char *name, int namelen,
1886 loff_t offset, __u64 ino, unsigned d_type)
1888 struct osd_ios_filldir_buf *fill_buf =
1889 (struct osd_ios_filldir_buf *)buf;
1890 struct osd_thread_info *info = fill_buf->oifb_info;
1891 struct osd_device *dev = fill_buf->oifb_dev;
1892 struct lu_fid *fid = &info->oti_fid;
1893 struct osd_scrub *scrub = &dev->od_scrub;
1894 struct dentry *parent = fill_buf->oifb_dentry;
1895 struct dentry *child;
1896 struct inode *dir = parent->d_inode;
1897 struct inode *inode;
1901 fill_buf->oifb_items++;
1903 /* skip any '.' started names */
1907 scrub->os_lf_scanned++;
1908 child = osd_lookup_one_len(dev, name, parent, namelen);
1909 if (IS_ERR(child)) {
1910 rc = PTR_ERR(child);
1911 CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
1912 osd_name(dev), namelen, name, rc);
1914 } else if (!child->d_inode) {
1916 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode\n",
1917 osd_name(dev), namelen, name);
1921 inode = child->d_inode;
1922 if (S_ISDIR(inode->i_mode)) {
1923 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
1926 CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
1927 "rc = %d\n", osd_name(dev), namelen, name, rc);
1931 if (!S_ISREG(inode->i_mode))
1934 rc = osd_scrub_get_fid(info, dev, inode, fid, true);
1935 if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
1936 rc = osd_obj_map_recover(info, dev, dir, child, fid);
1938 CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
1939 "/lost+found.\n", namelen, name, PFID(fid));
1940 scrub->os_lf_repaired++;
1942 CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
1944 osd_name(dev), namelen, name, PFID(fid), rc);
1948 /* XXX: For MDT-objects, we can move them from /lost+found to namespace
1949 * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
1950 * can process them in furtuer. */
1956 scrub->os_lf_failed++;
1958 /* skip the failure to make the scanning to continue. */
1962 #ifdef HAVE_FILLDIR_USE_CTX
1963 static int osd_ios_varfid_fill(struct dir_context *buf,
1965 static int osd_ios_varfid_fill(void *buf,
1967 const char *name, int namelen,
1968 loff_t offset, __u64 ino, unsigned d_type)
1970 struct osd_ios_filldir_buf *fill_buf =
1971 (struct osd_ios_filldir_buf *)buf;
1972 struct osd_device *dev = fill_buf->oifb_dev;
1973 struct dentry *child;
1977 fill_buf->oifb_items++;
1979 /* skip any '.' started names */
1983 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
1985 RETURN(PTR_ERR(child));
1987 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
1988 fill_buf->oifb_dentry->d_inode, child->d_inode,
1989 NULL, name, namelen, 0);
1990 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
1991 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
1992 osd_ios_varfid_fill);
1998 #ifdef HAVE_FILLDIR_USE_CTX
1999 static int osd_ios_dl_fill(struct dir_context *buf,
2001 static int osd_ios_dl_fill(void *buf,
2003 const char *name, int namelen,
2004 loff_t offset, __u64 ino, unsigned d_type)
2006 struct osd_ios_filldir_buf *fill_buf =
2007 (struct osd_ios_filldir_buf *)buf;
2008 struct osd_device *dev = fill_buf->oifb_dev;
2009 const struct osd_lf_map *map;
2010 struct dentry *child;
2014 fill_buf->oifb_items++;
2016 /* skip any '.' started names */
2020 for (map = osd_dl_maps; map->olm_name != NULL; map++) {
2021 if (map->olm_namelen != namelen)
2024 if (strncmp(map->olm_name, name, namelen) == 0)
2028 if (map->olm_name == NULL)
2031 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2033 RETURN(PTR_ERR(child));
2035 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2036 fill_buf->oifb_dentry->d_inode, child->d_inode,
2037 &map->olm_fid, name, namelen, map->olm_flags);
2043 #ifdef HAVE_FILLDIR_USE_CTX
2044 static int osd_ios_uld_fill(struct dir_context *buf,
2046 static int osd_ios_uld_fill(void *buf,
2048 const char *name, int namelen,
2049 loff_t offset, __u64 ino, unsigned d_type)
2051 struct osd_ios_filldir_buf *fill_buf =
2052 (struct osd_ios_filldir_buf *)buf;
2053 struct osd_device *dev = fill_buf->oifb_dev;
2054 struct dentry *child;
2059 fill_buf->oifb_items++;
2061 /* skip any non-DFID format name */
2065 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2067 RETURN(PTR_ERR(child));
2069 /* skip the start '[' */
2070 sscanf(&name[1], SFID, RFID(&tfid));
2071 if (fid_is_sane(&tfid))
2072 rc = osd_ios_scan_one(fill_buf->oifb_info, fill_buf->oifb_dev,
2073 fill_buf->oifb_dentry->d_inode,
2074 child->d_inode, &tfid, name, namelen, 0);
2082 #ifdef HAVE_FILLDIR_USE_CTX
2083 static int osd_ios_root_fill(struct dir_context *buf,
2085 static int osd_ios_root_fill(void *buf,
2087 const char *name, int namelen,
2088 loff_t offset, __u64 ino, unsigned d_type)
2090 struct osd_ios_filldir_buf *fill_buf =
2091 (struct osd_ios_filldir_buf *)buf;
2092 struct osd_device *dev = fill_buf->oifb_dev;
2093 const struct osd_lf_map *map;
2094 struct dentry *child;
2098 fill_buf->oifb_items++;
2100 /* skip any '.' started names */
2104 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
2105 if (map->olm_namelen != namelen)
2108 if (strncmp(map->olm_name, name, namelen) == 0)
2112 if (map->olm_name == NULL)
2115 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2117 RETURN(PTR_ERR(child));
2118 else if (!child->d_inode)
2119 GOTO(out_put, rc = -ENOENT);
2121 if (!(map->olm_flags & OLF_NO_OI))
2122 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2123 fill_buf->oifb_dentry->d_inode, child->d_inode,
2124 &map->olm_fid, name, namelen, map->olm_flags);
2125 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
2126 rc = osd_ios_new_item(dev, child, map->olm_scandir,
2135 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
2136 struct dentry *dentry, filldir_t filldir)
2138 struct osd_ios_filldir_buf buf = {
2139 .ctx.actor = filldir,
2142 .oifb_dentry = dentry
2145 struct inode *inode = dentry->d_inode;
2150 LASSERT(filldir != NULL);
2152 filp = osd_quasi_file_by_dentry(info->oti_env, dentry);
2153 rc = osd_security_file_alloc(filp);
2159 rc = iterate_dir(filp, &buf.ctx);
2160 } while (rc >= 0 && buf.oifb_items > 0 &&
2161 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
2162 inode->i_fop->release(inode, filp);
2168 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
2169 struct dentry *dentry, filldir_t filldir)
2171 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2172 struct scrub_file *sf = &scrub->os_file;
2173 struct dentry *child;
2177 /* It is existing MDT0 device. We only allow the case of object without
2178 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
2179 * can generate IGIF mode FID for the object and related OI mapping. If
2180 * it is on other MDTs, then becuase file-level backup/restore, related
2181 * OI mapping may be invalid already, we do not know which is the right
2182 * FID for the object. We only allow IGIF objects to reside on the MDT0.
2184 * XXX: For the case of object on non-MDT0 device with neither LMA nor
2185 * "fid" xattr, then something crashed. We cannot re-generate the
2186 * FID directly, instead, the OI scrub will scan the OI structure
2187 * and try to re-generate the LMA from the OI mapping. But if the
2188 * OI mapping crashed or lost also, then we have to give up under
2189 * double failure cases.
2191 spin_lock(&scrub->os_lock);
2192 scrub->os_convert_igif = 1;
2193 spin_unlock(&scrub->os_lock);
2194 child = osd_lookup_one_len_unlocked(dev, dot_lustre_name, dentry,
2195 strlen(dot_lustre_name));
2196 if (IS_ERR(child)) {
2197 if (PTR_ERR(child) != -ENOENT)
2198 RETURN(PTR_ERR(child));
2202 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
2203 * so the client will get IGIF for the ".lustre" object when
2206 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
2207 * it does not know whether there are some old clients cached
2208 * the ".lustre" IGIF during the upgrading. Two choices:
2210 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
2211 * It will allow the old connected clients to access the
2212 * ".lustre" with cached IGIF. But it will cause others
2213 * on the MDT failed to check "fid_is_dot_lustre()".
2215 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
2216 * for ".lustre" in spite of whether there are some clients
2217 * cached the ".lustre" IGIF or not. It enables the check
2218 * "fid_is_dot_lustre()" on the MDT, although it will cause
2219 * that the old connected clients cannot access the ".lustre"
2220 * with the cached IGIF.
2222 * Usually, it is rare case for the old connected clients
2223 * to access the ".lustre" with cached IGIF. So we prefer
2224 * to the solution 2).
2226 inode_lock(dentry->d_inode);
2227 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2228 child->d_inode, &LU_DOT_LUSTRE_FID,
2230 strlen(dot_lustre_name), 0);
2231 inode_unlock(dentry->d_inode);
2232 if (rc == -ENOENT) {
2234 /* It is 1.8 MDT device. */
2235 if (!(sf->sf_flags & SF_UPGRADE)) {
2236 scrub_file_reset(scrub, dev->od_uuid,
2238 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2239 rc = scrub_file_store(info->oti_env, scrub);
2243 } else if (rc == 0) {
2244 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2253 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
2254 struct dentry *dentry, filldir_t filldir)
2256 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2257 struct scrub_file *sf = &scrub->os_file;
2258 struct dentry *child;
2262 if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
2263 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2264 rc = scrub_file_store(info->oti_env, scrub);
2269 child = osd_lookup_one_len_unlocked(dev, ADMIN_USR, dentry,
2271 if (IS_ERR(child)) {
2272 rc = PTR_ERR(child);
2274 inode_lock(dentry->d_inode);
2275 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2276 child->d_inode, NULL, ADMIN_USR,
2277 strlen(ADMIN_USR), 0);
2278 inode_unlock(dentry->d_inode);
2282 if (rc != 0 && rc != -ENOENT)
2285 child = osd_lookup_one_len_unlocked(dev, ADMIN_GRP, dentry,
2288 GOTO(out, rc = PTR_ERR(child));
2290 inode_lock(dentry->d_inode);
2291 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2292 child->d_inode, NULL, ADMIN_GRP,
2293 strlen(ADMIN_GRP), 0);
2294 inode_unlock(dentry->d_inode);
2297 RETURN(rc == -ENOENT ? 0 : rc);
2300 static void osd_initial_OI_scrub(struct osd_thread_info *info,
2301 struct osd_device *dev)
2303 struct osd_ios_item *item = NULL;
2304 scandir_t scandir = osd_ios_general_scan;
2305 filldir_t filldir = osd_ios_root_fill;
2306 struct dentry *dentry = osd_sb(dev)->s_root;
2307 const struct osd_lf_map *map = osd_lf_maps;
2310 /* Lookup IGIF in OI by force for initial OI scrub. */
2311 dev->od_igif_inoi = 1;
2314 /* Don't take inode_lock here since scandir() callbacks
2315 * can call VFS functions which may manully take the
2316 * inode lock itself like iterate_dir(). Since this
2317 * is the case it is best to leave the scandir()
2318 * callbacks to managing the inode lock.
2320 scandir(info, dev, dentry, filldir);
2322 dput(item->oii_dentry);
2326 if (list_empty(&dev->od_ios_list))
2329 item = list_entry(dev->od_ios_list.next,
2330 struct osd_ios_item, oii_list);
2331 list_del_init(&item->oii_list);
2333 LASSERT(item->oii_scandir != NULL);
2334 scandir = item->oii_scandir;
2335 filldir = item->oii_filldir;
2336 dentry = item->oii_dentry;
2339 /* There maybe the case that the object has been removed, but its OI
2340 * mapping is still in the OI file, such as the "CATALOGS" after MDT
2341 * file-level backup/restore. So here cleanup the stale OI mappings. */
2342 while (map->olm_name != NULL) {
2343 struct dentry *child;
2345 if (fid_is_zero(&map->olm_fid)) {
2350 child = osd_lookup_one_len_unlocked(dev, map->olm_name,
2351 osd_sb(dev)->s_root,
2353 if (PTR_ERR(child) == -ENOENT ||
2354 (!IS_ERR(child) && !child->d_inode))
2355 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
2356 NULL, DTO_INDEX_DELETE,
2363 if (!list_empty(&dev->od_index_restore_list)) {
2366 OBD_ALLOC_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2368 CERROR("%s: not enough RAM for rebuild index\n",
2371 while (!list_empty(&dev->od_index_restore_list)) {
2372 struct lustre_index_restore_unit *liru;
2374 liru = list_entry(dev->od_index_restore_list.next,
2375 struct lustre_index_restore_unit,
2377 list_del(&liru->liru_link);
2379 osd_index_restore(info->oti_env, dev, liru,
2380 buf, INDEX_BACKUP_BUFSIZE);
2381 OBD_FREE(liru, liru->liru_len);
2385 OBD_FREE_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2391 char *osd_lf_fid2name(const struct lu_fid *fid)
2393 const struct osd_lf_map *map = osd_lf_maps;
2395 while (map->olm_name != NULL) {
2396 if (!lu_fid_eq(fid, &map->olm_fid)) {
2401 if (map->olm_flags & OLF_SHOW_NAME)
2402 return map->olm_name;
2410 /* OI scrub start/stop */
2412 int osd_scrub_start(const struct lu_env *env, struct osd_device *dev,
2415 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2419 if (dev->od_dt_dev.dd_rdonly)
2422 /* od_otable_mutex: prevent curcurrent start/stop */
2423 mutex_lock(&dev->od_otable_mutex);
2424 rc = scrub_start(osd_scrub_main, scrub, dev, flags);
2425 if (rc == -EALREADY) {
2427 if ((scrub->os_file.sf_flags & SF_AUTO ||
2428 scrub->os_partial_scan) &&
2429 !(flags & SS_AUTO_PARTIAL))
2430 osd_scrub_join(env, dev, flags, false);
2432 mutex_unlock(&dev->od_otable_mutex);
2437 void osd_scrub_stop(struct osd_device *dev)
2439 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2441 /* od_otable_mutex: prevent curcurrent start/stop */
2442 mutex_lock(&dev->od_otable_mutex);
2443 spin_lock(&scrub->os_lock);
2444 scrub->os_paused = 1;
2445 spin_unlock(&scrub->os_lock);
2447 mutex_unlock(&dev->od_otable_mutex);
2450 /* OI scrub setup/cleanup */
2452 static const char osd_scrub_name[] = "OI_scrub";
2454 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev,
2457 struct osd_thread_info *info = osd_oti_get(env);
2458 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2459 struct lvfs_run_ctxt *ctxt = &dev->od_scrub.os_ctxt;
2460 struct scrub_file *sf = &scrub->os_file;
2461 struct super_block *sb = osd_sb(dev);
2462 struct lvfs_run_ctxt saved;
2464 struct inode *inode;
2465 struct lu_fid *fid = &info->oti_fid;
2466 struct osd_inode_id *id = &info->oti_id;
2467 struct dt_object *obj;
2472 memset(&dev->od_scrub, 0, sizeof(struct osd_scrub));
2473 OBD_SET_CTXT_MAGIC(ctxt);
2474 ctxt->pwdmnt = dev->od_mnt;
2475 ctxt->pwd = dev->od_mnt->mnt_root;
2477 init_rwsem(&scrub->os_rwsem);
2478 spin_lock_init(&scrub->os_lock);
2479 INIT_LIST_HEAD(&scrub->os_inconsistent_items);
2480 scrub->os_name = osd_name(dev);
2482 push_ctxt(&saved, ctxt);
2483 filp = filp_open(osd_scrub_name, O_RDWR |
2484 (dev->od_dt_dev.dd_rdonly ? 0 : O_CREAT), 0644);
2486 pop_ctxt(&saved, ctxt);
2487 RETURN(PTR_ERR(filp));
2490 inode = file_inode(filp);
2491 ldiskfs_set_inode_flag(inode, LDISKFS_INODE_JOURNAL_DATA);
2492 if (!dev->od_dt_dev.dd_rdonly) {
2493 /* 'What the @fid is' is not imporatant, because the object
2494 * has no OI mapping, and only is visible inside the OSD.*/
2495 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2496 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
2498 filp_close(filp, NULL);
2499 pop_ctxt(&saved, ctxt);
2504 osd_id_gen(id, inode->i_ino, inode->i_generation);
2505 osd_add_oi_cache(info, dev, id, fid);
2506 filp_close(filp, NULL);
2507 pop_ctxt(&saved, ctxt);
2509 obj = lu2dt(lu_object_find_slice(env, osd2lu_dev(dev), fid, NULL));
2510 if (IS_ERR_OR_NULL(obj))
2511 RETURN(obj ? PTR_ERR(obj) : -ENOENT);
2513 #ifndef HAVE_S_UUID_AS_UUID_T
2514 memcpy(dev->od_uuid.b, sb->s_uuid, sizeof(dev->od_uuid));
2516 uuid_copy(&dev->od_uuid, &sb->s_uuid);
2518 scrub->os_obj = obj;
2519 rc = scrub_file_load(env, scrub);
2520 if (rc == -ENOENT || rc == -EFAULT) {
2521 scrub_file_init(scrub, dev->od_uuid);
2522 /* If the "/O" dir does not exist when mount (indicated by
2523 * osd_device::od_maybe_new), neither for the "/OI_scrub",
2524 * then it is quite probably that the device is a new one,
2525 * under such case, mark it as SIF_NO_HANDLE_OLD_FID.
2527 * For the rare case that "/O" and "OI_scrub" both lost on
2528 * an old device, it can be found and cleared later.
2530 * For the system with "SIF_NO_HANDLE_OLD_FID", we do not
2531 * need to check "filter_fid_18_23" and to convert it to
2532 * "filter_fid" for each object, and all the IGIF should
2533 * have their FID mapping in OI files already. */
2534 if (dev->od_maybe_new && rc == -ENOENT)
2535 sf->sf_internal_flags = SIF_NO_HANDLE_OLD_FID;
2537 } else if (rc < 0) {
2538 GOTO(cleanup_obj, rc);
2540 if (!uuid_equal(&sf->sf_uuid, &dev->od_uuid)) {
2542 "%s: UUID has been changed from %pU to %pU\n",
2543 osd_dev2name(dev), &sf->sf_uuid, &dev->od_uuid);
2544 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
2547 } else if (sf->sf_status == SS_SCANNING) {
2548 sf->sf_status = SS_CRASHED;
2552 if ((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) {
2553 LCONSOLE_WARN("%s: invalid oi count %d, set it to %d\n",
2554 osd_dev2name(dev), sf->sf_oi_count,
2556 sf->sf_oi_count = osd_oi_count;
2561 if (sf->sf_pos_last_checkpoint != 0)
2562 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
2564 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
2567 rc = scrub_file_store(env, scrub);
2569 GOTO(cleanup_obj, rc);
2572 /* Initialize OI files. */
2573 rc = osd_oi_init(info, dev, restored);
2575 GOTO(cleanup_obj, rc);
2577 if (!dev->od_dt_dev.dd_rdonly)
2578 osd_initial_OI_scrub(info, dev);
2580 if (sf->sf_flags & SF_UPGRADE ||
2581 !(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID ||
2582 sf->sf_success_count > 0)) {
2583 dev->od_igif_inoi = 0;
2584 dev->od_check_ff = dev->od_is_ost;
2586 dev->od_igif_inoi = 1;
2587 dev->od_check_ff = 0;
2590 if (sf->sf_flags & SF_INCONSISTENT)
2591 /* The 'od_igif_inoi' will be set under the
2593 * 1) new created system, or
2594 * 2) restored from file-level backup, or
2595 * 3) the upgrading completed.
2597 * The 'od_igif_inoi' may be cleared by OI scrub
2598 * later if found that the system is upgrading. */
2599 dev->od_igif_inoi = 1;
2601 if (!dev->od_dt_dev.dd_rdonly &&
2602 dev->od_auto_scrub_interval != AS_NEVER &&
2603 ((sf->sf_status == SS_PAUSED) ||
2604 (sf->sf_status == SS_CRASHED &&
2605 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2606 SF_UPGRADE | SF_AUTO)) ||
2607 (sf->sf_status == SS_INIT &&
2608 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2610 rc = osd_scrub_start(env, dev, SS_AUTO_FULL);
2613 GOTO(cleanup_oi, rc);
2615 /* it is possible that dcache entries may keep objects after they are
2616 * deleted by OSD. While it looks safe this can cause object data to
2617 * stay until umount causing failures in tests calculating free space,
2618 * e.g. replay-ost-single. Since those dcache entries are not used
2619 * anymore let's just free them after use here */
2620 shrink_dcache_sb(sb);
2624 osd_oi_fini(info, dev);
2626 dt_object_put_nocache(env, scrub->os_obj);
2627 scrub->os_obj = NULL;
2632 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
2634 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2636 LASSERT(dev->od_otable_it == NULL);
2638 if (scrub->os_obj != NULL) {
2639 osd_scrub_stop(dev);
2640 dt_object_put_nocache(env, scrub->os_obj);
2641 scrub->os_obj = NULL;
2645 /* object table based iteration APIs */
2647 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
2648 struct dt_object *dt, __u32 attr)
2650 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
2651 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
2652 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
2653 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2654 struct osd_otable_it *it;
2659 /* od_otable_mutex: prevent curcurrent init/fini */
2660 mutex_lock(&dev->od_otable_mutex);
2661 if (dev->od_otable_it != NULL)
2662 GOTO(out, it = ERR_PTR(-EALREADY));
2666 GOTO(out, it = ERR_PTR(-ENOMEM));
2668 dev->od_otable_it = it;
2670 it->ooi_cache.ooc_consumer_idx = -1;
2671 if (flags & DOIF_OUTUSED)
2672 it->ooi_used_outside = 1;
2674 if (flags & DOIF_RESET)
2677 if (valid & DOIV_ERROR_HANDLE) {
2678 if (flags & DOIF_FAILOUT)
2679 start |= SS_SET_FAILOUT;
2681 start |= SS_CLEAR_FAILOUT;
2684 if (valid & DOIV_DRYRUN) {
2685 if (flags & DOIF_DRYRUN)
2686 start |= SS_SET_DRYRUN;
2688 start |= SS_CLEAR_DRYRUN;
2691 rc = scrub_start(osd_scrub_main, scrub, dev, start & ~SS_AUTO_PARTIAL);
2692 if (rc == -EALREADY) {
2693 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2694 } else if (rc < 0) {
2695 dev->od_otable_it = NULL;
2699 /* We have to start from the begining. */
2700 it->ooi_cache.ooc_pos_preload =
2701 LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2707 mutex_unlock(&dev->od_otable_mutex);
2708 return (struct dt_it *)it;
2711 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2713 struct osd_otable_it *it = (struct osd_otable_it *)di;
2714 struct osd_device *dev = it->ooi_dev;
2716 /* od_otable_mutex: prevent curcurrent init/fini */
2717 mutex_lock(&dev->od_otable_mutex);
2718 scrub_stop(&dev->od_scrub.os_scrub);
2719 LASSERT(dev->od_otable_it == it);
2721 dev->od_otable_it = NULL;
2722 mutex_unlock(&dev->od_otable_mutex);
2726 static int osd_otable_it_get(const struct lu_env *env,
2727 struct dt_it *di, const struct dt_key *key)
2732 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2737 osd_otable_it_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
2739 spin_lock(&scrub->os_lock);
2740 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2741 scrub->os_waiting || !scrub->os_running)
2742 it->ooi_waiting = 0;
2744 it->ooi_waiting = 1;
2745 spin_unlock(&scrub->os_lock);
2747 return !it->ooi_waiting;
2750 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2752 struct osd_otable_it *it = (struct osd_otable_it *)di;
2753 struct osd_device *dev = it->ooi_dev;
2754 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2755 struct osd_otable_cache *ooc = &it->ooi_cache;
2759 LASSERT(it->ooi_user_ready);
2762 if (!scrub->os_running && !it->ooi_used_outside)
2765 if (ooc->ooc_cached_items > 0) {
2766 ooc->ooc_cached_items--;
2767 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2768 ~OSD_OTABLE_IT_CACHE_MASK;
2772 if (it->ooi_all_cached) {
2773 wait_var_event(scrub, !scrub->os_running);
2777 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2778 spin_lock(&scrub->os_lock);
2779 scrub->os_waiting = 0;
2781 spin_unlock(&scrub->os_lock);
2784 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2785 wait_var_event(scrub, osd_otable_it_wakeup(scrub, it));
2787 if (!scrub->os_running && !it->ooi_used_outside)
2790 rc = osd_otable_it_preload(env, it);
2797 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2798 const struct dt_it *di)
2803 static int osd_otable_it_key_size(const struct lu_env *env,
2804 const struct dt_it *di)
2806 return sizeof(__u64);
2809 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2810 struct dt_rec *rec, __u32 attr)
2812 struct osd_otable_it *it = (struct osd_otable_it *)di;
2813 struct osd_otable_cache *ooc = &it->ooi_cache;
2815 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2817 /* Filter out Invald FID already. */
2818 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2819 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2820 PFID((struct lu_fid *)rec),
2821 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2826 static __u64 osd_otable_it_store(const struct lu_env *env,
2827 const struct dt_it *di)
2829 struct osd_otable_it *it = (struct osd_otable_it *)di;
2830 struct osd_otable_cache *ooc = &it->ooi_cache;
2833 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2834 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2836 hash = ooc->ooc_pos_preload;
2841 * Set the OSD layer iteration start position as the specified hash.
2843 static int osd_otable_it_load(const struct lu_env *env,
2844 const struct dt_it *di, __u64 hash)
2846 struct osd_otable_it *it = (struct osd_otable_it *)di;
2847 struct osd_device *dev = it->ooi_dev;
2848 struct osd_otable_cache *ooc = &it->ooi_cache;
2849 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2850 struct osd_iit_param *param = &it->ooi_iit_param;
2854 /* Forbid to set iteration position after iteration started. */
2855 if (it->ooi_user_ready)
2858 LASSERT(!scrub->os_partial_scan);
2860 if (hash > OSD_OTABLE_MAX_HASH)
2861 hash = OSD_OTABLE_MAX_HASH;
2863 /* The hash is the last checkpoint position,
2864 * we will start from the next one. */
2865 ooc->ooc_pos_preload = hash + 1;
2866 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
2867 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2869 it->ooi_user_ready = 1;
2870 if (!scrub->os_full_speed)
2873 memset(param, 0, sizeof(*param));
2874 param->sb = osd_sb(dev);
2875 param->start = ooc->ooc_pos_preload;
2876 param->bg = (ooc->ooc_pos_preload - 1) /
2877 LDISKFS_INODES_PER_GROUP(param->sb);
2878 param->offset = (ooc->ooc_pos_preload - 1) %
2879 LDISKFS_INODES_PER_GROUP(param->sb);
2880 param->gbase = 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
2882 /* Unplug OSD layer iteration by the first next() call. */
2883 rc = osd_otable_it_next(env, (struct dt_it *)it);
2888 static int osd_otable_it_key_rec(const struct lu_env *env,
2889 const struct dt_it *di, void *key_rec)
2894 const struct dt_index_operations osd_otable_ops = {
2896 .init = osd_otable_it_init,
2897 .fini = osd_otable_it_fini,
2898 .get = osd_otable_it_get,
2899 .put = osd_otable_it_put,
2900 .next = osd_otable_it_next,
2901 .key = osd_otable_it_key,
2902 .key_size = osd_otable_it_key_size,
2903 .rec = osd_otable_it_rec,
2904 .store = osd_otable_it_store,
2905 .load = osd_otable_it_load,
2906 .key_rec = osd_otable_it_key_rec,
2910 /* high priority inconsistent items list APIs */
2912 #define SCRUB_BAD_OIMAP_DECAY_INTERVAL 60
2914 int osd_oii_insert(struct osd_device *dev, const struct lu_fid *fid,
2915 struct osd_inode_id *id, int insert)
2917 struct osd_inconsistent_item *oii;
2918 struct osd_scrub *oscrub = &dev->od_scrub;
2919 struct lustre_scrub *lscrub = &oscrub->os_scrub;
2924 if (unlikely(oii == NULL))
2927 INIT_LIST_HEAD(&oii->oii_list);
2928 oii->oii_cache.oic_fid = *fid;
2929 oii->oii_cache.oic_lid = *id;
2930 oii->oii_cache.oic_dev = dev;
2931 oii->oii_insert = insert;
2933 spin_lock(&lscrub->os_lock);
2934 if (lscrub->os_partial_scan) {
2935 __u64 now = ktime_get_real_seconds();
2937 /* If there haven't been errors in a long time,
2938 * decay old count until either the errors are
2939 * gone or we reach the current interval. */
2940 while (unlikely(oscrub->os_bad_oimap_count > 0 &&
2941 oscrub->os_bad_oimap_time +
2942 SCRUB_BAD_OIMAP_DECAY_INTERVAL < now)) {
2943 oscrub->os_bad_oimap_count >>= 1;
2944 oscrub->os_bad_oimap_time +=
2945 SCRUB_BAD_OIMAP_DECAY_INTERVAL;
2948 oscrub->os_bad_oimap_time = now;
2949 if (++oscrub->os_bad_oimap_count >
2950 dev->od_full_scrub_threshold_rate)
2951 lscrub->os_full_scrub = 1;
2954 if (!lscrub->os_running) {
2955 spin_unlock(&lscrub->os_lock);
2960 if (list_empty(&lscrub->os_inconsistent_items))
2962 list_add_tail(&oii->oii_list, &lscrub->os_inconsistent_items);
2963 spin_unlock(&lscrub->os_lock);
2966 wake_up_var(lscrub);
2971 int osd_oii_lookup(struct osd_device *dev, const struct lu_fid *fid,
2972 struct osd_inode_id *id)
2974 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2975 struct osd_inconsistent_item *oii;
2978 spin_lock(&scrub->os_lock);
2979 list_for_each_entry(oii, &scrub->os_inconsistent_items, oii_list) {
2980 if (lu_fid_eq(fid, &oii->oii_cache.oic_fid)) {
2981 *id = oii->oii_cache.oic_lid;
2982 spin_unlock(&scrub->os_lock);
2986 spin_unlock(&scrub->os_lock);
2991 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
2993 struct osd_scrub *scrub = &dev->od_scrub;
2995 scrub_dump(m, &scrub->os_scrub);
2996 seq_printf(m, "lf_scanned: %llu\n"
2998 "lf_failed: %llu\n",
2999 scrub->os_lf_scanned,
3000 scrub->os_scrub.os_file.sf_param & SP_DRYRUN ?
3001 "inconsistent" : "repaired",
3002 scrub->os_lf_repaired,
3003 scrub->os_lf_failed);
3006 typedef int (*scan_dir_helper_t)(const struct lu_env *env,
3007 struct osd_device *dev, struct inode *dir,
3008 struct osd_it_ea *oie);
3010 static int osd_scan_dir(const struct lu_env *env, struct osd_device *dev,
3011 struct inode *inode, scan_dir_helper_t cb)
3013 struct osd_it_ea *oie;
3018 oie = osd_it_dir_init(env, inode, LUDA_TYPE);
3020 RETURN(PTR_ERR(oie));
3022 oie->oie_file.f_pos = 0;
3023 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3029 while (oie->oie_it_dirent <= oie->oie_rd_dirent) {
3030 if (!name_is_dot_or_dotdot(oie->oie_dirent->oied_name,
3031 oie->oie_dirent->oied_namelen))
3032 cb(env, dev, inode, oie);
3034 oie->oie_dirent = (void *)oie->oie_dirent +
3035 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
3036 oie->oie_dirent->oied_namelen);
3038 oie->oie_it_dirent++;
3039 if (oie->oie_it_dirent <= oie->oie_rd_dirent)
3042 if (oie->oie_file.f_pos ==
3043 ldiskfs_get_htree_eof(&oie->oie_file))
3046 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3055 osd_it_dir_fini(env, oie, inode);
3059 static int osd_remove_ml_file(struct osd_thread_info *info,
3060 struct osd_device *dev, struct inode *dir,
3061 struct inode *inode, struct osd_it_ea *oie)
3064 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3065 struct dentry *dentry;
3070 if (scrub->os_file.sf_param & SP_DRYRUN)
3073 th = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
3074 osd_dto_credits_noquota[DTO_INDEX_DELETE] +
3075 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
3077 RETURN(PTR_ERR(th));
3079 dentry = &oie->oie_dentry;
3080 dentry->d_inode = dir;
3081 dentry->d_sb = dir->i_sb;
3082 rc = osd_obj_del_entry(info, dev, dentry, oie->oie_dirent->oied_name,
3083 oie->oie_dirent->oied_namelen, th);
3085 mark_inode_dirty(inode);
3086 ldiskfs_journal_stop(th);
3090 static int osd_scan_ml_file(const struct lu_env *env, struct osd_device *dev,
3091 struct inode *dir, struct osd_it_ea *oie)
3093 struct osd_thread_info *info = osd_oti_get(env);
3094 struct osd_inode_id id;
3095 struct inode *inode;
3096 struct osd_obj_seq *oseq;
3097 struct ost_id *ostid = &info->oti_ostid;
3098 struct lu_fid *fid = &oie->oie_dirent->oied_fid;
3104 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3106 if (!fid_is_sane(fid))
3107 inode = osd_iget_fid(info, dev, &id, fid);
3109 inode = osd_iget(info, dev, &id);
3112 RETURN(PTR_ERR(inode));
3114 fid_to_ostid(fid, ostid);
3115 oseq = osd_seq_load(info, dev, ostid_seq(ostid));
3117 RETURN(PTR_ERR(oseq));
3119 dirn = ostid_id(ostid) & (oseq->oos_subdir_count - 1);
3120 LASSERT(oseq->oos_dirs[dirn] != NULL);
3122 osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
3123 if (((strlen(oseq->oos_root->d_name.name) !=
3124 info->oti_seq_dirent->oied_namelen) ||
3125 strncmp(oseq->oos_root->d_name.name,
3126 info->oti_seq_dirent->oied_name,
3127 info->oti_seq_dirent->oied_namelen) != 0) ||
3128 ((strlen(oseq->oos_dirs[dirn]->d_name.name) !=
3129 info->oti_dir_dirent->oied_namelen) ||
3130 strncmp(oseq->oos_dirs[dirn]->d_name.name,
3131 info->oti_dir_dirent->oied_name,
3132 info->oti_dir_dirent->oied_namelen) != 0) ||
3133 ((strlen(name) != oie->oie_dirent->oied_namelen) ||
3134 strncmp(oie->oie_dirent->oied_name, name,
3135 oie->oie_dirent->oied_namelen) != 0)) {
3136 CDEBUG(D_LFSCK, "%s: the file O/%s/%s/%s is corrupted\n",
3137 osd_name(dev), info->oti_seq_dirent->oied_name,
3138 info->oti_dir_dirent->oied_name,
3139 oie->oie_dirent->oied_name);
3141 rc = osd_remove_ml_file(info, dev, dir, inode, oie);
3148 static int osd_scan_ml_file_dir(const struct lu_env *env,
3149 struct osd_device *dev, struct inode *dir,
3150 struct osd_it_ea *oie)
3152 struct osd_thread_info *info = osd_oti_get(env);
3153 struct inode *inode;
3154 struct osd_inode_id id;
3159 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3160 inode = osd_iget(info, dev, &id);
3162 RETURN(PTR_ERR(inode));
3164 if (!S_ISDIR(inode->i_mode))
3167 info->oti_dir_dirent = oie->oie_dirent;
3168 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file);
3169 info->oti_dir_dirent = NULL;
3176 static int osd_scan_ml_file_seq(const struct lu_env *env,
3177 struct osd_device *dev, struct inode *dir,
3178 struct osd_it_ea *oie)
3180 struct osd_thread_info *info = osd_oti_get(env);
3181 struct inode *inode;
3182 struct osd_inode_id id;
3187 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3188 inode = osd_iget(info, dev, &id);
3190 RETURN(PTR_ERR(inode));
3192 if (!S_ISDIR(inode->i_mode))
3195 info->oti_seq_dirent = oie->oie_dirent;
3196 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file_dir);
3197 info->oti_seq_dirent = NULL;
3204 static int osd_scan_ml_file_main(const struct lu_env *env,
3205 struct osd_device *dev)
3207 return osd_scan_dir(env, dev, dev->od_ost_map->om_root->d_inode,
3208 osd_scan_ml_file_seq);