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 sf->sf_flags |= SF_UPGRADE;
294 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
295 dev->od_check_ff = 1;
296 rc = osd_scrub_convert_ff(info, dev, inode, fid);
303 if ((val == SCRUB_NEXT_NOLMA) &&
304 (!scrub->os_convert_igif || OBD_FAIL_CHECK(OBD_FAIL_FID_NOLMA)))
307 if ((oii != NULL && oii->oii_insert) || (val == SCRUB_NEXT_NOLMA)) {
308 ops = DTO_INDEX_INSERT;
313 rc = osd_oi_lookup(info, dev, fid, lid2,
314 (val == SCRUB_NEXT_OSTOBJ ||
315 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0);
318 ops = DTO_INDEX_INSERT;
319 else if (rc != -ESTALE)
324 inode = osd_iget(info, dev, lid);
327 /* Someone removed the inode. */
328 if (rc == -ENOENT || rc == -ESTALE)
335 case SCRUB_NEXT_NOLMA:
336 sf->sf_flags |= SF_UPGRADE;
337 if (!(sf->sf_param & SP_DRYRUN)) {
338 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
343 if (!(sf->sf_flags & SF_INCONSISTENT))
344 dev->od_igif_inoi = 0;
346 case SCRUB_NEXT_OSTOBJ:
347 sf->sf_flags |= SF_INCONSISTENT;
348 case SCRUB_NEXT_OSTOBJ_OLD:
353 } else if (osd_id_eq(lid, lid2)) {
355 sf->sf_items_updated++;
359 if (!scrub->os_partial_scan) {
360 spin_lock(&scrub->os_lock);
361 scrub->os_full_speed = 1;
362 spin_unlock(&scrub->os_lock);
364 sf->sf_flags |= SF_INCONSISTENT;
366 /* XXX: If the device is restored from file-level backup, then
367 * some IGIFs may have been already in OI files, and some
368 * may be not yet. Means upgrading from 1.8 may be partly
369 * processed, but some clients may hold some immobilized
370 * IGIFs, and use them to access related objects. Under
371 * such case, OSD does not know whether an given IGIF has
372 * been processed or to be processed, and it also cannot
373 * generate local ino#/gen# directly from the immobilized
374 * IGIF because of the backup/restore. Then force OSD to
375 * lookup the given IGIF in OI files, and if no entry,
376 * then ask the client to retry after upgrading completed.
377 * No better choice. */
378 dev->od_igif_inoi = 1;
381 rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops, false,
382 (val == SCRUB_NEXT_OSTOBJ ||
383 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0,
386 if (scrub->os_in_prior)
387 sf->sf_items_updated_prior++;
389 sf->sf_items_updated++;
391 if (ops == DTO_INDEX_INSERT && val == 0 && !exist) {
392 int idx = osd_oi_fid2idx(dev, fid);
394 sf->sf_flags |= SF_RECREATED;
395 if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
396 ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
404 sf->sf_items_failed++;
405 if (sf->sf_pos_first_inconsistent == 0 ||
406 sf->sf_pos_first_inconsistent > lid->oii_ino)
407 sf->sf_pos_first_inconsistent = lid->oii_ino;
412 /* There may be conflict unlink during the OI scrub,
413 * if happend, then remove the new added OI mapping. */
414 if (ops == DTO_INDEX_INSERT && inode != NULL && !IS_ERR(inode) &&
415 unlikely(ldiskfs_test_inode_state(inode,
416 LDISKFS_STATE_LUSTRE_DESTROY)))
417 osd_scrub_refresh_mapping(info, dev, fid, lid,
418 DTO_INDEX_DELETE, false,
419 (val == SCRUB_NEXT_OSTOBJ ||
420 val == SCRUB_NEXT_OSTOBJ_OLD) ?
421 OI_KNOWN_ON_OST : 0, NULL);
422 up_write(&scrub->os_rwsem);
428 spin_lock(&scrub->os_lock);
429 if (likely(!list_empty(&oii->oii_list)))
430 list_del(&oii->oii_list);
431 spin_unlock(&scrub->os_lock);
436 RETURN(sf->sf_param & SP_FAILOUT ? rc : 0);
439 /* iteration engine */
441 typedef int (*osd_iit_next_policy)(struct osd_thread_info *info,
442 struct osd_device *dev,
443 struct osd_iit_param *param,
444 struct osd_idmap_cache **oic,
447 typedef int (*osd_iit_exec_policy)(struct osd_thread_info *info,
448 struct osd_device *dev,
449 struct osd_iit_param *param,
450 struct osd_idmap_cache *oic,
451 bool *noslot, int rc);
453 static int osd_iit_next(struct osd_iit_param *param, __u64 *pos)
458 param->offset = ldiskfs_find_next_bit(param->bitmap->b_data,
459 LDISKFS_INODES_PER_GROUP(param->sb), param->offset);
460 if (param->offset >= LDISKFS_INODES_PER_GROUP(param->sb)) {
461 *pos = 1 + (param->bg+1) * LDISKFS_INODES_PER_GROUP(param->sb);
462 return SCRUB_NEXT_BREAK;
465 offset = param->offset++;
466 if (unlikely(*pos == param->gbase + offset && *pos != param->start)) {
467 /* We should NOT find the same object more than once. */
468 CERROR("%s: scan the same object multiple times at the pos: "
469 "group = %u, base = %u, offset = %u, start = %u\n",
470 osd_sb2name(param->sb), (__u32)param->bg, param->gbase,
471 offset, param->start);
475 *pos = param->gbase + offset;
480 * \retval SCRUB_NEXT_OSTOBJ_OLD: FID-on-OST
481 * \retval 0: FID-on-MDT
483 static int osd_scrub_check_local_fldb(struct osd_thread_info *info,
484 struct osd_device *dev,
487 /* XXX: The initial OI scrub will scan the top level /O to generate
488 * a small local FLDB according to the <seq>. If the given FID
489 * is in the local FLDB, then it is FID-on-OST; otherwise it's
490 * quite possible for FID-on-MDT. */
492 return SCRUB_NEXT_OSTOBJ_OLD;
497 static int osd_scrub_get_fid(struct osd_thread_info *info,
498 struct osd_device *dev, struct inode *inode,
499 struct lu_fid *fid, bool scrub)
501 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
502 bool has_lma = false;
505 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
506 &info->oti_ost_attrs);
509 if (lma->lma_compat & LMAC_NOT_IN_OI ||
510 lma->lma_incompat & LMAI_AGENT)
511 return SCRUB_NEXT_CONTINUE;
513 *fid = lma->lma_self_fid;
517 if (lma->lma_compat & LMAC_FID_ON_OST)
518 return SCRUB_NEXT_OSTOBJ;
520 if (fid_is_idif(fid))
521 return SCRUB_NEXT_OSTOBJ_OLD;
523 /* For local object. */
524 if (fid_is_internal(fid))
527 /* For external visible MDT-object with non-normal FID. */
528 if (fid_is_namespace_visible(fid) && !fid_is_norm(fid))
531 /* For the object with normal FID, it may be MDT-object,
532 * or may be 2.4 OST-object, need further distinguish.
533 * Fall through to next section. */
536 if (rc == -ENODATA || rc == 0) {
537 rc = osd_get_idif(info, inode, &info->oti_obj_dentry, fid);
540 /* It is 2.3 or older OST-object. */
541 rc = SCRUB_NEXT_OSTOBJ_OLD;
547 /* It is FID-on-OST, but we do not know how
548 * to generate its FID, ignore it directly. */
549 rc = SCRUB_NEXT_CONTINUE;
551 /* It is 2.4 or newer OST-object. */
552 rc = SCRUB_NEXT_OSTOBJ_OLD;
560 if (dev->od_scrub.os_scrub.os_convert_igif) {
561 lu_igif_build(fid, inode->i_ino,
562 inode->i_generation);
564 rc = SCRUB_NEXT_NOLMA;
568 /* It may be FID-on-OST, or may be FID for
569 * non-MDT0, anyway, we do not know how to
570 * generate its FID, ignore it directly. */
571 rc = SCRUB_NEXT_CONTINUE;
576 /* For OI scrub case only: the object has LMA but has no ff
577 * (or ff crashed). It may be MDT-object, may be OST-object
578 * with crashed ff. The last check is local FLDB. */
579 rc = osd_scrub_check_local_fldb(info, dev, fid);
585 static int osd_iit_iget(struct osd_thread_info *info, struct osd_device *dev,
586 struct lu_fid *fid, struct osd_inode_id *lid, __u32 pos,
587 struct super_block *sb, bool scrub)
593 /* Not handle the backend root object and agent parent object.
594 * They are neither visible to namespace nor have OI mappings. */
595 if (unlikely(pos == osd_sb(dev)->s_root->d_inode->i_ino ||
596 is_remote_parent_ino(dev, pos)))
597 RETURN(SCRUB_NEXT_CONTINUE);
599 /* Skip project quota inode since it is greater than s_first_ino. */
600 #ifdef HAVE_PROJECT_QUOTA
601 if (ldiskfs_has_feature_project(sb) &&
602 pos == le32_to_cpu(LDISKFS_SB(sb)->s_es->s_prj_quota_inum))
603 RETURN(SCRUB_NEXT_CONTINUE);
606 osd_id_gen(lid, pos, OSD_OII_NOGEN);
607 inode = osd_iget(info, dev, lid);
610 /* The inode may be removed after bitmap searching, or the
611 * file is new created without inode initialized yet.
612 * LU-15754: After "new primitive: discard_new_inode()" change
613 * in the kernel find_inode_fast() returns -ESTALE, but
614 * iget_locked replaces it to the NULL and finally
615 * ldiskfs_inode_attach_jinode() returns -ENOMEM
616 * Let's skip an inode if -ENOMEM returned.
618 if (rc == -ENOENT || rc == -ESTALE || rc == -ENOMEM)
619 RETURN(SCRUB_NEXT_CONTINUE);
621 CDEBUG(D_LFSCK, "%s: fail to read inode, ino# = %u: "
622 "rc = %d\n", osd_dev2name(dev), pos, rc);
626 if (dev->od_is_ost && S_ISREG(inode->i_mode) && inode->i_nlink > 1)
627 dev->od_scrub.os_scrub.os_has_ml_file = 1;
630 ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB)) {
631 /* Only skip it for the first OI scrub accessing. */
632 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
633 GOTO(put, rc = SCRUB_NEXT_NOSCRUB);
636 rc = osd_scrub_get_fid(info, dev, inode, fid, scrub);
645 static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
646 struct osd_iit_param *param,
647 struct osd_idmap_cache **oic, const bool noslot)
649 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
651 struct osd_inode_id *lid;
654 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0)
655 wait_var_event_timeout(
657 !list_empty(&scrub->os_inconsistent_items) ||
658 kthread_should_stop(),
659 cfs_time_seconds(cfs_fail_val));
661 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_CRASH)) {
662 spin_lock(&scrub->os_lock);
663 scrub->os_running = 0;
664 spin_unlock(&scrub->os_lock);
665 return SCRUB_NEXT_CRASH;
668 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_FATAL))
669 return SCRUB_NEXT_FATAL;
671 if (kthread_should_stop())
672 return SCRUB_NEXT_EXIT;
674 if (!list_empty(&scrub->os_inconsistent_items)) {
675 spin_lock(&scrub->os_lock);
676 if (likely(!list_empty(&scrub->os_inconsistent_items))) {
677 struct osd_inconsistent_item *oii;
679 oii = list_entry(scrub->os_inconsistent_items.next,
680 struct osd_inconsistent_item, oii_list);
682 *oic = &oii->oii_cache;
683 scrub->os_in_prior = 1;
684 spin_unlock(&scrub->os_lock);
688 spin_unlock(&scrub->os_lock);
692 return SCRUB_NEXT_WAIT;
694 rc = osd_iit_next(param, &scrub->os_pos_current);
698 *oic = &dev->od_scrub.os_oic;
699 fid = &(*oic)->oic_fid;
700 lid = &(*oic)->oic_lid;
701 rc = osd_iit_iget(info, dev, fid, lid,
702 scrub->os_pos_current, param->sb, true);
706 static int osd_preload_next(struct osd_thread_info *info,
707 struct osd_device *dev, struct osd_iit_param *param,
708 struct osd_idmap_cache **oic, const bool noslot)
710 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
711 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
714 if (scrub->os_running &&
715 ooc->ooc_pos_preload >= scrub->os_pos_current)
716 return SCRUB_NEXT_EXIT;
718 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
722 rc = osd_iit_iget(info, dev,
723 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
724 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
725 ooc->ooc_pos_preload, param->sb, false);
730 osd_scrub_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
732 spin_lock(&scrub->os_lock);
733 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
734 !list_empty(&scrub->os_inconsistent_items) ||
735 it->ooi_waiting || kthread_should_stop())
736 scrub->os_waiting = 0;
738 scrub->os_waiting = 1;
739 spin_unlock(&scrub->os_lock);
741 return !scrub->os_waiting;
744 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
745 struct osd_iit_param *param,
746 struct osd_idmap_cache *oic, bool *noslot, int rc)
748 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
749 struct scrub_file *sf = &scrub->os_file;
750 struct osd_otable_it *it = dev->od_otable_it;
751 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
754 case SCRUB_NEXT_NOSCRUB:
755 down_write(&scrub->os_rwsem);
756 scrub->os_new_checked++;
757 sf->sf_items_noscrub++;
758 up_write(&scrub->os_rwsem);
759 case SCRUB_NEXT_CONTINUE:
760 case SCRUB_NEXT_WAIT:
764 rc = osd_scrub_check_update(info, dev, oic, rc);
766 spin_lock(&scrub->os_lock);
767 scrub->os_in_prior = 0;
768 spin_unlock(&scrub->os_lock);
772 rc = scrub_checkpoint(info->oti_env, scrub);
774 CDEBUG(D_LFSCK, "%s: fail to checkpoint, pos = %llu: "
775 "rc = %d\n", osd_scrub2name(scrub),
776 scrub->os_pos_current, rc);
777 /* Continue, as long as the scrub itself can go ahead. */
780 if (scrub->os_in_prior) {
781 spin_lock(&scrub->os_lock);
782 scrub->os_in_prior = 0;
783 spin_unlock(&scrub->os_lock);
788 if (it != NULL && it->ooi_waiting && ooc != NULL &&
789 ooc->ooc_pos_preload < scrub->os_pos_current) {
790 spin_lock(&scrub->os_lock);
793 spin_unlock(&scrub->os_lock);
796 if (rc == SCRUB_NEXT_CONTINUE)
799 if (scrub->os_full_speed || !ooc || osd_scrub_has_window(scrub, ooc)) {
805 wait_var_event(scrub, osd_scrub_wakeup(scrub, it));
807 if (!ooc || osd_scrub_has_window(scrub, ooc))
814 static int osd_preload_exec(struct osd_thread_info *info,
815 struct osd_device *dev, struct osd_iit_param *param,
816 struct osd_idmap_cache *oic, bool *noslot, int rc)
818 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
821 ooc->ooc_cached_items++;
822 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
823 ~OSD_OTABLE_IT_CACHE_MASK;
825 return rc > 0 ? 0 : rc;
828 #define SCRUB_IT_ALL 1
829 #define SCRUB_IT_CRASH 2
831 static void osd_scrub_join(const struct lu_env *env, struct osd_device *dev,
832 __u32 flags, bool inconsistent)
834 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
835 struct scrub_file *sf = &scrub->os_file;
839 LASSERT(!(flags & SS_AUTO_PARTIAL));
841 down_write(&scrub->os_rwsem);
842 spin_lock(&scrub->os_lock);
843 scrub->os_in_join = 1;
844 if (flags & SS_SET_FAILOUT)
845 sf->sf_param |= SP_FAILOUT;
846 else if (flags & SS_CLEAR_FAILOUT)
847 sf->sf_param &= ~SP_FAILOUT;
849 if (flags & SS_SET_DRYRUN)
850 sf->sf_param |= SP_DRYRUN;
851 else if (flags & SS_CLEAR_DRYRUN)
852 sf->sf_param &= ~SP_DRYRUN;
854 if (flags & SS_RESET) {
855 scrub_file_reset(scrub, dev->od_uuid,
856 inconsistent ? SF_INCONSISTENT : 0);
857 sf->sf_status = SS_SCANNING;
860 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
861 scrub->os_full_speed = 1;
863 scrub->os_full_speed = 0;
865 if (flags & SS_AUTO_FULL) {
866 sf->sf_flags |= SF_AUTO;
867 scrub->os_full_speed = 1;
869 spin_unlock(&scrub->os_lock);
871 scrub->os_new_checked = 0;
872 if (sf->sf_pos_last_checkpoint != 0)
873 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
875 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
877 scrub->os_pos_current = sf->sf_pos_latest_start;
878 sf->sf_time_latest_start = ktime_get_real_seconds();
879 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
880 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
881 rc = scrub_file_store(env, scrub);
883 spin_lock(&scrub->os_lock);
884 scrub->os_waiting = 0;
885 scrub->os_paused = 0;
886 scrub->os_partial_scan = 0;
887 scrub->os_in_join = 0;
888 scrub->os_full_scrub = 0;
889 spin_unlock(&scrub->os_lock);
891 up_write(&scrub->os_rwsem);
893 CDEBUG(D_LFSCK, "%s: joined in the OI scrub with flag %u: rc = %d\n",
894 osd_scrub2name(scrub), flags, rc);
899 static int osd_inode_iteration(struct osd_thread_info *info,
900 struct osd_device *dev, __u32 max, bool preload)
902 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
903 struct scrub_file *sf = &scrub->os_file;
904 osd_iit_next_policy next;
905 osd_iit_exec_policy exec;
908 struct osd_iit_param *param;
917 param = &dev->od_scrub.os_iit_param;
918 memset(param, 0, sizeof(*param));
919 param->sb = osd_sb(dev);
921 while (scrub->os_partial_scan && !scrub->os_in_join) {
922 struct osd_idmap_cache *oic = NULL;
924 rc = osd_scrub_next(info, dev, param, &oic, noslot);
926 case SCRUB_NEXT_EXIT:
928 case SCRUB_NEXT_CRASH:
929 RETURN(SCRUB_IT_CRASH);
930 case SCRUB_NEXT_FATAL:
932 case SCRUB_NEXT_WAIT: {
933 struct kstatfs *ksfs = &info->oti_ksfs;
936 if (dev->od_full_scrub_ratio == OFSR_NEVER ||
937 unlikely(sf->sf_items_updated_prior == 0))
940 if (dev->od_full_scrub_ratio == OFSR_DIRECTLY ||
941 scrub->os_full_scrub) {
942 osd_scrub_join(info->oti_env, dev,
943 SS_AUTO_FULL | SS_RESET, true);
947 rc = param->sb->s_op->statfs(param->sb->s_root, ksfs);
949 __u64 used = ksfs->f_files - ksfs->f_ffree;
951 used = div64_u64(used, sf->sf_items_updated_prior);
952 /* If we hit too much inconsistent OI
953 * mappings during the partial scan,
954 * then scan the device completely. */
955 if (used < dev->od_full_scrub_ratio) {
956 osd_scrub_join(info->oti_env, dev,
957 SS_AUTO_FULL | SS_RESET, true);
963 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) &&
967 saved_flags = sf->sf_flags;
968 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
969 SF_UPGRADE | SF_AUTO);
970 sf->sf_status = SS_COMPLETED;
973 kthread_should_stop() ||
974 !scrub->os_partial_scan ||
976 !list_empty(&scrub->os_inconsistent_items));
977 sf->sf_flags = saved_flags;
978 sf->sf_status = SS_SCANNING;
980 if (kthread_should_stop())
983 if (!scrub->os_partial_scan || scrub->os_in_join)
989 LASSERTF(rc == 0, "rc = %d\n", rc);
991 osd_scrub_exec(info, dev, param, oic, &noslot, rc);
998 wait_var_event(scrub,
999 kthread_should_stop() ||
1000 !scrub->os_in_join);
1002 if (kthread_should_stop())
1008 next = osd_scrub_next;
1009 exec = osd_scrub_exec;
1010 pos = &scrub->os_pos_current;
1011 count = &scrub->os_new_checked;
1012 param->start = *pos;
1013 param->bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param->sb);
1015 (*pos - 1) % LDISKFS_INODES_PER_GROUP(param->sb);
1017 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1019 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1021 next = osd_preload_next;
1022 exec = osd_preload_exec;
1023 pos = &ooc->ooc_pos_preload;
1024 count = &ooc->ooc_cached_items;
1025 param = &dev->od_otable_it->ooi_iit_param;
1029 limit = le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count);
1030 while (*pos <= limit && *count < max) {
1031 struct ldiskfs_group_desc *desc;
1032 bool next_group = false;
1034 desc = ldiskfs_get_group_desc(param->sb, param->bg, NULL);
1038 if (desc->bg_flags & cpu_to_le16(LDISKFS_BG_INODE_UNINIT)) {
1043 param->bitmap = ldiskfs_read_inode_bitmap(param->sb, param->bg);
1044 if (IS_ERR_OR_NULL(param->bitmap)) {
1045 if (param->bitmap) {
1046 rc = PTR_ERR(param->bitmap);
1047 param->bitmap = NULL;
1051 CERROR("%s: fail to read bitmap for %u, scrub will stop, urgent mode: rc = %d\n",
1052 osd_scrub2name(scrub), (__u32)param->bg, rc);
1057 struct osd_idmap_cache *oic = NULL;
1060 ldiskfs_itable_unused_count(param->sb, desc) >=
1061 LDISKFS_INODES_PER_GROUP(param->sb)) {
1066 rc = next(info, dev, param, &oic, noslot);
1068 case SCRUB_NEXT_BREAK:
1071 case SCRUB_NEXT_EXIT:
1072 brelse(param->bitmap);
1074 case SCRUB_NEXT_CRASH:
1075 brelse(param->bitmap);
1076 RETURN(SCRUB_IT_CRASH);
1077 case SCRUB_NEXT_FATAL:
1078 brelse(param->bitmap);
1082 rc = exec(info, dev, param, oic, &noslot, rc);
1083 } while (!rc && *pos <= limit && *count < max);
1086 if (param->bitmap) {
1087 brelse(param->bitmap);
1088 param->bitmap = NULL;
1098 param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1099 *pos = param->gbase;
1100 param->start = *pos;
1105 RETURN(SCRUB_IT_ALL);
1111 static int osd_otable_it_preload(const struct lu_env *env,
1112 struct osd_otable_it *it)
1114 struct osd_device *dev = it->ooi_dev;
1115 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1116 struct osd_otable_cache *ooc = &it->ooi_cache;
1120 rc = osd_inode_iteration(osd_oti_get(env), dev,
1121 OSD_OTABLE_IT_CACHE_SIZE, true);
1122 if (rc == SCRUB_IT_ALL)
1123 it->ooi_all_cached = 1;
1125 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1126 spin_lock(&scrub->os_lock);
1127 scrub->os_waiting = 0;
1129 spin_unlock(&scrub->os_lock);
1132 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1135 static int osd_scan_ml_file_main(const struct lu_env *env,
1136 struct osd_device *dev);
1138 static int osd_scrub_main(void *args)
1141 struct osd_device *dev = (struct osd_device *)args;
1142 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1146 rc = lu_env_init(&env, LCT_LOCAL | LCT_DT_THREAD);
1148 CDEBUG(D_LFSCK, "%s: OI scrub fail to init env: rc = %d\n",
1149 osd_scrub2name(scrub), rc);
1153 rc = scrub_thread_prep(&env, scrub, dev->od_uuid,
1154 LDISKFS_FIRST_INO(osd_sb(dev)) + 1);
1156 CDEBUG(D_LFSCK, "%s: OI scrub fail to scrub prep: rc = %d\n",
1157 osd_scrub2name(scrub), rc);
1161 if (!scrub->os_full_speed && !scrub->os_partial_scan) {
1162 struct osd_otable_it *it = dev->od_otable_it;
1163 struct osd_otable_cache *ooc = &it->ooi_cache;
1165 wait_var_event(scrub,
1166 it->ooi_user_ready || kthread_should_stop());
1167 if (kthread_should_stop())
1170 scrub->os_pos_current = ooc->ooc_pos_preload;
1173 CDEBUG(D_LFSCK, "%s: OI scrub start, flags = 0x%x, pos = %llu\n",
1174 osd_scrub2name(scrub), scrub->os_start_flags,
1175 scrub->os_pos_current);
1177 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1178 if (unlikely(rc == SCRUB_IT_CRASH)) {
1179 spin_lock(&scrub->os_lock);
1180 scrub->os_running = 0;
1181 spin_unlock(&scrub->os_lock);
1182 GOTO(out, rc = -EINVAL);
1185 if (scrub->os_has_ml_file) {
1186 ret = osd_scan_ml_file_main(&env, dev);
1195 dev->od_igif_inoi = 1;
1196 dev->od_check_ff = 0;
1198 rc = scrub_thread_post(&env, &dev->od_scrub.os_scrub, rc);
1199 CDEBUG(D_LFSCK, "%s: OI scrub: stop, pos = %llu: rc = %d\n",
1200 osd_scrub2name(scrub), scrub->os_pos_current, rc);
1203 while (!list_empty(&scrub->os_inconsistent_items)) {
1204 struct osd_inconsistent_item *oii;
1206 oii = list_entry(scrub->os_inconsistent_items.next,
1207 struct osd_inconsistent_item, oii_list);
1208 list_del_init(&oii->oii_list);
1215 spin_lock(&scrub->os_lock);
1216 scrub->os_running = 0;
1217 spin_unlock(&scrub->os_lock);
1218 if (xchg(&scrub->os_task, NULL) == NULL)
1219 /* scrub_stop() is waiting, we need to synchronize */
1220 wait_var_event(scrub, kthread_should_stop());
1225 /* initial OI scrub */
1227 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1228 struct dentry *, filldir_t filldir);
1230 #ifdef HAVE_FILLDIR_USE_CTX
1231 static int osd_ios_varfid_fill(struct dir_context *buf, const char *name,
1232 int namelen, loff_t offset, __u64 ino,
1234 static int osd_ios_lf_fill(struct dir_context *buf, const char *name,
1235 int namelen, loff_t offset, __u64 ino,
1237 static int osd_ios_dl_fill(struct dir_context *buf, const char *name,
1238 int namelen, loff_t offset, __u64 ino,
1240 static int osd_ios_uld_fill(struct dir_context *buf, const char *name,
1241 int namelen, loff_t offset, __u64 ino,
1244 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1245 loff_t offset, __u64 ino, unsigned d_type);
1246 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1247 loff_t offset, __u64 ino, unsigned d_type);
1248 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1249 loff_t offset, __u64 ino, unsigned d_type);
1250 static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
1251 loff_t offset, __u64 ino, unsigned d_type);
1255 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1256 struct dentry *dentry, filldir_t filldir);
1258 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1259 struct dentry *dentry, filldir_t filldir);
1262 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1263 struct dentry *dentry, filldir_t filldir);
1267 struct lu_fid olm_fid;
1270 scandir_t olm_scandir;
1271 filldir_t olm_filldir;
1274 /* Add the new introduced local files in the list in the future. */
1275 static const struct osd_lf_map osd_lf_maps[] = {
1278 .olm_name = CATLIST,
1280 .f_seq = FID_SEQ_LOCAL_FILE,
1281 .f_oid = LLOG_CATALOGS_OID,
1283 .olm_flags = OLF_SHOW_NAME,
1284 .olm_namelen = sizeof(CATLIST) - 1,
1289 .olm_name = MOUNT_CONFIGS_DIR,
1291 .f_seq = FID_SEQ_LOCAL_FILE,
1292 .f_oid = MGS_CONFIGS_OID,
1294 .olm_flags = OLF_SCAN_SUBITEMS,
1295 .olm_namelen = sizeof(MOUNT_CONFIGS_DIR) - 1,
1296 .olm_scandir = osd_ios_general_scan,
1297 .olm_filldir = osd_ios_varfid_fill,
1300 /* NIDTBL_VERSIONS */
1302 .olm_name = MGS_NIDTBL_DIR,
1303 .olm_flags = OLF_SCAN_SUBITEMS,
1304 .olm_namelen = sizeof(MGS_NIDTBL_DIR) - 1,
1305 .olm_scandir = osd_ios_general_scan,
1306 .olm_filldir = osd_ios_varfid_fill,
1311 .olm_name = MDT_ORPHAN_DIR,
1312 .olm_namelen = sizeof(MDT_ORPHAN_DIR) - 1,
1319 .f_seq = FID_SEQ_ROOT,
1320 .f_oid = FID_OID_ROOT,
1322 .olm_flags = OLF_SCAN_SUBITEMS | OLF_HIDE_FID,
1323 .olm_namelen = sizeof("ROOT") - 1,
1324 .olm_scandir = osd_ios_ROOT_scan,
1327 /* changelog_catalog */
1329 .olm_name = CHANGELOG_CATALOG,
1330 .olm_namelen = sizeof(CHANGELOG_CATALOG) - 1,
1333 /* changelog_users */
1335 .olm_name = CHANGELOG_USERS,
1336 .olm_namelen = sizeof(CHANGELOG_USERS) - 1,
1343 .f_seq = FID_SEQ_LOCAL_FILE,
1344 .f_oid = FLD_INDEX_OID,
1346 .olm_flags = OLF_SHOW_NAME,
1347 .olm_namelen = sizeof("fld") - 1,
1352 .olm_name = LAST_RCVD,
1354 .f_seq = FID_SEQ_LOCAL_FILE,
1355 .f_oid = LAST_RECV_OID,
1357 .olm_flags = OLF_SHOW_NAME,
1358 .olm_namelen = sizeof(LAST_RCVD) - 1,
1363 .olm_name = REPLY_DATA,
1365 .f_seq = FID_SEQ_LOCAL_FILE,
1366 .f_oid = REPLY_DATA_OID,
1368 .olm_flags = OLF_SHOW_NAME,
1369 .olm_namelen = sizeof(REPLY_DATA) - 1,
1374 .olm_name = LOV_OBJID,
1376 .f_seq = FID_SEQ_LOCAL_FILE,
1377 .f_oid = MDD_LOV_OBJ_OID,
1379 .olm_flags = OLF_SHOW_NAME,
1380 .olm_namelen = sizeof(LOV_OBJID) - 1,
1385 .olm_name = LOV_OBJSEQ,
1387 .f_seq = FID_SEQ_LOCAL_FILE,
1388 .f_oid = MDD_LOV_OBJ_OSEQ,
1390 .olm_flags = OLF_SHOW_NAME,
1391 .olm_namelen = sizeof(LOV_OBJSEQ) - 1,
1396 .olm_name = QMT_DIR,
1397 .olm_flags = OLF_SCAN_SUBITEMS,
1398 .olm_namelen = sizeof(QMT_DIR) - 1,
1399 .olm_scandir = osd_ios_general_scan,
1400 .olm_filldir = osd_ios_varfid_fill,
1405 .olm_name = QSD_DIR,
1406 .olm_flags = OLF_SCAN_SUBITEMS,
1407 .olm_namelen = sizeof(QSD_DIR) - 1,
1408 .olm_scandir = osd_ios_general_scan,
1409 .olm_filldir = osd_ios_varfid_fill,
1414 .olm_name = "seq_ctl",
1416 .f_seq = FID_SEQ_LOCAL_FILE,
1417 .f_oid = FID_SEQ_CTL_OID,
1419 .olm_flags = OLF_SHOW_NAME,
1420 .olm_namelen = sizeof("seq_ctl") - 1,
1425 .olm_name = "seq_srv",
1427 .f_seq = FID_SEQ_LOCAL_FILE,
1428 .f_oid = FID_SEQ_SRV_OID,
1430 .olm_flags = OLF_SHOW_NAME,
1431 .olm_namelen = sizeof("seq_srv") - 1,
1436 .olm_name = HEALTH_CHECK,
1438 .f_seq = FID_SEQ_LOCAL_FILE,
1439 .f_oid = OFD_HEALTH_CHECK_OID,
1441 .olm_flags = OLF_SHOW_NAME,
1442 .olm_namelen = sizeof(HEALTH_CHECK) - 1,
1447 .olm_name = LFSCK_DIR,
1448 .olm_flags = OLF_SCAN_SUBITEMS,
1449 .olm_namelen = sizeof(LFSCK_DIR) - 1,
1450 .olm_scandir = osd_ios_general_scan,
1451 .olm_filldir = osd_ios_varfid_fill,
1454 /* lfsck_bookmark */
1456 .olm_name = LFSCK_BOOKMARK,
1457 .olm_namelen = sizeof(LFSCK_BOOKMARK) - 1,
1462 .olm_name = LFSCK_LAYOUT,
1463 .olm_namelen = sizeof(LFSCK_LAYOUT) - 1,
1466 /* lfsck_namespace */
1468 .olm_name = LFSCK_NAMESPACE,
1469 .olm_namelen = sizeof(LFSCK_NAMESPACE) - 1,
1472 /* OBJECTS, upgrade from old device */
1474 .olm_name = OBJECTS,
1475 .olm_flags = OLF_SCAN_SUBITEMS,
1476 .olm_namelen = sizeof(OBJECTS) - 1,
1477 .olm_scandir = osd_ios_OBJECTS_scan,
1480 /* lquota_v2.user, upgrade from old device */
1482 .olm_name = "lquota_v2.user",
1483 .olm_namelen = sizeof("lquota_v2.user") - 1,
1486 /* lquota_v2.group, upgrade from old device */
1488 .olm_name = "lquota_v2.group",
1489 .olm_namelen = sizeof("lquota_v2.group") - 1,
1492 /* LAST_GROUP, upgrade from old device */
1494 .olm_name = "LAST_GROUP",
1496 .f_seq = FID_SEQ_LOCAL_FILE,
1497 .f_oid = OFD_LAST_GROUP_OID,
1499 .olm_flags = OLF_SHOW_NAME,
1500 .olm_namelen = sizeof("LAST_GROUP") - 1,
1503 /* committed batchid for cross-MDT operation */
1505 .olm_name = "BATCHID",
1507 .f_seq = FID_SEQ_LOCAL_FILE,
1508 .f_oid = BATCHID_COMMITTED_OID,
1510 .olm_flags = OLF_SHOW_NAME,
1511 .olm_namelen = sizeof("BATCHID") - 1,
1514 /* OSP update logs update_log{_dir} use f_seq = FID_SEQ_UPDATE_LOG{_DIR}
1515 * and f_oid = index for their log files. See lu_update_log{_dir}_fid()
1516 * for more details. */
1520 .olm_name = "update_log",
1522 .f_seq = FID_SEQ_UPDATE_LOG,
1524 .olm_flags = OLF_SHOW_NAME | OLF_IDX_IN_FID,
1525 .olm_namelen = sizeof("update_log") - 1,
1528 /* update_log_dir */
1530 .olm_name = "update_log_dir",
1532 .f_seq = FID_SEQ_UPDATE_LOG_DIR,
1534 .olm_flags = OLF_SHOW_NAME | OLF_SCAN_SUBITEMS |
1536 .olm_namelen = sizeof("update_log_dir") - 1,
1537 .olm_scandir = osd_ios_general_scan,
1538 .olm_filldir = osd_ios_uld_fill,
1543 .olm_name = "lost+found",
1545 .f_seq = FID_SEQ_LOCAL_FILE,
1546 .f_oid = OSD_LPF_OID,
1548 .olm_flags = OLF_SCAN_SUBITEMS,
1549 .olm_namelen = sizeof("lost+found") - 1,
1550 .olm_scandir = osd_ios_general_scan,
1551 .olm_filldir = osd_ios_lf_fill,
1556 .olm_name = HSM_ACTIONS,
1561 .olm_name = LUSTRE_NODEMAP_NAME,
1566 .olm_name = INDEX_BACKUP_DIR,
1568 .f_seq = FID_SEQ_LOCAL_FILE,
1569 .f_oid = INDEX_BACKUP_OID,
1571 .olm_flags = OLF_SCAN_SUBITEMS | OLF_NOT_BACKUP,
1572 .olm_namelen = sizeof(INDEX_BACKUP_DIR) - 1,
1573 .olm_scandir = osd_ios_general_scan,
1574 .olm_filldir = osd_ios_varfid_fill,
1582 /* Add the new introduced files under .lustre/ in the list in the future. */
1583 static const struct osd_lf_map osd_dl_maps[] = {
1588 .f_seq = FID_SEQ_DOT_LUSTRE,
1589 .f_oid = FID_OID_DOT_LUSTRE_OBF,
1591 .olm_namelen = sizeof("fid") - 1,
1594 /* .lustre/lost+found */
1596 .olm_name = "lost+found",
1598 .f_seq = FID_SEQ_DOT_LUSTRE,
1599 .f_oid = FID_OID_DOT_LUSTRE_LPF,
1601 .olm_namelen = sizeof("lost+found") - 1,
1609 struct osd_ios_item {
1610 struct list_head oii_list;
1611 struct dentry *oii_dentry;
1612 scandir_t oii_scandir;
1613 filldir_t oii_filldir;
1616 struct osd_ios_filldir_buf {
1617 /* please keep it as first member */
1618 struct dir_context ctx;
1619 struct osd_thread_info *oifb_info;
1620 struct osd_device *oifb_dev;
1621 struct dentry *oifb_dentry;
1626 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1627 scandir_t scandir, filldir_t filldir)
1629 struct osd_ios_item *item;
1632 OBD_ALLOC_PTR(item);
1636 INIT_LIST_HEAD(&item->oii_list);
1637 item->oii_dentry = dget(dentry);
1638 item->oii_scandir = scandir;
1639 item->oii_filldir = filldir;
1640 list_add_tail(&item->oii_list, &dev->od_ios_list);
1645 static bool osd_index_need_recreate(const struct lu_env *env,
1646 struct osd_device *dev, struct inode *inode)
1648 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1649 struct iam_container *bag = &iam->od_container;
1653 rc = iam_container_init(bag, &iam->od_descr, inode);
1657 rc = iam_container_setup(bag);
1658 iam_container_fini(bag);
1665 static void osd_ios_index_register(const struct lu_env *env,
1666 struct osd_device *osd,
1667 const struct lu_fid *fid,
1668 struct inode *inode)
1670 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1671 struct iam_container *bag = &iam->od_container;
1672 struct super_block *sb = osd_sb(osd);
1673 struct iam_descr *descr;
1679 /* Index must be a regular file. */
1680 if (!S_ISREG(inode->i_mode))
1683 /* Index's size must be block aligned. */
1684 if (inode->i_size < sb->s_blocksize ||
1685 (inode->i_size & (sb->s_blocksize - 1)) != 0)
1688 iam_container_init(bag, &iam->od_descr, inode);
1689 rc = iam_container_setup(bag);
1693 descr = bag->ic_descr;
1694 /* May be regular file with IAM_LFIX_ROOT_MAGIC matched
1695 * coincidentally, or corrupted index object, skip it. */
1696 if (descr->id_ptr_size != 4)
1699 keysize = descr->id_key_size;
1700 recsize = descr->id_rec_size;
1701 rc = osd_index_register(osd, fid, keysize, recsize);
1706 iam_container_fini(bag);
1708 CDEBUG(D_LFSCK, "%s: index object "DFID" (%u/%u) registered\n",
1709 osd_name(osd), PFID(fid), keysize, recsize);
1712 static void osd_index_restore(const struct lu_env *env, struct osd_device *dev,
1713 struct lustre_index_restore_unit *liru,
1714 void *buf, int bufsize)
1716 struct osd_thread_info *info = osd_oti_get(env);
1717 struct osd_inode_id *id = &info->oti_id;
1718 struct lu_fid *tgt_fid = &liru->liru_cfid;
1719 struct inode *bak_inode = NULL;
1720 struct ldiskfs_dir_entry_2 *de = NULL;
1721 struct buffer_head *bh = NULL;
1722 struct dentry *dentry;
1724 struct lu_fid bak_fid;
1728 lustre_fid2lbx(name, tgt_fid, bufsize);
1729 dentry = osd_child_dentry_by_inode(env, dev->od_index_backup_inode,
1730 name, strlen(name));
1731 bh = osd_ldiskfs_find_entry(dev->od_index_backup_inode,
1732 &dentry->d_name, &de, NULL, NULL);
1734 GOTO(log, rc = PTR_ERR(bh));
1736 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
1738 bak_inode = osd_iget_fid(info, dev, id, &bak_fid);
1739 if (IS_ERR(bak_inode))
1740 GOTO(log, rc = PTR_ERR(bak_inode));
1743 /* The OI mapping for index may be invalid, since it will be
1744 * re-created, not update the OI mapping, just cache it in RAM. */
1745 osd_id_gen(id, liru->liru_clid, OSD_OII_NOGEN);
1746 osd_add_oi_cache(info, dev, id, tgt_fid);
1747 rc = lustre_index_restore(env, &dev->od_dt_dev, &liru->liru_pfid,
1748 tgt_fid, &bak_fid, liru->liru_name,
1749 &dev->od_index_backup_list, &dev->od_lock,
1754 CDEBUG(D_WARNING, "%s: restore index '%s' with "DFID": rc = %d\n",
1755 osd_name(dev), liru->liru_name, PFID(tgt_fid), rc);
1759 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1761 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1762 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1763 * reference the inode, or fixed if it is missing or references another inode.
1766 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1767 struct inode *parent, struct inode *inode,
1768 const struct lu_fid *fid, const char *name,
1769 int namelen, int flags)
1771 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1772 struct osd_inode_id *id = &info->oti_id;
1773 struct osd_inode_id *id2 = &info->oti_id2;
1774 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1775 struct scrub_file *sf = &scrub->os_file;
1781 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode: rc = -2\n",
1782 osd_name(dev), namelen, name);
1786 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
1787 &info->oti_ost_attrs);
1788 if (rc != 0 && rc != -ENODATA) {
1789 CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
1790 "rc = %d\n", osd_name(dev), rc);
1795 osd_id_gen(id, inode->i_ino, inode->i_generation);
1796 if (rc == -ENODATA) {
1797 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID) {
1798 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1801 if (flags & OLF_IDX_IN_FID) {
1802 LASSERT(dev->od_index >= 0);
1804 tfid.f_oid = dev->od_index;
1807 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1809 CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
1810 "scrub: rc = %d\n", osd_name(dev), rc);
1815 if (lma->lma_compat & LMAC_NOT_IN_OI)
1818 tfid = lma->lma_self_fid;
1819 if (lma->lma_compat & LMAC_IDX_BACKUP &&
1820 osd_index_need_recreate(info->oti_env, dev, inode)) {
1821 struct lu_fid *pfid = &info->oti_fid3;
1823 if (is_root_inode(parent)) {
1824 lu_local_obj_fid(pfid, OSD_FS_ROOT_OID);
1826 rc = osd_scrub_get_fid(info, dev, parent, pfid,
1832 rc = lustre_liru_new(&dev->od_index_restore_list, pfid,
1833 &tfid, inode->i_ino, name, namelen);
1838 if (!(flags & OLF_NOT_BACKUP))
1839 osd_ios_index_register(info->oti_env, dev, &tfid,
1843 /* Since this called from iterate_dir() the inode lock will be taken */
1844 rc = osd_oi_lookup(info, dev, &tfid, id2, OI_LOCKED);
1849 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1850 DTO_INDEX_INSERT, true, 0, NULL);
1857 if (osd_id_eq_strict(id, id2))
1860 if (!(sf->sf_flags & SF_INCONSISTENT)) {
1861 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
1862 rc = scrub_file_store(info->oti_env, scrub);
1867 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1868 DTO_INDEX_UPDATE, true, 0, NULL);
1876 * It scans the /lost+found, and for the OST-object (with filter_fid
1877 * or filter_fid_18_23), move them back to its proper /O/<seq>/d<x>.
1879 #ifdef HAVE_FILLDIR_USE_CTX
1880 static int osd_ios_lf_fill(struct dir_context *buf,
1882 static int osd_ios_lf_fill(void *buf,
1884 const char *name, int namelen,
1885 loff_t offset, __u64 ino, unsigned d_type)
1887 struct osd_ios_filldir_buf *fill_buf =
1888 (struct osd_ios_filldir_buf *)buf;
1889 struct osd_thread_info *info = fill_buf->oifb_info;
1890 struct osd_device *dev = fill_buf->oifb_dev;
1891 struct lu_fid *fid = &info->oti_fid;
1892 struct osd_scrub *scrub = &dev->od_scrub;
1893 struct dentry *parent = fill_buf->oifb_dentry;
1894 struct dentry *child;
1895 struct inode *dir = parent->d_inode;
1896 struct inode *inode;
1900 fill_buf->oifb_items++;
1902 /* skip any '.' started names */
1906 scrub->os_lf_scanned++;
1907 child = osd_lookup_one_len(dev, name, parent, namelen);
1908 if (IS_ERR(child)) {
1909 rc = PTR_ERR(child);
1910 CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
1911 osd_name(dev), namelen, name, rc);
1913 } else if (!child->d_inode) {
1915 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode\n",
1916 osd_name(dev), namelen, name);
1920 inode = child->d_inode;
1921 if (S_ISDIR(inode->i_mode)) {
1922 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
1925 CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
1926 "rc = %d\n", osd_name(dev), namelen, name, rc);
1930 if (!S_ISREG(inode->i_mode))
1933 rc = osd_scrub_get_fid(info, dev, inode, fid, true);
1934 if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
1935 rc = osd_obj_map_recover(info, dev, dir, child, fid);
1937 CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
1938 "/lost+found.\n", namelen, name, PFID(fid));
1939 scrub->os_lf_repaired++;
1941 CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
1943 osd_name(dev), namelen, name, PFID(fid), rc);
1947 /* XXX: For MDT-objects, we can move them from /lost+found to namespace
1948 * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
1949 * can process them in furtuer. */
1955 scrub->os_lf_failed++;
1957 /* skip the failure to make the scanning to continue. */
1961 #ifdef HAVE_FILLDIR_USE_CTX
1962 static int osd_ios_varfid_fill(struct dir_context *buf,
1964 static int osd_ios_varfid_fill(void *buf,
1966 const char *name, int namelen,
1967 loff_t offset, __u64 ino, unsigned d_type)
1969 struct osd_ios_filldir_buf *fill_buf =
1970 (struct osd_ios_filldir_buf *)buf;
1971 struct osd_device *dev = fill_buf->oifb_dev;
1972 struct dentry *child;
1976 fill_buf->oifb_items++;
1978 /* skip any '.' started names */
1982 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
1984 RETURN(PTR_ERR(child));
1986 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
1987 fill_buf->oifb_dentry->d_inode, child->d_inode,
1988 NULL, name, namelen, 0);
1989 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
1990 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
1991 osd_ios_varfid_fill);
1997 #ifdef HAVE_FILLDIR_USE_CTX
1998 static int osd_ios_dl_fill(struct dir_context *buf,
2000 static int osd_ios_dl_fill(void *buf,
2002 const char *name, int namelen,
2003 loff_t offset, __u64 ino, unsigned d_type)
2005 struct osd_ios_filldir_buf *fill_buf =
2006 (struct osd_ios_filldir_buf *)buf;
2007 struct osd_device *dev = fill_buf->oifb_dev;
2008 const struct osd_lf_map *map;
2009 struct dentry *child;
2013 fill_buf->oifb_items++;
2015 /* skip any '.' started names */
2019 for (map = osd_dl_maps; map->olm_name != NULL; map++) {
2020 if (map->olm_namelen != namelen)
2023 if (strncmp(map->olm_name, name, namelen) == 0)
2027 if (map->olm_name == NULL)
2030 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2032 RETURN(PTR_ERR(child));
2034 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2035 fill_buf->oifb_dentry->d_inode, child->d_inode,
2036 &map->olm_fid, name, namelen, map->olm_flags);
2042 #ifdef HAVE_FILLDIR_USE_CTX
2043 static int osd_ios_uld_fill(struct dir_context *buf,
2045 static int osd_ios_uld_fill(void *buf,
2047 const char *name, int namelen,
2048 loff_t offset, __u64 ino, unsigned d_type)
2050 struct osd_ios_filldir_buf *fill_buf =
2051 (struct osd_ios_filldir_buf *)buf;
2052 struct osd_device *dev = fill_buf->oifb_dev;
2053 struct dentry *child;
2058 fill_buf->oifb_items++;
2060 /* skip any non-DFID format name */
2064 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2066 RETURN(PTR_ERR(child));
2068 /* skip the start '[' */
2069 sscanf(&name[1], SFID, RFID(&tfid));
2070 if (fid_is_sane(&tfid))
2071 rc = osd_ios_scan_one(fill_buf->oifb_info, fill_buf->oifb_dev,
2072 fill_buf->oifb_dentry->d_inode,
2073 child->d_inode, &tfid, name, namelen, 0);
2081 #ifdef HAVE_FILLDIR_USE_CTX
2082 static int osd_ios_root_fill(struct dir_context *buf,
2084 static int osd_ios_root_fill(void *buf,
2086 const char *name, int namelen,
2087 loff_t offset, __u64 ino, unsigned d_type)
2089 struct osd_ios_filldir_buf *fill_buf =
2090 (struct osd_ios_filldir_buf *)buf;
2091 struct osd_device *dev = fill_buf->oifb_dev;
2092 const struct osd_lf_map *map;
2093 struct dentry *child;
2097 fill_buf->oifb_items++;
2099 /* skip any '.' started names */
2103 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
2104 if (map->olm_namelen != namelen)
2107 if (strncmp(map->olm_name, name, namelen) == 0)
2111 if (map->olm_name == NULL)
2114 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2116 RETURN(PTR_ERR(child));
2117 else if (!child->d_inode)
2118 GOTO(out_put, rc = -ENOENT);
2120 if (!(map->olm_flags & OLF_NO_OI))
2121 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2122 fill_buf->oifb_dentry->d_inode, child->d_inode,
2123 &map->olm_fid, name, namelen, map->olm_flags);
2124 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
2125 rc = osd_ios_new_item(dev, child, map->olm_scandir,
2134 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
2135 struct dentry *dentry, filldir_t filldir)
2137 struct osd_ios_filldir_buf buf = {
2138 .ctx.actor = filldir,
2141 .oifb_dentry = dentry
2149 path.dentry = dget(dentry);
2150 path.mnt = mntget(dev->od_mnt);
2152 filp = dentry_open(&path, O_RDONLY, current_cred());
2155 RETURN(PTR_ERR(filp));
2157 filp->f_mode |= FMODE_64BITHASH | FMODE_NONOTIFY;
2158 filp->f_flags |= O_NOATIME;
2163 rc = iterate_dir(filp, &buf.ctx);
2164 } while (rc >= 0 && buf.oifb_items > 0 &&
2165 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
2172 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
2173 struct dentry *dentry, filldir_t filldir)
2175 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2176 struct scrub_file *sf = &scrub->os_file;
2177 struct dentry *child;
2181 /* It is existing MDT0 device. We only allow the case of object without
2182 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
2183 * can generate IGIF mode FID for the object and related OI mapping. If
2184 * it is on other MDTs, then becuase file-level backup/restore, related
2185 * OI mapping may be invalid already, we do not know which is the right
2186 * FID for the object. We only allow IGIF objects to reside on the MDT0.
2188 * XXX: For the case of object on non-MDT0 device with neither LMA nor
2189 * "fid" xattr, then something crashed. We cannot re-generate the
2190 * FID directly, instead, the OI scrub will scan the OI structure
2191 * and try to re-generate the LMA from the OI mapping. But if the
2192 * OI mapping crashed or lost also, then we have to give up under
2193 * double failure cases.
2195 spin_lock(&scrub->os_lock);
2196 scrub->os_convert_igif = 1;
2197 spin_unlock(&scrub->os_lock);
2198 child = osd_lookup_one_len_unlocked(dev, dot_lustre_name, dentry,
2199 strlen(dot_lustre_name));
2200 if (IS_ERR(child)) {
2201 if (PTR_ERR(child) != -ENOENT)
2202 RETURN(PTR_ERR(child));
2206 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
2207 * so the client will get IGIF for the ".lustre" object when
2210 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
2211 * it does not know whether there are some old clients cached
2212 * the ".lustre" IGIF during the upgrading. Two choices:
2214 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
2215 * It will allow the old connected clients to access the
2216 * ".lustre" with cached IGIF. But it will cause others
2217 * on the MDT failed to check "fid_is_dot_lustre()".
2219 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
2220 * for ".lustre" in spite of whether there are some clients
2221 * cached the ".lustre" IGIF or not. It enables the check
2222 * "fid_is_dot_lustre()" on the MDT, although it will cause
2223 * that the old connected clients cannot access the ".lustre"
2224 * with the cached IGIF.
2226 * Usually, it is rare case for the old connected clients
2227 * to access the ".lustre" with cached IGIF. So we prefer
2228 * to the solution 2).
2230 inode_lock(dentry->d_inode);
2231 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2232 child->d_inode, &LU_DOT_LUSTRE_FID,
2234 strlen(dot_lustre_name), 0);
2235 inode_unlock(dentry->d_inode);
2236 if (rc == -ENOENT) {
2238 /* It is 1.8 MDT device. */
2239 if (!(sf->sf_flags & SF_UPGRADE)) {
2240 scrub_file_reset(scrub, dev->od_uuid,
2242 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2243 rc = scrub_file_store(info->oti_env, scrub);
2247 } else if (rc == 0) {
2248 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2257 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
2258 struct dentry *dentry, filldir_t filldir)
2260 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2261 struct scrub_file *sf = &scrub->os_file;
2262 struct dentry *child;
2266 if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
2267 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2268 rc = scrub_file_store(info->oti_env, scrub);
2273 child = osd_lookup_one_len_unlocked(dev, ADMIN_USR, dentry,
2275 if (IS_ERR(child)) {
2276 rc = PTR_ERR(child);
2278 inode_lock(dentry->d_inode);
2279 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2280 child->d_inode, NULL, ADMIN_USR,
2281 strlen(ADMIN_USR), 0);
2282 inode_unlock(dentry->d_inode);
2286 if (rc != 0 && rc != -ENOENT)
2289 child = osd_lookup_one_len_unlocked(dev, ADMIN_GRP, dentry,
2292 GOTO(out, rc = PTR_ERR(child));
2294 inode_lock(dentry->d_inode);
2295 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2296 child->d_inode, NULL, ADMIN_GRP,
2297 strlen(ADMIN_GRP), 0);
2298 inode_unlock(dentry->d_inode);
2301 RETURN(rc == -ENOENT ? 0 : rc);
2304 static void osd_initial_OI_scrub(struct osd_thread_info *info,
2305 struct osd_device *dev)
2307 struct osd_ios_item *item = NULL;
2308 scandir_t scandir = osd_ios_general_scan;
2309 filldir_t filldir = osd_ios_root_fill;
2310 struct dentry *dentry = osd_sb(dev)->s_root;
2311 const struct osd_lf_map *map = osd_lf_maps;
2314 /* Lookup IGIF in OI by force for initial OI scrub. */
2315 dev->od_igif_inoi = 1;
2318 /* Don't take inode_lock here since scandir() callbacks
2319 * can call VFS functions which may manully take the
2320 * inode lock itself like iterate_dir(). Since this
2321 * is the case it is best to leave the scandir()
2322 * callbacks to managing the inode lock.
2324 scandir(info, dev, dentry, filldir);
2326 dput(item->oii_dentry);
2330 if (list_empty(&dev->od_ios_list))
2333 item = list_entry(dev->od_ios_list.next,
2334 struct osd_ios_item, oii_list);
2335 list_del_init(&item->oii_list);
2337 LASSERT(item->oii_scandir != NULL);
2338 scandir = item->oii_scandir;
2339 filldir = item->oii_filldir;
2340 dentry = item->oii_dentry;
2343 /* There maybe the case that the object has been removed, but its OI
2344 * mapping is still in the OI file, such as the "CATALOGS" after MDT
2345 * file-level backup/restore. So here cleanup the stale OI mappings. */
2346 while (map->olm_name != NULL) {
2347 struct dentry *child;
2349 if (fid_is_zero(&map->olm_fid)) {
2354 child = osd_lookup_one_len_unlocked(dev, map->olm_name,
2355 osd_sb(dev)->s_root,
2357 if (PTR_ERR(child) == -ENOENT ||
2358 (!IS_ERR(child) && !child->d_inode))
2359 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
2360 NULL, DTO_INDEX_DELETE,
2367 if (!list_empty(&dev->od_index_restore_list)) {
2370 OBD_ALLOC_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2372 CERROR("%s: not enough RAM for rebuild index\n",
2375 while (!list_empty(&dev->od_index_restore_list)) {
2376 struct lustre_index_restore_unit *liru;
2378 liru = list_entry(dev->od_index_restore_list.next,
2379 struct lustre_index_restore_unit,
2381 list_del(&liru->liru_link);
2383 osd_index_restore(info->oti_env, dev, liru,
2384 buf, INDEX_BACKUP_BUFSIZE);
2385 OBD_FREE(liru, liru->liru_len);
2389 OBD_FREE_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2395 char *osd_lf_fid2name(const struct lu_fid *fid)
2397 const struct osd_lf_map *map = osd_lf_maps;
2399 while (map->olm_name != NULL) {
2400 if (!lu_fid_eq(fid, &map->olm_fid)) {
2405 if (map->olm_flags & OLF_SHOW_NAME)
2406 return map->olm_name;
2414 /* OI scrub start/stop */
2416 int osd_scrub_start(const struct lu_env *env, struct osd_device *dev,
2419 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2423 if (dev->od_dt_dev.dd_rdonly)
2426 /* od_otable_mutex: prevent curcurrent start/stop */
2427 mutex_lock(&dev->od_otable_mutex);
2428 rc = scrub_start(osd_scrub_main, scrub, dev, flags);
2429 if (rc == -EALREADY) {
2431 if ((scrub->os_file.sf_flags & SF_AUTO ||
2432 scrub->os_partial_scan) &&
2433 !(flags & SS_AUTO_PARTIAL))
2434 osd_scrub_join(env, dev, flags, false);
2436 mutex_unlock(&dev->od_otable_mutex);
2441 void osd_scrub_stop(struct osd_device *dev)
2443 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2445 /* od_otable_mutex: prevent curcurrent start/stop */
2446 mutex_lock(&dev->od_otable_mutex);
2447 spin_lock(&scrub->os_lock);
2448 scrub->os_paused = 1;
2449 spin_unlock(&scrub->os_lock);
2451 mutex_unlock(&dev->od_otable_mutex);
2454 /* OI scrub setup/cleanup */
2456 static const char osd_scrub_name[] = "OI_scrub";
2458 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev,
2461 struct osd_thread_info *info = osd_oti_get(env);
2462 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2463 struct lvfs_run_ctxt *ctxt = &dev->od_scrub.os_ctxt;
2464 time64_t interval = scrub->os_auto_scrub_interval;
2465 struct scrub_file *sf = &scrub->os_file;
2466 struct super_block *sb = osd_sb(dev);
2467 struct lvfs_run_ctxt saved;
2469 struct inode *inode;
2470 struct lu_fid *fid = &info->oti_fid;
2471 struct osd_inode_id *id = &info->oti_id;
2472 struct dt_object *obj;
2477 memset(&dev->od_scrub, 0, sizeof(struct osd_scrub));
2478 OBD_SET_CTXT_MAGIC(ctxt);
2479 ctxt->pwdmnt = dev->od_mnt;
2480 ctxt->pwd = dev->od_mnt->mnt_root;
2482 init_rwsem(&scrub->os_rwsem);
2483 spin_lock_init(&scrub->os_lock);
2484 INIT_LIST_HEAD(&scrub->os_inconsistent_items);
2485 scrub->os_name = osd_name(dev);
2486 scrub->os_auto_scrub_interval = interval;
2488 push_ctxt(&saved, ctxt);
2489 filp = filp_open(osd_scrub_name, O_RDWR |
2490 (dev->od_dt_dev.dd_rdonly ? 0 : O_CREAT), 0644);
2492 pop_ctxt(&saved, ctxt);
2493 RETURN(PTR_ERR(filp));
2496 inode = file_inode(filp);
2497 ldiskfs_set_inode_flag(inode, LDISKFS_INODE_JOURNAL_DATA);
2498 if (!dev->od_dt_dev.dd_rdonly) {
2499 /* 'What the @fid is' is not imporatant, because the object
2500 * has no OI mapping, and only is visible inside the OSD.*/
2501 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2502 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
2504 filp_close(filp, NULL);
2505 pop_ctxt(&saved, ctxt);
2510 osd_id_gen(id, inode->i_ino, inode->i_generation);
2511 osd_add_oi_cache(info, dev, id, fid);
2512 filp_close(filp, NULL);
2513 pop_ctxt(&saved, ctxt);
2515 obj = lu2dt(lu_object_find_slice(env, osd2lu_dev(dev), fid, NULL));
2516 if (IS_ERR_OR_NULL(obj))
2517 RETURN(obj ? PTR_ERR(obj) : -ENOENT);
2519 #ifndef HAVE_S_UUID_AS_UUID_T
2520 memcpy(dev->od_uuid.b, sb->s_uuid, sizeof(dev->od_uuid));
2522 uuid_copy(&dev->od_uuid, &sb->s_uuid);
2524 scrub->os_obj = obj;
2525 rc = scrub_file_load(env, scrub);
2526 if (rc == -ENOENT || rc == -EFAULT) {
2527 scrub_file_init(scrub, dev->od_uuid);
2528 /* If the "/O" dir does not exist when mount (indicated by
2529 * osd_device::od_maybe_new), neither for the "/OI_scrub",
2530 * then it is quite probably that the device is a new one,
2531 * under such case, mark it as SIF_NO_HANDLE_OLD_FID.
2533 * For the rare case that "/O" and "OI_scrub" both lost on
2534 * an old device, it can be found and cleared later.
2536 * For the system with "SIF_NO_HANDLE_OLD_FID", we do not
2537 * need to check "filter_fid_18_23" and to convert it to
2538 * "filter_fid" for each object, and all the IGIF should
2539 * have their FID mapping in OI files already. */
2540 if (dev->od_maybe_new && rc == -ENOENT)
2541 sf->sf_internal_flags = SIF_NO_HANDLE_OLD_FID;
2543 } else if (rc < 0) {
2544 GOTO(cleanup_obj, rc);
2546 if (!uuid_equal(&sf->sf_uuid, &dev->od_uuid)) {
2548 "%s: UUID has been changed from %pU to %pU\n",
2549 osd_dev2name(dev), &sf->sf_uuid, &dev->od_uuid);
2550 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
2553 } else if (sf->sf_status == SS_SCANNING) {
2554 sf->sf_status = SS_CRASHED;
2558 if ((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) {
2559 LCONSOLE_WARN("%s: invalid oi count %d, set it to %d\n",
2560 osd_dev2name(dev), sf->sf_oi_count,
2562 sf->sf_oi_count = osd_oi_count;
2567 if (sf->sf_pos_last_checkpoint != 0)
2568 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
2570 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
2573 rc = scrub_file_store(env, scrub);
2575 GOTO(cleanup_obj, rc);
2578 /* Initialize OI files. */
2579 rc = osd_oi_init(info, dev, restored);
2581 GOTO(cleanup_obj, rc);
2583 if (!dev->od_dt_dev.dd_rdonly)
2584 osd_initial_OI_scrub(info, dev);
2586 if (sf->sf_flags & SF_UPGRADE ||
2587 !(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID ||
2588 sf->sf_success_count > 0)) {
2589 dev->od_igif_inoi = 0;
2590 dev->od_check_ff = dev->od_is_ost;
2592 dev->od_igif_inoi = 1;
2593 dev->od_check_ff = 0;
2596 if (sf->sf_flags & SF_INCONSISTENT)
2597 /* The 'od_igif_inoi' will be set under the
2599 * 1) new created system, or
2600 * 2) restored from file-level backup, or
2601 * 3) the upgrading completed.
2603 * The 'od_igif_inoi' may be cleared by OI scrub
2604 * later if found that the system is upgrading. */
2605 dev->od_igif_inoi = 1;
2607 if (!dev->od_dt_dev.dd_rdonly &&
2608 dev->od_scrub.os_scrub.os_auto_scrub_interval != AS_NEVER &&
2609 ((sf->sf_status == SS_PAUSED) ||
2610 (sf->sf_status == SS_CRASHED &&
2611 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2612 SF_UPGRADE | SF_AUTO)) ||
2613 (sf->sf_status == SS_INIT &&
2614 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2616 rc = osd_scrub_start(env, dev, SS_AUTO_FULL);
2619 GOTO(cleanup_oi, rc);
2621 /* it is possible that dcache entries may keep objects after they are
2622 * deleted by OSD. While it looks safe this can cause object data to
2623 * stay until umount causing failures in tests calculating free space,
2624 * e.g. replay-ost-single. Since those dcache entries are not used
2625 * anymore let's just free them after use here */
2626 shrink_dcache_sb(sb);
2630 osd_oi_fini(info, dev);
2632 dt_object_put_nocache(env, scrub->os_obj);
2633 scrub->os_obj = NULL;
2638 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
2640 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2642 LASSERT(dev->od_otable_it == NULL);
2644 if (scrub->os_obj != NULL) {
2645 osd_scrub_stop(dev);
2646 dt_object_put_nocache(env, scrub->os_obj);
2647 scrub->os_obj = NULL;
2651 /* object table based iteration APIs */
2653 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
2654 struct dt_object *dt, __u32 attr)
2656 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
2657 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
2658 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
2659 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2660 struct osd_otable_it *it;
2665 /* od_otable_mutex: prevent curcurrent init/fini */
2666 mutex_lock(&dev->od_otable_mutex);
2667 if (dev->od_otable_it != NULL)
2668 GOTO(out, it = ERR_PTR(-EALREADY));
2672 GOTO(out, it = ERR_PTR(-ENOMEM));
2674 dev->od_otable_it = it;
2676 it->ooi_cache.ooc_consumer_idx = -1;
2677 if (flags & DOIF_OUTUSED)
2678 it->ooi_used_outside = 1;
2680 if (flags & DOIF_RESET)
2683 if (valid & DOIV_ERROR_HANDLE) {
2684 if (flags & DOIF_FAILOUT)
2685 start |= SS_SET_FAILOUT;
2687 start |= SS_CLEAR_FAILOUT;
2690 if (valid & DOIV_DRYRUN) {
2691 if (flags & DOIF_DRYRUN)
2692 start |= SS_SET_DRYRUN;
2694 start |= SS_CLEAR_DRYRUN;
2697 rc = scrub_start(osd_scrub_main, scrub, dev, start & ~SS_AUTO_PARTIAL);
2698 if (rc == -EALREADY) {
2699 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2700 } else if (rc < 0) {
2701 dev->od_otable_it = NULL;
2705 /* We have to start from the begining. */
2706 it->ooi_cache.ooc_pos_preload =
2707 LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2713 mutex_unlock(&dev->od_otable_mutex);
2714 return (struct dt_it *)it;
2717 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2719 struct osd_otable_it *it = (struct osd_otable_it *)di;
2720 struct osd_device *dev = it->ooi_dev;
2722 /* od_otable_mutex: prevent curcurrent init/fini */
2723 mutex_lock(&dev->od_otable_mutex);
2724 scrub_stop(&dev->od_scrub.os_scrub);
2725 LASSERT(dev->od_otable_it == it);
2727 dev->od_otable_it = NULL;
2728 mutex_unlock(&dev->od_otable_mutex);
2732 static int osd_otable_it_get(const struct lu_env *env,
2733 struct dt_it *di, const struct dt_key *key)
2738 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2743 osd_otable_it_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
2745 spin_lock(&scrub->os_lock);
2746 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2747 scrub->os_waiting || !scrub->os_running)
2748 it->ooi_waiting = 0;
2750 it->ooi_waiting = 1;
2751 spin_unlock(&scrub->os_lock);
2753 return !it->ooi_waiting;
2756 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2758 struct osd_otable_it *it = (struct osd_otable_it *)di;
2759 struct osd_device *dev = it->ooi_dev;
2760 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2761 struct osd_otable_cache *ooc = &it->ooi_cache;
2765 LASSERT(it->ooi_user_ready);
2768 if (!scrub->os_running && !it->ooi_used_outside)
2771 if (ooc->ooc_cached_items > 0) {
2772 ooc->ooc_cached_items--;
2773 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2774 ~OSD_OTABLE_IT_CACHE_MASK;
2778 if (it->ooi_all_cached) {
2779 wait_var_event(scrub, !scrub->os_running);
2783 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2784 spin_lock(&scrub->os_lock);
2785 scrub->os_waiting = 0;
2787 spin_unlock(&scrub->os_lock);
2790 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2791 wait_var_event(scrub, osd_otable_it_wakeup(scrub, it));
2793 if (!scrub->os_running && !it->ooi_used_outside)
2796 rc = osd_otable_it_preload(env, it);
2803 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2804 const struct dt_it *di)
2809 static int osd_otable_it_key_size(const struct lu_env *env,
2810 const struct dt_it *di)
2812 return sizeof(__u64);
2815 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2816 struct dt_rec *rec, __u32 attr)
2818 struct osd_otable_it *it = (struct osd_otable_it *)di;
2819 struct osd_otable_cache *ooc = &it->ooi_cache;
2821 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2823 /* Filter out Invald FID already. */
2824 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2825 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2826 PFID((struct lu_fid *)rec),
2827 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2832 static __u64 osd_otable_it_store(const struct lu_env *env,
2833 const struct dt_it *di)
2835 struct osd_otable_it *it = (struct osd_otable_it *)di;
2836 struct osd_otable_cache *ooc = &it->ooi_cache;
2839 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2840 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2842 hash = ooc->ooc_pos_preload;
2847 * Set the OSD layer iteration start position as the specified hash.
2849 static int osd_otable_it_load(const struct lu_env *env,
2850 const struct dt_it *di, __u64 hash)
2852 struct osd_otable_it *it = (struct osd_otable_it *)di;
2853 struct osd_device *dev = it->ooi_dev;
2854 struct osd_otable_cache *ooc = &it->ooi_cache;
2855 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2856 struct osd_iit_param *param = &it->ooi_iit_param;
2860 /* Forbid to set iteration position after iteration started. */
2861 if (it->ooi_user_ready)
2864 LASSERT(!scrub->os_partial_scan);
2866 if (hash > OSD_OTABLE_MAX_HASH)
2867 hash = OSD_OTABLE_MAX_HASH;
2869 /* The hash is the last checkpoint position,
2870 * we will start from the next one. */
2871 ooc->ooc_pos_preload = hash + 1;
2872 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
2873 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2875 it->ooi_user_ready = 1;
2876 if (!scrub->os_full_speed)
2879 memset(param, 0, sizeof(*param));
2880 param->sb = osd_sb(dev);
2881 param->start = ooc->ooc_pos_preload;
2882 param->bg = (ooc->ooc_pos_preload - 1) /
2883 LDISKFS_INODES_PER_GROUP(param->sb);
2884 param->offset = (ooc->ooc_pos_preload - 1) %
2885 LDISKFS_INODES_PER_GROUP(param->sb);
2886 param->gbase = 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
2888 /* Unplug OSD layer iteration by the first next() call. */
2889 rc = osd_otable_it_next(env, (struct dt_it *)it);
2894 static int osd_otable_it_key_rec(const struct lu_env *env,
2895 const struct dt_it *di, void *key_rec)
2900 const struct dt_index_operations osd_otable_ops = {
2902 .init = osd_otable_it_init,
2903 .fini = osd_otable_it_fini,
2904 .get = osd_otable_it_get,
2905 .put = osd_otable_it_put,
2906 .next = osd_otable_it_next,
2907 .key = osd_otable_it_key,
2908 .key_size = osd_otable_it_key_size,
2909 .rec = osd_otable_it_rec,
2910 .store = osd_otable_it_store,
2911 .load = osd_otable_it_load,
2912 .key_rec = osd_otable_it_key_rec,
2916 /* high priority inconsistent items list APIs */
2918 #define SCRUB_BAD_OIMAP_DECAY_INTERVAL 60
2920 int osd_oii_insert(struct osd_device *dev, const struct lu_fid *fid,
2921 struct osd_inode_id *id, int insert)
2923 struct osd_inconsistent_item *oii;
2924 struct osd_scrub *oscrub = &dev->od_scrub;
2925 struct lustre_scrub *lscrub = &oscrub->os_scrub;
2930 if (unlikely(oii == NULL))
2933 INIT_LIST_HEAD(&oii->oii_list);
2934 oii->oii_cache.oic_fid = *fid;
2935 oii->oii_cache.oic_lid = *id;
2936 oii->oii_cache.oic_dev = dev;
2937 oii->oii_insert = insert;
2939 spin_lock(&lscrub->os_lock);
2940 if (lscrub->os_partial_scan) {
2941 __u64 now = ktime_get_real_seconds();
2943 /* If there haven't been errors in a long time,
2944 * decay old count until either the errors are
2945 * gone or we reach the current interval. */
2946 while (unlikely(oscrub->os_bad_oimap_count > 0 &&
2947 oscrub->os_bad_oimap_time +
2948 SCRUB_BAD_OIMAP_DECAY_INTERVAL < now)) {
2949 oscrub->os_bad_oimap_count >>= 1;
2950 oscrub->os_bad_oimap_time +=
2951 SCRUB_BAD_OIMAP_DECAY_INTERVAL;
2954 oscrub->os_bad_oimap_time = now;
2955 if (++oscrub->os_bad_oimap_count >
2956 dev->od_full_scrub_threshold_rate)
2957 lscrub->os_full_scrub = 1;
2960 if (!lscrub->os_running) {
2961 spin_unlock(&lscrub->os_lock);
2966 if (list_empty(&lscrub->os_inconsistent_items))
2968 list_add_tail(&oii->oii_list, &lscrub->os_inconsistent_items);
2969 spin_unlock(&lscrub->os_lock);
2972 wake_up_var(lscrub);
2977 int osd_oii_lookup(struct osd_device *dev, const struct lu_fid *fid,
2978 struct osd_inode_id *id)
2980 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2981 struct osd_inconsistent_item *oii;
2984 spin_lock(&scrub->os_lock);
2985 list_for_each_entry(oii, &scrub->os_inconsistent_items, oii_list) {
2986 if (lu_fid_eq(fid, &oii->oii_cache.oic_fid)) {
2987 *id = oii->oii_cache.oic_lid;
2988 spin_unlock(&scrub->os_lock);
2992 spin_unlock(&scrub->os_lock);
2997 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
2999 struct osd_scrub *scrub = &dev->od_scrub;
3001 scrub_dump(m, &scrub->os_scrub);
3002 seq_printf(m, "lf_scanned: %llu\n"
3004 "lf_failed: %llu\n",
3005 scrub->os_lf_scanned,
3006 scrub->os_scrub.os_file.sf_param & SP_DRYRUN ?
3007 "inconsistent" : "repaired",
3008 scrub->os_lf_repaired,
3009 scrub->os_lf_failed);
3012 typedef int (*scan_dir_helper_t)(const struct lu_env *env,
3013 struct osd_device *dev, struct inode *dir,
3014 struct osd_it_ea *oie);
3016 static int osd_scan_dir(const struct lu_env *env, struct osd_device *dev,
3017 struct inode *inode, scan_dir_helper_t cb)
3019 struct osd_it_ea *oie;
3024 oie = osd_it_dir_init(env, dev, inode, LUDA_TYPE);
3026 RETURN(PTR_ERR(oie));
3028 oie->oie_file->f_pos = 0;
3029 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3035 while (oie->oie_it_dirent <= oie->oie_rd_dirent) {
3036 if (!name_is_dot_or_dotdot(oie->oie_dirent->oied_name,
3037 oie->oie_dirent->oied_namelen))
3038 cb(env, dev, inode, oie);
3040 oie->oie_dirent = (void *)oie->oie_dirent +
3041 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
3042 oie->oie_dirent->oied_namelen);
3044 oie->oie_it_dirent++;
3045 if (oie->oie_it_dirent <= oie->oie_rd_dirent)
3048 if (oie->oie_file->f_pos ==
3049 ldiskfs_get_htree_eof(oie->oie_file))
3052 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3061 osd_it_dir_fini(env, oie, inode);
3065 static int osd_remove_ml_file(struct osd_thread_info *info,
3066 struct osd_device *dev, struct inode *dir,
3067 struct inode *inode, struct osd_it_ea *oie)
3070 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3071 struct dentry dentry;
3076 if (scrub->os_file.sf_param & SP_DRYRUN)
3079 th = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
3080 osd_dto_credits_noquota[DTO_INDEX_DELETE] +
3081 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
3083 RETURN(PTR_ERR(th));
3085 /* Should be created by the VFS layer */
3086 dentry.d_inode = dir;
3087 dentry.d_sb = dir->i_sb;
3088 rc = osd_obj_del_entry(info, dev, &dentry, oie->oie_dirent->oied_name,
3089 oie->oie_dirent->oied_namelen, th);
3091 mark_inode_dirty(inode);
3092 ldiskfs_journal_stop(th);
3096 static int osd_scan_ml_file(const struct lu_env *env, struct osd_device *dev,
3097 struct inode *dir, struct osd_it_ea *oie)
3099 struct osd_thread_info *info = osd_oti_get(env);
3100 struct osd_inode_id id;
3101 struct inode *inode;
3102 struct osd_obj_seq *oseq;
3103 struct ost_id *ostid = &info->oti_ostid;
3104 struct lu_fid *fid = &oie->oie_dirent->oied_fid;
3110 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3112 if (!fid_is_sane(fid))
3113 inode = osd_iget_fid(info, dev, &id, fid);
3115 inode = osd_iget(info, dev, &id);
3118 RETURN(PTR_ERR(inode));
3120 fid_to_ostid(fid, ostid);
3121 oseq = osd_seq_load(info, dev, ostid_seq(ostid));
3123 RETURN(PTR_ERR(oseq));
3125 dirn = ostid_id(ostid) & (oseq->oos_subdir_count - 1);
3126 LASSERT(oseq->oos_dirs[dirn] != NULL);
3128 osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
3129 if (((strlen(oseq->oos_root->d_name.name) !=
3130 info->oti_seq_dirent->oied_namelen) ||
3131 strncmp(oseq->oos_root->d_name.name,
3132 info->oti_seq_dirent->oied_name,
3133 info->oti_seq_dirent->oied_namelen) != 0) ||
3134 ((strlen(oseq->oos_dirs[dirn]->d_name.name) !=
3135 info->oti_dir_dirent->oied_namelen) ||
3136 strncmp(oseq->oos_dirs[dirn]->d_name.name,
3137 info->oti_dir_dirent->oied_name,
3138 info->oti_dir_dirent->oied_namelen) != 0) ||
3139 ((strlen(name) != oie->oie_dirent->oied_namelen) ||
3140 strncmp(oie->oie_dirent->oied_name, name,
3141 oie->oie_dirent->oied_namelen) != 0)) {
3142 CDEBUG(D_LFSCK, "%s: the file O/%s/%s/%s is corrupted\n",
3143 osd_name(dev), info->oti_seq_dirent->oied_name,
3144 info->oti_dir_dirent->oied_name,
3145 oie->oie_dirent->oied_name);
3147 rc = osd_remove_ml_file(info, dev, dir, inode, oie);
3154 static int osd_scan_ml_file_dir(const struct lu_env *env,
3155 struct osd_device *dev, struct inode *dir,
3156 struct osd_it_ea *oie)
3158 struct osd_thread_info *info = osd_oti_get(env);
3159 struct inode *inode;
3160 struct osd_inode_id id;
3165 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3166 inode = osd_iget(info, dev, &id);
3168 RETURN(PTR_ERR(inode));
3170 if (!S_ISDIR(inode->i_mode))
3173 info->oti_dir_dirent = oie->oie_dirent;
3174 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file);
3175 info->oti_dir_dirent = NULL;
3182 static int osd_scan_ml_file_seq(const struct lu_env *env,
3183 struct osd_device *dev, struct inode *dir,
3184 struct osd_it_ea *oie)
3186 struct osd_thread_info *info = osd_oti_get(env);
3187 struct inode *inode;
3188 struct osd_inode_id id;
3193 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3194 inode = osd_iget(info, dev, &id);
3196 RETURN(PTR_ERR(inode));
3198 if (!S_ISDIR(inode->i_mode))
3201 info->oti_seq_dirent = oie->oie_dirent;
3202 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file_dir);
3203 info->oti_seq_dirent = NULL;
3210 static int osd_scan_ml_file_main(const struct lu_env *env,
3211 struct osd_device *dev)
3213 return osd_scan_dir(env, dev, dev->od_ost_map->om_root->d_inode,
3214 osd_scan_ml_file_seq);