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 /* high priority inconsistent items list APIs */
55 #define SCRUB_BAD_OIMAP_DECAY_INTERVAL 60
58 * Add mapping into scrub.os_inconsistent_item list, and the OI scrub thread
59 * will fix them in priority.
61 int osd_scrub_oi_insert(struct osd_device *dev, const struct lu_fid *fid,
62 struct osd_inode_id *id, int insert)
64 struct osd_inconsistent_item *oii;
65 struct osd_scrub *oscrub = &dev->od_scrub;
66 struct lustre_scrub *lscrub = &oscrub->os_scrub;
72 if (unlikely(oii == NULL))
75 INIT_LIST_HEAD(&oii->oii_list);
76 oii->oii_cache.oic_fid = *fid;
77 oii->oii_cache.oic_lid = *id;
78 oii->oii_cache.oic_dev = dev;
79 oii->oii_insert = insert;
81 spin_lock(&lscrub->os_lock);
82 if (lscrub->os_partial_scan) {
83 __u64 now = ktime_get_real_seconds();
85 /* If there haven't been errors in a long time,
86 * decay old count until either the errors are
87 * gone or we reach the current interval.
89 while (unlikely(oscrub->os_bad_oimap_count > 0 &&
90 oscrub->os_bad_oimap_time +
91 SCRUB_BAD_OIMAP_DECAY_INTERVAL < now)) {
92 oscrub->os_bad_oimap_count >>= 1;
93 oscrub->os_bad_oimap_time +=
94 SCRUB_BAD_OIMAP_DECAY_INTERVAL;
97 oscrub->os_bad_oimap_time = now;
98 if (++oscrub->os_bad_oimap_count >
99 dev->od_full_scrub_threshold_rate)
100 lscrub->os_full_scrub = 1;
103 if (list_empty(&lscrub->os_inconsistent_items)) {
106 struct osd_inconsistent_item *tmp;
108 list_for_each_entry(tmp, &lscrub->os_inconsistent_items,
110 if (lu_fid_eq(fid, &tmp->oii_cache.oic_fid)) {
111 spin_unlock(&lscrub->os_lock);
118 list_add_tail(&oii->oii_list, &lscrub->os_inconsistent_items);
119 spin_unlock(&lscrub->os_lock);
127 /* if item could not be repaired, add it to the os_stale_items list to avoid
128 * triggering scrub repeatedly.
130 static inline void osd_scrub_oi_mark_stale(struct lustre_scrub *scrub,
131 struct osd_inconsistent_item *oii)
133 spin_lock(&scrub->os_lock);
134 list_move_tail(&oii->oii_list, &scrub->os_stale_items);
135 spin_unlock(&scrub->os_lock);
138 /* OI of \a fid may be marked stale, and if its mapping is scrubbed, remove it
139 * from os_stale_items list.
141 void osd_scrub_oi_resurrect(struct lustre_scrub *scrub,
142 const struct lu_fid *fid)
144 struct osd_inconsistent_item *oii;
146 if (list_empty(&scrub->os_stale_items))
149 spin_lock(&scrub->os_lock);
150 list_for_each_entry(oii, &scrub->os_stale_items, oii_list) {
151 if (lu_fid_eq(fid, &oii->oii_cache.oic_fid)) {
152 list_del(&oii->oii_list);
157 spin_unlock(&scrub->os_lock);
160 static void osd_scrub_ois_fini(struct lustre_scrub *scrub,
161 struct list_head *list)
163 struct osd_inconsistent_item *oii;
164 struct osd_inconsistent_item *tmp;
166 spin_lock(&scrub->os_lock);
167 list_for_each_entry_safe(oii, tmp, list, oii_list) {
168 list_del(&oii->oii_list);
171 spin_unlock(&scrub->os_lock);
174 static inline int osd_scrub_has_window(struct lustre_scrub *scrub,
175 struct osd_otable_cache *ooc)
177 return scrub->os_pos_current < ooc->ooc_pos_preload + SCRUB_WINDOW_SIZE;
181 * update/insert/delete the specified OI mapping (@fid @id) according to the ops
183 * \retval 1, changed nothing
184 * \retval 0, changed successfully
185 * \retval -ve, on error
187 int osd_scrub_refresh_mapping(struct osd_thread_info *info,
188 struct osd_device *dev,
189 const struct lu_fid *fid,
190 const struct osd_inode_id *id,
192 enum oi_check_flags flags, bool *exist)
198 if (dev->od_scrub.os_scrub.os_file.sf_param & SP_DRYRUN && !force)
201 /* DTO_INDEX_INSERT is enough for other two ops:
202 * delete/update, but save stack. */
203 th = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
204 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
207 CDEBUG(D_LFSCK, "%s: fail to start trans for scrub op %d "
208 DFID" => %u/%u: rc = %d\n", osd_name(dev), ops,
209 PFID(fid), id ? id->oii_ino : -1, id ? id->oii_gen : -1,
215 case DTO_INDEX_UPDATE:
216 rc = osd_oi_update(info, dev, fid, id, th, flags);
217 if (unlikely(rc == -ENOENT)) {
218 /* Some unlink thread may removed the OI mapping. */
222 case DTO_INDEX_INSERT:
223 rc = osd_oi_insert(info, dev, fid, id, th, flags, exist);
224 if (unlikely(rc == -EEXIST)) {
226 /* XXX: There are trouble things when adding OI
227 * mapping for IGIF object, which may cause
228 * multiple objects to be mapped to the same
229 * IGIF formatted FID. Consider the following
232 * 1) The MDT is upgrading from 1.8 device.
233 * The OI scrub generates IGIF FID1 for the
234 * OBJ1 and adds the OI mapping.
236 * 2) For some reason, the OI scrub does not
237 * process all the IGIF objects completely.
239 * 3) The MDT is backuped and restored against
242 * 4) When the MDT mounts up, the OI scrub will
243 * try to rebuild the OI files. For some IGIF
244 * object, OBJ2, which was not processed by the
245 * OI scrub before the backup/restore, and the
246 * new generated IGIF formatted FID may be just
247 * the FID1, the same as OBJ1.
249 * Under such case, the OI scrub cannot know how
250 * to generate new FID for the OBJ2.
252 * Currently, we do nothing for that. One possible
253 * solution is to generate new normal FID for the
256 * Anyway, it is rare, only exists in theory. */
259 case DTO_INDEX_DELETE:
260 rc = osd_oi_delete(info, dev, fid, th, flags);
262 /* It is normal that the unlink thread has removed the
263 * OI mapping already. */
268 LASSERTF(0, "Unexpected ops %d\n", ops);
272 ldiskfs_journal_stop(th);
274 CDEBUG(D_LFSCK, "%s: fail to refresh OI map for scrub op %d "
275 DFID" => %u/%u: rc = %d\n", osd_name(dev), ops,
276 PFID(fid), id ? id->oii_ino : -1, id ? id->oii_gen : -1,
283 osd_scrub_convert_ff(struct osd_thread_info *info, struct osd_device *dev,
284 struct inode *inode, const struct lu_fid *fid)
286 struct filter_fid_18_23 *ff = &info->oti_ff_old;
287 struct dentry *dentry = &info->oti_obj_dentry;
288 struct lu_fid *tfid = &info->oti_fid;
289 bool fid_18_23 = false;
295 if (dev->od_scrub.os_scrub.os_file.sf_param & SP_DRYRUN)
298 if (fid_is_idif(fid) && dev->od_index_in_idif == 0) {
299 struct ost_id *oi = &info->oti_ostid;
301 fid_to_ostid(fid, oi);
302 ostid_to_fid(tfid, oi, 0);
307 /* We want the LMA to fit into the 256-byte OST inode, so operate
309 * 1) read old XATTR_NAME_FID and save the parent FID;
310 * 2) delete the old XATTR_NAME_FID;
311 * 3) make new LMA and add it;
312 * 4) generate new XATTR_NAME_FID with the saved parent FID and add it.
314 * Making the LMA to fit into the 256-byte OST inode can save time for
315 * normal osd_check_lma() and for other OI scrub scanning in future.
316 * So it is worth to make some slow conversion here. */
317 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
318 osd_dto_credits_noquota[DTO_XATTR_SET] * 3);
321 CDEBUG(D_LFSCK, "%s: fail to start trans for convert ff "
322 DFID": rc = %d\n", osd_name(dev), PFID(tfid), rc);
326 /* 1) read old XATTR_NAME_FID and save the parent FID */
327 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_FID, ff, sizeof(*ff));
328 if (rc == sizeof(*ff)) {
329 /* 2) delete the old XATTR_NAME_FID */
330 dquot_initialize(inode);
331 rc = ll_vfs_removexattr(dentry, inode, XATTR_NAME_FID);
336 } else if (rc != -ENODATA && rc < (int)sizeof(struct filter_fid_24_29)) {
337 GOTO(stop, rc = -EINVAL);
340 /* 3) make new LMA and add it */
341 rc = osd_ea_fid_set(info, inode, tfid, LMAC_FID_ON_OST, 0);
344 /* If failed, we should try to add the old back. */
347 /* The new PFID EA will only contains ::ff_parent */
348 size = sizeof(ff->ff_parent);
351 /* 4) generate new XATTR_NAME_FID with the saved parent FID and add it*/
355 rc1 = __osd_xattr_set(info, inode, XATTR_NAME_FID, ff, size,
357 if (rc1 != 0 && rc == 0)
364 ldiskfs_journal_stop(jh);
366 CDEBUG(D_LFSCK, "%s: fail to convert ff "DFID": rc = %d\n",
367 osd_name(dev), PFID(tfid), rc);
372 osd_scrub_check_update(struct osd_thread_info *info, struct osd_device *dev,
373 struct osd_idmap_cache *oic, int val)
375 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
376 struct scrub_file *sf = &scrub->os_file;
377 struct lu_fid *fid = &oic->oic_fid;
378 struct osd_inode_id *lid = &oic->oic_lid;
379 struct osd_inode_id *lid2 = &info->oti_id;
380 struct osd_inconsistent_item *oii = NULL;
381 struct inode *inode = NULL;
382 int ops = DTO_INDEX_UPDATE;
384 bool converted = false;
388 down_write(&scrub->os_rwsem);
389 scrub->os_new_checked++;
393 if (scrub->os_in_prior) {
394 oii = list_entry(oic, struct osd_inconsistent_item,
396 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_STALE))
397 GOTO(out, rc = -ESTALE);
400 if (lid->oii_ino < sf->sf_pos_latest_start && oii == NULL)
403 if (fid_is_igif(fid))
406 if (val == SCRUB_NEXT_OSTOBJ_OLD) {
407 inode = osd_iget(info, dev, lid);
410 /* Someone removed the inode. */
411 if (rc == -ENOENT || rc == -ESTALE)
416 sf->sf_flags |= SF_UPGRADE;
417 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
418 dev->od_check_ff = 1;
419 rc = osd_scrub_convert_ff(info, dev, inode, fid);
426 if ((val == SCRUB_NEXT_NOLMA) &&
427 (!scrub->os_convert_igif || OBD_FAIL_CHECK(OBD_FAIL_FID_NOLMA)))
430 if ((oii != NULL && oii->oii_insert) || (val == SCRUB_NEXT_NOLMA)) {
431 ops = DTO_INDEX_INSERT;
436 rc = osd_oi_lookup(info, dev, fid, lid2,
437 (val == SCRUB_NEXT_OSTOBJ ||
438 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0);
441 ops = DTO_INDEX_INSERT;
442 else if (rc != -ESTALE)
447 inode = osd_iget(info, dev, lid);
450 /* Someone removed the inode. */
451 if (rc == -ENOENT || rc == -ESTALE)
458 case SCRUB_NEXT_NOLMA:
459 sf->sf_flags |= SF_UPGRADE;
460 if (!(sf->sf_param & SP_DRYRUN)) {
461 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
466 if (!(sf->sf_flags & SF_INCONSISTENT))
467 dev->od_igif_inoi = 0;
469 case SCRUB_NEXT_OSTOBJ:
470 sf->sf_flags |= SF_INCONSISTENT;
471 case SCRUB_NEXT_OSTOBJ_OLD:
476 } else if (osd_id_eq(lid, lid2)) {
478 sf->sf_items_updated++;
482 if (!scrub->os_partial_scan) {
483 spin_lock(&scrub->os_lock);
484 scrub->os_full_speed = 1;
485 spin_unlock(&scrub->os_lock);
487 sf->sf_flags |= SF_INCONSISTENT;
489 /* XXX: If the device is restored from file-level backup, then
490 * some IGIFs may have been already in OI files, and some
491 * may be not yet. Means upgrading from 1.8 may be partly
492 * processed, but some clients may hold some immobilized
493 * IGIFs, and use them to access related objects. Under
494 * such case, OSD does not know whether an given IGIF has
495 * been processed or to be processed, and it also cannot
496 * generate local ino#/gen# directly from the immobilized
497 * IGIF because of the backup/restore. Then force OSD to
498 * lookup the given IGIF in OI files, and if no entry,
499 * then ask the client to retry after upgrading completed.
500 * No better choice. */
501 dev->od_igif_inoi = 1;
504 rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops, false,
505 (val == SCRUB_NEXT_OSTOBJ ||
506 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0,
509 if (scrub->os_in_prior)
510 sf->sf_items_updated_prior++;
512 sf->sf_items_updated++;
514 if (ops == DTO_INDEX_INSERT && val == 0 && !exist) {
515 int idx = osd_oi_fid2idx(dev, fid);
517 sf->sf_flags |= SF_RECREATED;
518 if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
519 ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
527 sf->sf_items_failed++;
528 if (sf->sf_pos_first_inconsistent == 0 ||
529 sf->sf_pos_first_inconsistent > lid->oii_ino)
530 sf->sf_pos_first_inconsistent = lid->oii_ino;
532 osd_scrub_oi_mark_stale(scrub, oii);
534 "%s: fix inconsistent OI "DFID" -> %u/%u failed: %d\n",
535 osd_dev2name(dev), PFID(fid), lid->oii_ino,
539 if (!oii && !OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_STALE)) {
540 osd_scrub_oi_resurrect(scrub, fid);
542 "%s: resurrect OI "DFID" -> %u/%u\n",
543 osd_dev2name(dev), PFID(fid), lid->oii_ino,
546 /* release fixed inconsistent item */
548 "%s: inconsistent OI "DFID" -> %u/%u fixed\n",
549 osd_dev2name(dev), PFID(fid), lid->oii_ino,
551 spin_lock(&scrub->os_lock);
552 list_del_init(&oii->oii_list);
553 spin_unlock(&scrub->os_lock);
560 /* There may be conflict unlink during the OI scrub,
561 * if happend, then remove the new added OI mapping. */
562 if (ops == DTO_INDEX_INSERT && !IS_ERR_OR_NULL(inode) &&
563 unlikely(ldiskfs_test_inode_state(inode,
564 LDISKFS_STATE_LUSTRE_DESTROY)))
565 osd_scrub_refresh_mapping(info, dev, fid, lid,
566 DTO_INDEX_DELETE, false,
567 (val == SCRUB_NEXT_OSTOBJ ||
568 val == SCRUB_NEXT_OSTOBJ_OLD) ?
569 OI_KNOWN_ON_OST : 0, NULL);
571 up_write(&scrub->os_rwsem);
573 if (!IS_ERR_OR_NULL(inode))
576 RETURN(sf->sf_param & SP_FAILOUT ? rc : 0);
579 /* iteration engine */
581 typedef int (*osd_iit_next_policy)(struct osd_thread_info *info,
582 struct osd_device *dev,
583 struct osd_iit_param *param,
584 struct osd_idmap_cache **oic,
587 typedef int (*osd_iit_exec_policy)(struct osd_thread_info *info,
588 struct osd_device *dev,
589 struct osd_iit_param *param,
590 struct osd_idmap_cache *oic,
591 bool *noslot, int rc);
593 static int osd_iit_next(struct osd_iit_param *param, __u64 *pos)
598 param->offset = ldiskfs_find_next_bit(param->bitmap->b_data,
599 LDISKFS_INODES_PER_GROUP(param->sb), param->offset);
600 if (param->offset >= LDISKFS_INODES_PER_GROUP(param->sb)) {
601 *pos = 1 + (param->bg+1) * LDISKFS_INODES_PER_GROUP(param->sb);
602 return SCRUB_NEXT_BREAK;
605 offset = param->offset++;
606 if (unlikely(*pos == param->gbase + offset && *pos != param->start)) {
607 /* We should NOT find the same object more than once. */
608 CERROR("%s: scan the same object multiple times at the pos: "
609 "group = %u, base = %u, offset = %u, start = %u\n",
610 osd_sb2name(param->sb), (__u32)param->bg, param->gbase,
611 offset, param->start);
615 *pos = param->gbase + offset;
620 * \retval SCRUB_NEXT_OSTOBJ_OLD: FID-on-OST
621 * \retval 0: FID-on-MDT
623 static int osd_scrub_check_local_fldb(struct osd_thread_info *info,
624 struct osd_device *dev,
627 /* XXX: The initial OI scrub will scan the top level /O to generate
628 * a small local FLDB according to the <seq>. If the given FID
629 * is in the local FLDB, then it is FID-on-OST; otherwise it's
630 * quite possible for FID-on-MDT. */
632 return SCRUB_NEXT_OSTOBJ_OLD;
637 static int osd_scrub_get_fid(struct osd_thread_info *info,
638 struct osd_device *dev, struct inode *inode,
639 struct lu_fid *fid, bool scrub)
641 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
642 bool has_lma = false;
645 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
646 &info->oti_ost_attrs);
649 if (lma->lma_compat & LMAC_NOT_IN_OI ||
650 lma->lma_incompat & LMAI_AGENT)
651 return SCRUB_NEXT_CONTINUE;
653 *fid = lma->lma_self_fid;
657 if (lma->lma_compat & LMAC_FID_ON_OST)
658 return SCRUB_NEXT_OSTOBJ;
660 if (fid_is_idif(fid))
661 return SCRUB_NEXT_OSTOBJ_OLD;
663 /* For local object. */
664 if (fid_is_internal(fid))
667 /* For external visible MDT-object with non-normal FID. */
668 if (fid_is_namespace_visible(fid) && !fid_is_norm(fid))
671 /* For the object with normal FID, it may be MDT-object,
672 * or may be 2.4 OST-object, need further distinguish.
673 * Fall through to next section. */
676 if (rc == -ENODATA || rc == 0) {
677 rc = osd_get_idif(info, inode, &info->oti_obj_dentry, fid);
680 /* It is 2.3 or older OST-object. */
681 rc = SCRUB_NEXT_OSTOBJ_OLD;
687 /* It is FID-on-OST, but we do not know how
688 * to generate its FID, ignore it directly. */
689 rc = SCRUB_NEXT_CONTINUE;
691 /* It is 2.4 or newer OST-object. */
692 rc = SCRUB_NEXT_OSTOBJ_OLD;
700 if (dev->od_scrub.os_scrub.os_convert_igif) {
701 lu_igif_build(fid, inode->i_ino,
702 inode->i_generation);
704 rc = SCRUB_NEXT_NOLMA;
708 /* It may be FID-on-OST, or may be FID for
709 * non-MDT0, anyway, we do not know how to
710 * generate its FID, ignore it directly. */
711 rc = SCRUB_NEXT_CONTINUE;
716 /* For OI scrub case only: the object has LMA but has no ff
717 * (or ff crashed). It may be MDT-object, may be OST-object
718 * with crashed ff. The last check is local FLDB. */
719 rc = osd_scrub_check_local_fldb(info, dev, fid);
725 static int osd_iit_iget(struct osd_thread_info *info, struct osd_device *dev,
726 struct lu_fid *fid, struct osd_inode_id *lid, __u32 pos,
727 struct super_block *sb, bool scrub)
733 /* Not handle the backend root object and agent parent object.
734 * They are neither visible to namespace nor have OI mappings. */
735 if (unlikely(pos == osd_sb(dev)->s_root->d_inode->i_ino ||
736 is_remote_parent_ino(dev, pos)))
737 RETURN(SCRUB_NEXT_CONTINUE);
739 /* Skip project quota inode since it is greater than s_first_ino. */
740 #ifdef HAVE_PROJECT_QUOTA
741 if (ldiskfs_has_feature_project(sb) &&
742 pos == le32_to_cpu(LDISKFS_SB(sb)->s_es->s_prj_quota_inum))
743 RETURN(SCRUB_NEXT_CONTINUE);
746 osd_id_gen(lid, pos, OSD_OII_NOGEN);
747 inode = osd_iget(info, dev, lid);
750 /* The inode may be removed after bitmap searching, or the
751 * file is new created without inode initialized yet.
752 * LU-15754: After "new primitive: discard_new_inode()" change
753 * in the kernel find_inode_fast() returns -ESTALE, but
754 * iget_locked replaces it to the NULL and finally
755 * ldiskfs_inode_attach_jinode() returns -ENOMEM
756 * Let's skip an inode if -ENOMEM returned.
758 if (rc == -ENOENT || rc == -ESTALE || rc == -ENOMEM)
759 RETURN(SCRUB_NEXT_CONTINUE);
761 CDEBUG(D_LFSCK, "%s: fail to read inode, ino# = %u: "
762 "rc = %d\n", osd_dev2name(dev), pos, rc);
766 if (dev->od_is_ost && S_ISREG(inode->i_mode) && inode->i_nlink > 1)
767 dev->od_scrub.os_scrub.os_has_ml_file = 1;
770 ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB)) {
771 /* Only skip it for the first OI scrub accessing. */
772 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
773 GOTO(put, rc = SCRUB_NEXT_NOSCRUB);
776 rc = osd_scrub_get_fid(info, dev, inode, fid, scrub);
785 static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
786 struct osd_iit_param *param,
787 struct osd_idmap_cache **oic, const bool noslot)
789 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
791 struct osd_inode_id *lid;
794 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0)
795 wait_var_event_timeout(
797 !list_empty(&scrub->os_inconsistent_items) ||
798 kthread_should_stop(),
799 cfs_time_seconds(cfs_fail_val));
801 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_CRASH)) {
802 spin_lock(&scrub->os_lock);
803 scrub->os_running = 0;
804 spin_unlock(&scrub->os_lock);
805 return SCRUB_NEXT_CRASH;
808 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_FATAL))
809 return SCRUB_NEXT_FATAL;
811 if (kthread_should_stop())
812 return SCRUB_NEXT_EXIT;
814 if (!list_empty(&scrub->os_inconsistent_items)) {
815 spin_lock(&scrub->os_lock);
816 if (likely(!list_empty(&scrub->os_inconsistent_items))) {
817 struct osd_inconsistent_item *oii;
819 oii = list_entry(scrub->os_inconsistent_items.next,
820 struct osd_inconsistent_item, oii_list);
822 *oic = &oii->oii_cache;
823 scrub->os_in_prior = 1;
824 spin_unlock(&scrub->os_lock);
828 spin_unlock(&scrub->os_lock);
832 return SCRUB_NEXT_WAIT;
834 rc = osd_iit_next(param, &scrub->os_pos_current);
838 *oic = &dev->od_scrub.os_oic;
839 fid = &(*oic)->oic_fid;
840 lid = &(*oic)->oic_lid;
841 rc = osd_iit_iget(info, dev, fid, lid,
842 scrub->os_pos_current, param->sb, true);
846 static int osd_preload_next(struct osd_thread_info *info,
847 struct osd_device *dev, struct osd_iit_param *param,
848 struct osd_idmap_cache **oic, const bool noslot)
850 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
851 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
854 if (scrub->os_running &&
855 ooc->ooc_pos_preload >= scrub->os_pos_current)
856 return SCRUB_NEXT_EXIT;
858 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
862 rc = osd_iit_iget(info, dev,
863 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
864 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
865 ooc->ooc_pos_preload, param->sb, false);
870 osd_scrub_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
872 spin_lock(&scrub->os_lock);
873 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
874 !list_empty(&scrub->os_inconsistent_items) ||
875 it->ooi_waiting || kthread_should_stop())
876 scrub->os_waiting = 0;
878 scrub->os_waiting = 1;
879 spin_unlock(&scrub->os_lock);
881 return !scrub->os_waiting;
884 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
885 struct osd_iit_param *param,
886 struct osd_idmap_cache *oic, bool *noslot, int rc)
888 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
889 struct scrub_file *sf = &scrub->os_file;
890 struct osd_otable_it *it = dev->od_otable_it;
891 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
894 case SCRUB_NEXT_NOSCRUB:
895 down_write(&scrub->os_rwsem);
896 scrub->os_new_checked++;
897 sf->sf_items_noscrub++;
898 up_write(&scrub->os_rwsem);
899 case SCRUB_NEXT_CONTINUE:
900 case SCRUB_NEXT_WAIT:
904 rc = osd_scrub_check_update(info, dev, oic, rc);
906 spin_lock(&scrub->os_lock);
907 scrub->os_in_prior = 0;
908 spin_unlock(&scrub->os_lock);
912 rc = scrub_checkpoint(info->oti_env, scrub);
914 CDEBUG(D_LFSCK, "%s: fail to checkpoint, pos = %llu: "
915 "rc = %d\n", osd_scrub2name(scrub),
916 scrub->os_pos_current, rc);
917 /* Continue, as long as the scrub itself can go ahead. */
920 if (scrub->os_in_prior) {
921 spin_lock(&scrub->os_lock);
922 scrub->os_in_prior = 0;
923 spin_unlock(&scrub->os_lock);
928 if (it != NULL && it->ooi_waiting && ooc != NULL &&
929 ooc->ooc_pos_preload < scrub->os_pos_current) {
930 spin_lock(&scrub->os_lock);
933 spin_unlock(&scrub->os_lock);
936 if (rc == SCRUB_NEXT_CONTINUE)
939 if (scrub->os_full_speed || !ooc || osd_scrub_has_window(scrub, ooc)) {
945 wait_var_event(scrub, osd_scrub_wakeup(scrub, it));
947 if (!ooc || osd_scrub_has_window(scrub, ooc))
954 static int osd_preload_exec(struct osd_thread_info *info,
955 struct osd_device *dev, struct osd_iit_param *param,
956 struct osd_idmap_cache *oic, bool *noslot, int rc)
958 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
961 ooc->ooc_cached_items++;
962 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
963 ~OSD_OTABLE_IT_CACHE_MASK;
965 return rc > 0 ? 0 : rc;
968 #define SCRUB_IT_ALL 1
969 #define SCRUB_IT_CRASH 2
971 static void osd_scrub_join(const struct lu_env *env, struct osd_device *dev,
972 __u32 flags, bool inconsistent)
974 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
975 struct scrub_file *sf = &scrub->os_file;
979 LASSERT(!(flags & SS_AUTO_PARTIAL));
981 down_write(&scrub->os_rwsem);
982 spin_lock(&scrub->os_lock);
983 scrub->os_in_join = 1;
984 if (flags & SS_SET_FAILOUT)
985 sf->sf_param |= SP_FAILOUT;
986 else if (flags & SS_CLEAR_FAILOUT)
987 sf->sf_param &= ~SP_FAILOUT;
989 if (flags & SS_SET_DRYRUN)
990 sf->sf_param |= SP_DRYRUN;
991 else if (flags & SS_CLEAR_DRYRUN)
992 sf->sf_param &= ~SP_DRYRUN;
994 if (flags & SS_RESET) {
995 scrub_file_reset(scrub, dev->od_uuid,
996 inconsistent ? SF_INCONSISTENT : 0);
997 sf->sf_status = SS_SCANNING;
1000 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
1001 scrub->os_full_speed = 1;
1003 scrub->os_full_speed = 0;
1005 if (flags & SS_AUTO_FULL) {
1006 sf->sf_flags |= SF_AUTO;
1007 scrub->os_full_speed = 1;
1009 spin_unlock(&scrub->os_lock);
1011 scrub->os_new_checked = 0;
1012 if (sf->sf_pos_last_checkpoint != 0)
1013 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
1015 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
1017 scrub->os_pos_current = sf->sf_pos_latest_start;
1018 sf->sf_time_latest_start = ktime_get_real_seconds();
1019 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
1020 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
1021 rc = scrub_file_store(env, scrub);
1023 spin_lock(&scrub->os_lock);
1024 scrub->os_waiting = 0;
1025 scrub->os_paused = 0;
1026 scrub->os_partial_scan = 0;
1027 scrub->os_in_join = 0;
1028 scrub->os_full_scrub = 0;
1029 spin_unlock(&scrub->os_lock);
1031 up_write(&scrub->os_rwsem);
1033 CDEBUG(D_LFSCK, "%s: joined in the OI scrub with flag %u: rc = %d\n",
1034 osd_scrub2name(scrub), flags, rc);
1039 static int osd_inode_iteration(struct osd_thread_info *info,
1040 struct osd_device *dev, __u32 max, bool preload)
1042 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1043 struct scrub_file *sf = &scrub->os_file;
1044 osd_iit_next_policy next;
1045 osd_iit_exec_policy exec;
1048 struct osd_iit_param *param;
1057 param = &dev->od_scrub.os_iit_param;
1058 memset(param, 0, sizeof(*param));
1059 param->sb = osd_sb(dev);
1061 while (scrub->os_partial_scan && !scrub->os_in_join) {
1062 struct osd_idmap_cache *oic = NULL;
1064 rc = osd_scrub_next(info, dev, param, &oic, noslot);
1066 case SCRUB_NEXT_EXIT:
1068 case SCRUB_NEXT_CRASH:
1069 RETURN(SCRUB_IT_CRASH);
1070 case SCRUB_NEXT_FATAL:
1072 case SCRUB_NEXT_WAIT: {
1073 struct kstatfs *ksfs = &info->oti_ksfs;
1076 if (dev->od_full_scrub_ratio == OFSR_NEVER ||
1077 unlikely(sf->sf_items_updated_prior == 0))
1080 if (dev->od_full_scrub_ratio == OFSR_DIRECTLY ||
1081 scrub->os_full_scrub) {
1082 osd_scrub_join(info->oti_env, dev,
1083 SS_AUTO_FULL | SS_RESET, true);
1087 rc = param->sb->s_op->statfs(param->sb->s_root, ksfs);
1089 __u64 used = ksfs->f_files - ksfs->f_ffree;
1091 used = div64_u64(used, sf->sf_items_updated_prior);
1092 /* If we hit too much inconsistent OI
1093 * mappings during the partial scan,
1094 * then scan the device completely. */
1095 if (used < dev->od_full_scrub_ratio) {
1096 osd_scrub_join(info->oti_env, dev,
1097 SS_AUTO_FULL | SS_RESET, true);
1103 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) &&
1107 saved_flags = sf->sf_flags;
1108 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
1109 SF_UPGRADE | SF_AUTO);
1110 sf->sf_status = SS_COMPLETED;
1113 kthread_should_stop() ||
1114 !scrub->os_partial_scan ||
1115 scrub->os_in_join ||
1116 !list_empty(&scrub->os_inconsistent_items));
1117 sf->sf_flags = saved_flags;
1118 sf->sf_status = SS_SCANNING;
1120 if (kthread_should_stop())
1123 if (!scrub->os_partial_scan || scrub->os_in_join)
1129 LASSERTF(rc == 0, "rc = %d\n", rc);
1131 osd_scrub_exec(info, dev, param, oic, &noslot, rc);
1138 wait_var_event(scrub,
1139 kthread_should_stop() ||
1140 !scrub->os_in_join);
1142 if (kthread_should_stop())
1148 next = osd_scrub_next;
1149 exec = osd_scrub_exec;
1150 pos = &scrub->os_pos_current;
1151 count = &scrub->os_new_checked;
1152 param->start = *pos;
1153 param->bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param->sb);
1155 (*pos - 1) % LDISKFS_INODES_PER_GROUP(param->sb);
1157 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1159 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1161 next = osd_preload_next;
1162 exec = osd_preload_exec;
1163 pos = &ooc->ooc_pos_preload;
1164 count = &ooc->ooc_cached_items;
1165 param = &dev->od_otable_it->ooi_iit_param;
1169 limit = le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count);
1170 while (*pos <= limit && *count < max) {
1171 struct ldiskfs_group_desc *desc;
1172 bool next_group = false;
1174 desc = ldiskfs_get_group_desc(param->sb, param->bg, NULL);
1178 if (desc->bg_flags & cpu_to_le16(LDISKFS_BG_INODE_UNINIT)) {
1183 param->bitmap = ldiskfs_read_inode_bitmap(param->sb, param->bg);
1184 if (IS_ERR_OR_NULL(param->bitmap)) {
1185 if (param->bitmap) {
1186 rc = PTR_ERR(param->bitmap);
1187 param->bitmap = NULL;
1191 CERROR("%s: fail to read bitmap for %u, scrub will stop, urgent mode: rc = %d\n",
1192 osd_scrub2name(scrub), (__u32)param->bg, rc);
1197 struct osd_idmap_cache *oic = NULL;
1200 ldiskfs_itable_unused_count(param->sb, desc) >=
1201 LDISKFS_INODES_PER_GROUP(param->sb)) {
1206 rc = next(info, dev, param, &oic, noslot);
1208 case SCRUB_NEXT_BREAK:
1211 case SCRUB_NEXT_EXIT:
1212 brelse(param->bitmap);
1214 case SCRUB_NEXT_CRASH:
1215 brelse(param->bitmap);
1216 RETURN(SCRUB_IT_CRASH);
1217 case SCRUB_NEXT_FATAL:
1218 brelse(param->bitmap);
1222 rc = exec(info, dev, param, oic, &noslot, rc);
1223 } while (!rc && *pos <= limit && *count < max);
1226 if (param->bitmap) {
1227 brelse(param->bitmap);
1228 param->bitmap = NULL;
1238 param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1239 *pos = param->gbase;
1240 param->start = *pos;
1245 RETURN(SCRUB_IT_ALL);
1251 static int osd_otable_it_preload(const struct lu_env *env,
1252 struct osd_otable_it *it)
1254 struct osd_device *dev = it->ooi_dev;
1255 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1256 struct osd_otable_cache *ooc = &it->ooi_cache;
1260 rc = osd_inode_iteration(osd_oti_get(env), dev,
1261 OSD_OTABLE_IT_CACHE_SIZE, true);
1262 if (rc == SCRUB_IT_ALL)
1263 it->ooi_all_cached = 1;
1265 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1266 spin_lock(&scrub->os_lock);
1267 scrub->os_waiting = 0;
1269 spin_unlock(&scrub->os_lock);
1272 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1275 static int osd_scan_ml_file_main(const struct lu_env *env,
1276 struct osd_device *dev);
1278 static int osd_scrub_main(void *args)
1281 struct osd_device *dev = (struct osd_device *)args;
1282 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1286 rc = lu_env_init(&env, LCT_LOCAL | LCT_DT_THREAD);
1288 CDEBUG(D_LFSCK, "%s: OI scrub fail to init env: rc = %d\n",
1289 osd_scrub2name(scrub), rc);
1293 rc = scrub_thread_prep(&env, scrub, dev->od_uuid,
1294 LDISKFS_FIRST_INO(osd_sb(dev)) + 1);
1296 CDEBUG(D_LFSCK, "%s: OI scrub fail to scrub prep: rc = %d\n",
1297 osd_scrub2name(scrub), rc);
1301 if (!scrub->os_full_speed && !scrub->os_partial_scan) {
1302 struct osd_otable_it *it = dev->od_otable_it;
1303 struct osd_otable_cache *ooc = &it->ooi_cache;
1305 wait_var_event(scrub,
1306 it->ooi_user_ready || kthread_should_stop());
1307 if (kthread_should_stop())
1310 scrub->os_pos_current = ooc->ooc_pos_preload;
1313 CDEBUG(D_LFSCK, "%s: OI scrub start, flags = 0x%x, pos = %llu\n",
1314 osd_scrub2name(scrub), scrub->os_start_flags,
1315 scrub->os_pos_current);
1317 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1318 if (unlikely(rc == SCRUB_IT_CRASH)) {
1319 spin_lock(&scrub->os_lock);
1320 scrub->os_running = 0;
1321 spin_unlock(&scrub->os_lock);
1322 GOTO(out, rc = -EINVAL);
1325 if (scrub->os_has_ml_file) {
1326 ret = osd_scan_ml_file_main(&env, dev);
1335 dev->od_igif_inoi = 1;
1336 dev->od_check_ff = 0;
1338 rc = scrub_thread_post(&env, &dev->od_scrub.os_scrub, rc);
1339 CDEBUG(D_LFSCK, "%s: OI scrub: stop, pos = %llu: rc = %d\n",
1340 osd_scrub2name(scrub), scrub->os_pos_current, rc);
1343 osd_scrub_ois_fini(scrub, &scrub->os_inconsistent_items);
1347 spin_lock(&scrub->os_lock);
1348 scrub->os_running = 0;
1349 spin_unlock(&scrub->os_lock);
1350 if (xchg(&scrub->os_task, NULL) == NULL)
1351 /* scrub_stop() is waiting, we need to synchronize */
1352 wait_var_event(scrub, kthread_should_stop());
1357 /* initial OI scrub */
1359 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1360 struct dentry *, filldir_t filldir);
1362 #ifdef HAVE_FILLDIR_USE_CTX
1363 static int osd_ios_varfid_fill(struct dir_context *buf, const char *name,
1364 int namelen, loff_t offset, __u64 ino,
1366 static int osd_ios_lf_fill(struct dir_context *buf, const char *name,
1367 int namelen, loff_t offset, __u64 ino,
1369 static int osd_ios_dl_fill(struct dir_context *buf, const char *name,
1370 int namelen, loff_t offset, __u64 ino,
1372 static int osd_ios_uld_fill(struct dir_context *buf, const char *name,
1373 int namelen, loff_t offset, __u64 ino,
1376 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1377 loff_t offset, __u64 ino, unsigned d_type);
1378 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1379 loff_t offset, __u64 ino, unsigned d_type);
1380 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1381 loff_t offset, __u64 ino, unsigned d_type);
1382 static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
1383 loff_t offset, __u64 ino, unsigned d_type);
1387 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1388 struct dentry *dentry, filldir_t filldir);
1390 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1391 struct dentry *dentry, filldir_t filldir);
1394 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1395 struct dentry *dentry, filldir_t filldir);
1399 struct lu_fid olm_fid;
1402 scandir_t olm_scandir;
1403 filldir_t olm_filldir;
1406 /* Add the new introduced local files in the list in the future. */
1407 static const struct osd_lf_map osd_lf_maps[] = {
1410 .olm_name = CATLIST,
1412 .f_seq = FID_SEQ_LOCAL_FILE,
1413 .f_oid = LLOG_CATALOGS_OID,
1415 .olm_flags = OLF_SHOW_NAME,
1416 .olm_namelen = sizeof(CATLIST) - 1,
1421 .olm_name = MOUNT_CONFIGS_DIR,
1423 .f_seq = FID_SEQ_LOCAL_FILE,
1424 .f_oid = MGS_CONFIGS_OID,
1426 .olm_flags = OLF_SCAN_SUBITEMS,
1427 .olm_namelen = sizeof(MOUNT_CONFIGS_DIR) - 1,
1428 .olm_scandir = osd_ios_general_scan,
1429 .olm_filldir = osd_ios_varfid_fill,
1432 /* NIDTBL_VERSIONS */
1434 .olm_name = MGS_NIDTBL_DIR,
1435 .olm_flags = OLF_SCAN_SUBITEMS,
1436 .olm_namelen = sizeof(MGS_NIDTBL_DIR) - 1,
1437 .olm_scandir = osd_ios_general_scan,
1438 .olm_filldir = osd_ios_varfid_fill,
1443 .olm_name = MDT_ORPHAN_DIR,
1444 .olm_namelen = sizeof(MDT_ORPHAN_DIR) - 1,
1451 .f_seq = FID_SEQ_ROOT,
1452 .f_oid = FID_OID_ROOT,
1454 .olm_flags = OLF_SCAN_SUBITEMS | OLF_HIDE_FID,
1455 .olm_namelen = sizeof("ROOT") - 1,
1456 .olm_scandir = osd_ios_ROOT_scan,
1459 /* changelog_catalog */
1461 .olm_name = CHANGELOG_CATALOG,
1462 .olm_namelen = sizeof(CHANGELOG_CATALOG) - 1,
1465 /* changelog_users */
1467 .olm_name = CHANGELOG_USERS,
1468 .olm_namelen = sizeof(CHANGELOG_USERS) - 1,
1475 .f_seq = FID_SEQ_LOCAL_FILE,
1476 .f_oid = FLD_INDEX_OID,
1478 .olm_flags = OLF_SHOW_NAME,
1479 .olm_namelen = sizeof("fld") - 1,
1484 .olm_name = LAST_RCVD,
1486 .f_seq = FID_SEQ_LOCAL_FILE,
1487 .f_oid = LAST_RECV_OID,
1489 .olm_flags = OLF_SHOW_NAME,
1490 .olm_namelen = sizeof(LAST_RCVD) - 1,
1495 .olm_name = REPLY_DATA,
1497 .f_seq = FID_SEQ_LOCAL_FILE,
1498 .f_oid = REPLY_DATA_OID,
1500 .olm_flags = OLF_SHOW_NAME,
1501 .olm_namelen = sizeof(REPLY_DATA) - 1,
1506 .olm_name = LOV_OBJID,
1508 .f_seq = FID_SEQ_LOCAL_FILE,
1509 .f_oid = MDD_LOV_OBJ_OID,
1511 .olm_flags = OLF_SHOW_NAME,
1512 .olm_namelen = sizeof(LOV_OBJID) - 1,
1517 .olm_name = LOV_OBJSEQ,
1519 .f_seq = FID_SEQ_LOCAL_FILE,
1520 .f_oid = MDD_LOV_OBJ_OSEQ,
1522 .olm_flags = OLF_SHOW_NAME,
1523 .olm_namelen = sizeof(LOV_OBJSEQ) - 1,
1528 .olm_name = QMT_DIR,
1529 .olm_flags = OLF_SCAN_SUBITEMS,
1530 .olm_namelen = sizeof(QMT_DIR) - 1,
1531 .olm_scandir = osd_ios_general_scan,
1532 .olm_filldir = osd_ios_varfid_fill,
1537 .olm_name = QSD_DIR,
1538 .olm_flags = OLF_SCAN_SUBITEMS,
1539 .olm_namelen = sizeof(QSD_DIR) - 1,
1540 .olm_scandir = osd_ios_general_scan,
1541 .olm_filldir = osd_ios_varfid_fill,
1546 .olm_name = "seq_ctl",
1548 .f_seq = FID_SEQ_LOCAL_FILE,
1549 .f_oid = FID_SEQ_CTL_OID,
1551 .olm_flags = OLF_SHOW_NAME,
1552 .olm_namelen = sizeof("seq_ctl") - 1,
1557 .olm_name = "seq_srv",
1559 .f_seq = FID_SEQ_LOCAL_FILE,
1560 .f_oid = FID_SEQ_SRV_OID,
1562 .olm_flags = OLF_SHOW_NAME,
1563 .olm_namelen = sizeof("seq_srv") - 1,
1568 .olm_name = HEALTH_CHECK,
1570 .f_seq = FID_SEQ_LOCAL_FILE,
1571 .f_oid = OFD_HEALTH_CHECK_OID,
1573 .olm_flags = OLF_SHOW_NAME,
1574 .olm_namelen = sizeof(HEALTH_CHECK) - 1,
1579 .olm_name = LFSCK_DIR,
1580 .olm_flags = OLF_SCAN_SUBITEMS,
1581 .olm_namelen = sizeof(LFSCK_DIR) - 1,
1582 .olm_scandir = osd_ios_general_scan,
1583 .olm_filldir = osd_ios_varfid_fill,
1586 /* lfsck_bookmark */
1588 .olm_name = LFSCK_BOOKMARK,
1589 .olm_namelen = sizeof(LFSCK_BOOKMARK) - 1,
1594 .olm_name = LFSCK_LAYOUT,
1595 .olm_namelen = sizeof(LFSCK_LAYOUT) - 1,
1598 /* lfsck_namespace */
1600 .olm_name = LFSCK_NAMESPACE,
1601 .olm_namelen = sizeof(LFSCK_NAMESPACE) - 1,
1604 /* OBJECTS, upgrade from old device */
1606 .olm_name = OBJECTS,
1607 .olm_flags = OLF_SCAN_SUBITEMS,
1608 .olm_namelen = sizeof(OBJECTS) - 1,
1609 .olm_scandir = osd_ios_OBJECTS_scan,
1612 /* lquota_v2.user, upgrade from old device */
1614 .olm_name = "lquota_v2.user",
1615 .olm_namelen = sizeof("lquota_v2.user") - 1,
1618 /* lquota_v2.group, upgrade from old device */
1620 .olm_name = "lquota_v2.group",
1621 .olm_namelen = sizeof("lquota_v2.group") - 1,
1624 /* LAST_GROUP, upgrade from old device */
1626 .olm_name = "LAST_GROUP",
1628 .f_seq = FID_SEQ_LOCAL_FILE,
1629 .f_oid = OFD_LAST_GROUP_OID,
1631 .olm_flags = OLF_SHOW_NAME,
1632 .olm_namelen = sizeof("LAST_GROUP") - 1,
1635 /* committed batchid for cross-MDT operation */
1637 .olm_name = "BATCHID",
1639 .f_seq = FID_SEQ_LOCAL_FILE,
1640 .f_oid = BATCHID_COMMITTED_OID,
1642 .olm_flags = OLF_SHOW_NAME,
1643 .olm_namelen = sizeof("BATCHID") - 1,
1646 /* OSP update logs update_log{_dir} use f_seq = FID_SEQ_UPDATE_LOG{_DIR}
1647 * and f_oid = index for their log files. See lu_update_log{_dir}_fid()
1648 * for more details. */
1652 .olm_name = "update_log",
1654 .f_seq = FID_SEQ_UPDATE_LOG,
1656 .olm_flags = OLF_SHOW_NAME | OLF_IDX_IN_FID,
1657 .olm_namelen = sizeof("update_log") - 1,
1660 /* update_log_dir */
1662 .olm_name = "update_log_dir",
1664 .f_seq = FID_SEQ_UPDATE_LOG_DIR,
1666 .olm_flags = OLF_SHOW_NAME | OLF_SCAN_SUBITEMS |
1668 .olm_namelen = sizeof("update_log_dir") - 1,
1669 .olm_scandir = osd_ios_general_scan,
1670 .olm_filldir = osd_ios_uld_fill,
1675 .olm_name = "lost+found",
1677 .f_seq = FID_SEQ_LOCAL_FILE,
1678 .f_oid = OSD_LPF_OID,
1680 .olm_flags = OLF_SCAN_SUBITEMS,
1681 .olm_namelen = sizeof("lost+found") - 1,
1682 .olm_scandir = osd_ios_general_scan,
1683 .olm_filldir = osd_ios_lf_fill,
1688 .olm_name = HSM_ACTIONS,
1693 .olm_name = LUSTRE_NODEMAP_NAME,
1698 .olm_name = INDEX_BACKUP_DIR,
1700 .f_seq = FID_SEQ_LOCAL_FILE,
1701 .f_oid = INDEX_BACKUP_OID,
1703 .olm_flags = OLF_SCAN_SUBITEMS | OLF_NOT_BACKUP,
1704 .olm_namelen = sizeof(INDEX_BACKUP_DIR) - 1,
1705 .olm_scandir = osd_ios_general_scan,
1706 .olm_filldir = osd_ios_varfid_fill,
1714 /* Add the new introduced files under .lustre/ in the list in the future. */
1715 static const struct osd_lf_map osd_dl_maps[] = {
1720 .f_seq = FID_SEQ_DOT_LUSTRE,
1721 .f_oid = FID_OID_DOT_LUSTRE_OBF,
1723 .olm_namelen = sizeof("fid") - 1,
1726 /* .lustre/lost+found */
1728 .olm_name = "lost+found",
1730 .f_seq = FID_SEQ_DOT_LUSTRE,
1731 .f_oid = FID_OID_DOT_LUSTRE_LPF,
1733 .olm_namelen = sizeof("lost+found") - 1,
1741 struct osd_ios_item {
1742 struct list_head oii_list;
1743 struct dentry *oii_dentry;
1744 scandir_t oii_scandir;
1745 filldir_t oii_filldir;
1748 struct osd_ios_filldir_buf {
1749 /* please keep it as first member */
1750 struct dir_context ctx;
1751 struct osd_thread_info *oifb_info;
1752 struct osd_device *oifb_dev;
1753 struct dentry *oifb_dentry;
1758 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1759 scandir_t scandir, filldir_t filldir)
1761 struct osd_ios_item *item;
1764 OBD_ALLOC_PTR(item);
1768 INIT_LIST_HEAD(&item->oii_list);
1769 item->oii_dentry = dget(dentry);
1770 item->oii_scandir = scandir;
1771 item->oii_filldir = filldir;
1772 list_add_tail(&item->oii_list, &dev->od_ios_list);
1777 static bool osd_index_need_recreate(const struct lu_env *env,
1778 struct osd_device *dev, struct inode *inode)
1780 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1781 struct iam_container *bag = &iam->od_container;
1785 rc = iam_container_init(bag, &iam->od_descr, inode);
1789 rc = iam_container_setup(bag);
1790 iam_container_fini(bag);
1797 static void osd_ios_index_register(const struct lu_env *env,
1798 struct osd_device *osd,
1799 const struct lu_fid *fid,
1800 struct inode *inode)
1802 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1803 struct iam_container *bag = &iam->od_container;
1804 struct super_block *sb = osd_sb(osd);
1805 struct iam_descr *descr;
1811 /* Index must be a regular file. */
1812 if (!S_ISREG(inode->i_mode))
1815 /* Index's size must be block aligned. */
1816 if (inode->i_size < sb->s_blocksize ||
1817 (inode->i_size & (sb->s_blocksize - 1)) != 0)
1820 iam_container_init(bag, &iam->od_descr, inode);
1821 rc = iam_container_setup(bag);
1825 descr = bag->ic_descr;
1826 /* May be regular file with IAM_LFIX_ROOT_MAGIC matched
1827 * coincidentally, or corrupted index object, skip it. */
1828 if (descr->id_ptr_size != 4)
1831 keysize = descr->id_key_size;
1832 recsize = descr->id_rec_size;
1833 rc = osd_index_register(osd, fid, keysize, recsize);
1838 iam_container_fini(bag);
1840 CDEBUG(D_LFSCK, "%s: index object "DFID" (%u/%u) registered\n",
1841 osd_name(osd), PFID(fid), keysize, recsize);
1844 static void osd_index_restore(const struct lu_env *env, struct osd_device *dev,
1845 struct lustre_index_restore_unit *liru,
1846 void *buf, int bufsize)
1848 struct osd_thread_info *info = osd_oti_get(env);
1849 struct osd_inode_id *id = &info->oti_id;
1850 struct lu_fid *tgt_fid = &liru->liru_cfid;
1851 struct inode *bak_inode = NULL;
1852 struct ldiskfs_dir_entry_2 *de = NULL;
1853 struct buffer_head *bh = NULL;
1854 struct dentry *dentry;
1856 struct lu_fid bak_fid;
1860 lustre_fid2lbx(name, tgt_fid, bufsize);
1861 dentry = osd_child_dentry_by_inode(env, dev->od_index_backup_inode,
1862 name, strlen(name));
1863 bh = osd_ldiskfs_find_entry(dev->od_index_backup_inode,
1864 &dentry->d_name, &de, NULL, NULL);
1866 GOTO(log, rc = PTR_ERR(bh));
1868 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
1870 bak_inode = osd_iget_fid(info, dev, id, &bak_fid);
1871 if (IS_ERR(bak_inode))
1872 GOTO(log, rc = PTR_ERR(bak_inode));
1875 /* The OI mapping for index may be invalid, since it will be
1876 * re-created, not update the OI mapping, just cache it in RAM. */
1877 osd_id_gen(id, liru->liru_clid, OSD_OII_NOGEN);
1878 osd_add_oi_cache(info, dev, id, tgt_fid);
1879 rc = lustre_index_restore(env, &dev->od_dt_dev, &liru->liru_pfid,
1880 tgt_fid, &bak_fid, liru->liru_name,
1881 &dev->od_index_backup_list, &dev->od_lock,
1886 CDEBUG(D_WARNING, "%s: restore index '%s' with "DFID": rc = %d\n",
1887 osd_name(dev), liru->liru_name, PFID(tgt_fid), rc);
1891 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1893 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1894 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1895 * reference the inode, or fixed if it is missing or references another inode.
1898 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1899 struct inode *parent, struct inode *inode,
1900 const struct lu_fid *fid, const char *name,
1901 int namelen, int flags)
1903 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1904 struct osd_inode_id *id = &info->oti_id;
1905 struct osd_inode_id *id2 = &info->oti_id2;
1906 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1907 struct scrub_file *sf = &scrub->os_file;
1913 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode: rc = -2\n",
1914 osd_name(dev), namelen, name);
1918 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
1919 &info->oti_ost_attrs);
1920 if (rc != 0 && rc != -ENODATA) {
1921 CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
1922 "rc = %d\n", osd_name(dev), rc);
1927 osd_id_gen(id, inode->i_ino, inode->i_generation);
1928 if (rc == -ENODATA) {
1929 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID) {
1930 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1933 if (flags & OLF_IDX_IN_FID) {
1934 LASSERT(dev->od_index >= 0);
1936 tfid.f_oid = dev->od_index;
1939 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1941 CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
1942 "scrub: rc = %d\n", osd_name(dev), rc);
1947 if (lma->lma_compat & LMAC_NOT_IN_OI)
1950 tfid = lma->lma_self_fid;
1951 if (lma->lma_compat & LMAC_IDX_BACKUP &&
1952 osd_index_need_recreate(info->oti_env, dev, inode)) {
1953 struct lu_fid *pfid = &info->oti_fid3;
1955 if (is_root_inode(parent)) {
1956 lu_local_obj_fid(pfid, OSD_FS_ROOT_OID);
1958 rc = osd_scrub_get_fid(info, dev, parent, pfid,
1964 rc = lustre_liru_new(&dev->od_index_restore_list, pfid,
1965 &tfid, inode->i_ino, name, namelen);
1970 if (!(flags & OLF_NOT_BACKUP))
1971 osd_ios_index_register(info->oti_env, dev, &tfid,
1975 /* Since this called from iterate_dir() the inode lock will be taken */
1976 rc = osd_oi_lookup(info, dev, &tfid, id2, OI_LOCKED);
1981 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1982 DTO_INDEX_INSERT, true, 0, NULL);
1989 if (osd_id_eq_strict(id, id2))
1992 if (!(sf->sf_flags & SF_INCONSISTENT)) {
1993 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
1994 rc = scrub_file_store(info->oti_env, scrub);
1999 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
2000 DTO_INDEX_UPDATE, true, 0, NULL);
2008 * It scans the /lost+found, and for the OST-object (with filter_fid
2009 * or filter_fid_18_23), move them back to its proper /O/<seq>/d<x>.
2011 #ifdef HAVE_FILLDIR_USE_CTX
2012 static int osd_ios_lf_fill(struct dir_context *buf,
2014 static int osd_ios_lf_fill(void *buf,
2016 const char *name, int namelen,
2017 loff_t offset, __u64 ino, unsigned d_type)
2019 struct osd_ios_filldir_buf *fill_buf =
2020 (struct osd_ios_filldir_buf *)buf;
2021 struct osd_thread_info *info = fill_buf->oifb_info;
2022 struct osd_device *dev = fill_buf->oifb_dev;
2023 struct lu_fid *fid = &info->oti_fid;
2024 struct osd_scrub *scrub = &dev->od_scrub;
2025 struct dentry *parent = fill_buf->oifb_dentry;
2026 struct dentry *child;
2027 struct inode *dir = parent->d_inode;
2028 struct inode *inode;
2032 fill_buf->oifb_items++;
2034 /* skip any '.' started names */
2038 scrub->os_lf_scanned++;
2039 child = osd_lookup_one_len(dev, name, parent, namelen);
2040 if (IS_ERR(child)) {
2041 rc = PTR_ERR(child);
2042 CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
2043 osd_name(dev), namelen, name, rc);
2045 } else if (!child->d_inode) {
2047 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode\n",
2048 osd_name(dev), namelen, name);
2052 inode = child->d_inode;
2053 if (S_ISDIR(inode->i_mode)) {
2054 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2057 CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
2058 "rc = %d\n", osd_name(dev), namelen, name, rc);
2062 if (!S_ISREG(inode->i_mode))
2065 rc = osd_scrub_get_fid(info, dev, inode, fid, true);
2066 if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
2067 rc = osd_obj_map_recover(info, dev, dir, child, fid);
2069 CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
2070 "/lost+found.\n", namelen, name, PFID(fid));
2071 scrub->os_lf_repaired++;
2073 CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
2075 osd_name(dev), namelen, name, PFID(fid), rc);
2079 /* XXX: For MDT-objects, we can move them from /lost+found to namespace
2080 * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
2081 * can process them in furtuer. */
2087 scrub->os_lf_failed++;
2089 /* skip the failure to make the scanning to continue. */
2093 #ifdef HAVE_FILLDIR_USE_CTX
2094 static int osd_ios_varfid_fill(struct dir_context *buf,
2096 static int osd_ios_varfid_fill(void *buf,
2098 const char *name, int namelen,
2099 loff_t offset, __u64 ino, unsigned d_type)
2101 struct osd_ios_filldir_buf *fill_buf =
2102 (struct osd_ios_filldir_buf *)buf;
2103 struct osd_device *dev = fill_buf->oifb_dev;
2104 struct dentry *child;
2108 fill_buf->oifb_items++;
2110 /* skip any '.' started names */
2114 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2116 RETURN(PTR_ERR(child));
2118 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2119 fill_buf->oifb_dentry->d_inode, child->d_inode,
2120 NULL, name, namelen, 0);
2121 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
2122 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2123 osd_ios_varfid_fill);
2129 #ifdef HAVE_FILLDIR_USE_CTX
2130 static int osd_ios_dl_fill(struct dir_context *buf,
2132 static int osd_ios_dl_fill(void *buf,
2134 const char *name, int namelen,
2135 loff_t offset, __u64 ino, unsigned d_type)
2137 struct osd_ios_filldir_buf *fill_buf =
2138 (struct osd_ios_filldir_buf *)buf;
2139 struct osd_device *dev = fill_buf->oifb_dev;
2140 const struct osd_lf_map *map;
2141 struct dentry *child;
2145 fill_buf->oifb_items++;
2147 /* skip any '.' started names */
2151 for (map = osd_dl_maps; map->olm_name != NULL; map++) {
2152 if (map->olm_namelen != namelen)
2155 if (strncmp(map->olm_name, name, namelen) == 0)
2159 if (map->olm_name == NULL)
2162 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2164 RETURN(PTR_ERR(child));
2166 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2167 fill_buf->oifb_dentry->d_inode, child->d_inode,
2168 &map->olm_fid, name, namelen, map->olm_flags);
2174 #ifdef HAVE_FILLDIR_USE_CTX
2175 static int osd_ios_uld_fill(struct dir_context *buf,
2177 static int osd_ios_uld_fill(void *buf,
2179 const char *name, int namelen,
2180 loff_t offset, __u64 ino, unsigned d_type)
2182 struct osd_ios_filldir_buf *fill_buf =
2183 (struct osd_ios_filldir_buf *)buf;
2184 struct osd_device *dev = fill_buf->oifb_dev;
2185 struct dentry *child;
2190 fill_buf->oifb_items++;
2192 /* skip any non-DFID format name */
2196 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2198 RETURN(PTR_ERR(child));
2200 /* skip the start '[' */
2201 sscanf(&name[1], SFID, RFID(&tfid));
2202 if (fid_is_sane(&tfid))
2203 rc = osd_ios_scan_one(fill_buf->oifb_info, fill_buf->oifb_dev,
2204 fill_buf->oifb_dentry->d_inode,
2205 child->d_inode, &tfid, name, namelen, 0);
2213 #ifdef HAVE_FILLDIR_USE_CTX
2214 static int osd_ios_root_fill(struct dir_context *buf,
2216 static int osd_ios_root_fill(void *buf,
2218 const char *name, int namelen,
2219 loff_t offset, __u64 ino, unsigned d_type)
2221 struct osd_ios_filldir_buf *fill_buf =
2222 (struct osd_ios_filldir_buf *)buf;
2223 struct osd_device *dev = fill_buf->oifb_dev;
2224 const struct osd_lf_map *map;
2225 struct dentry *child;
2229 fill_buf->oifb_items++;
2231 /* skip any '.' started names */
2235 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
2236 if (map->olm_namelen != namelen)
2239 if (strncmp(map->olm_name, name, namelen) == 0)
2243 if (map->olm_name == NULL)
2246 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2248 RETURN(PTR_ERR(child));
2249 else if (!child->d_inode)
2250 GOTO(out_put, rc = -ENOENT);
2252 if (!(map->olm_flags & OLF_NO_OI))
2253 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2254 fill_buf->oifb_dentry->d_inode, child->d_inode,
2255 &map->olm_fid, name, namelen, map->olm_flags);
2256 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
2257 rc = osd_ios_new_item(dev, child, map->olm_scandir,
2266 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
2267 struct dentry *dentry, filldir_t filldir)
2269 struct osd_ios_filldir_buf buf = {
2270 .ctx.actor = filldir,
2273 .oifb_dentry = dentry
2281 path.dentry = dget(dentry);
2282 path.mnt = mntget(dev->od_mnt);
2284 filp = dentry_open(&path, O_RDONLY, current_cred());
2287 RETURN(PTR_ERR(filp));
2289 filp->f_mode |= FMODE_64BITHASH | FMODE_NONOTIFY;
2290 filp->f_flags |= O_NOATIME;
2295 rc = iterate_dir(filp, &buf.ctx);
2296 } while (rc >= 0 && buf.oifb_items > 0 &&
2297 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
2304 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
2305 struct dentry *dentry, filldir_t filldir)
2307 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2308 struct scrub_file *sf = &scrub->os_file;
2309 struct dentry *child;
2313 /* It is existing MDT0 device. We only allow the case of object without
2314 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
2315 * can generate IGIF mode FID for the object and related OI mapping. If
2316 * it is on other MDTs, then becuase file-level backup/restore, related
2317 * OI mapping may be invalid already, we do not know which is the right
2318 * FID for the object. We only allow IGIF objects to reside on the MDT0.
2320 * XXX: For the case of object on non-MDT0 device with neither LMA nor
2321 * "fid" xattr, then something crashed. We cannot re-generate the
2322 * FID directly, instead, the OI scrub will scan the OI structure
2323 * and try to re-generate the LMA from the OI mapping. But if the
2324 * OI mapping crashed or lost also, then we have to give up under
2325 * double failure cases.
2327 spin_lock(&scrub->os_lock);
2328 scrub->os_convert_igif = 1;
2329 spin_unlock(&scrub->os_lock);
2330 child = osd_lookup_one_len_unlocked(dev, dot_lustre_name, dentry,
2331 strlen(dot_lustre_name));
2332 if (IS_ERR(child)) {
2333 if (PTR_ERR(child) != -ENOENT)
2334 RETURN(PTR_ERR(child));
2338 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
2339 * so the client will get IGIF for the ".lustre" object when
2342 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
2343 * it does not know whether there are some old clients cached
2344 * the ".lustre" IGIF during the upgrading. Two choices:
2346 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
2347 * It will allow the old connected clients to access the
2348 * ".lustre" with cached IGIF. But it will cause others
2349 * on the MDT failed to check "fid_is_dot_lustre()".
2351 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
2352 * for ".lustre" in spite of whether there are some clients
2353 * cached the ".lustre" IGIF or not. It enables the check
2354 * "fid_is_dot_lustre()" on the MDT, although it will cause
2355 * that the old connected clients cannot access the ".lustre"
2356 * with the cached IGIF.
2358 * Usually, it is rare case for the old connected clients
2359 * to access the ".lustre" with cached IGIF. So we prefer
2360 * to the solution 2).
2362 inode_lock(dentry->d_inode);
2363 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2364 child->d_inode, &LU_DOT_LUSTRE_FID,
2366 strlen(dot_lustre_name), 0);
2367 inode_unlock(dentry->d_inode);
2368 if (rc == -ENOENT) {
2370 /* It is 1.8 MDT device. */
2371 if (!(sf->sf_flags & SF_UPGRADE)) {
2372 scrub_file_reset(scrub, dev->od_uuid,
2374 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2375 rc = scrub_file_store(info->oti_env, scrub);
2379 } else if (rc == 0) {
2380 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2389 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
2390 struct dentry *dentry, filldir_t filldir)
2392 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2393 struct scrub_file *sf = &scrub->os_file;
2394 struct dentry *child;
2398 if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
2399 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2400 rc = scrub_file_store(info->oti_env, scrub);
2405 child = osd_lookup_one_len_unlocked(dev, ADMIN_USR, dentry,
2407 if (IS_ERR(child)) {
2408 rc = PTR_ERR(child);
2410 inode_lock(dentry->d_inode);
2411 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2412 child->d_inode, NULL, ADMIN_USR,
2413 strlen(ADMIN_USR), 0);
2414 inode_unlock(dentry->d_inode);
2418 if (rc != 0 && rc != -ENOENT)
2421 child = osd_lookup_one_len_unlocked(dev, ADMIN_GRP, dentry,
2424 GOTO(out, rc = PTR_ERR(child));
2426 inode_lock(dentry->d_inode);
2427 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2428 child->d_inode, NULL, ADMIN_GRP,
2429 strlen(ADMIN_GRP), 0);
2430 inode_unlock(dentry->d_inode);
2433 RETURN(rc == -ENOENT ? 0 : rc);
2436 static void osd_initial_OI_scrub(struct osd_thread_info *info,
2437 struct osd_device *dev)
2439 struct osd_ios_item *item = NULL;
2440 scandir_t scandir = osd_ios_general_scan;
2441 filldir_t filldir = osd_ios_root_fill;
2442 struct dentry *dentry = osd_sb(dev)->s_root;
2443 const struct osd_lf_map *map = osd_lf_maps;
2446 /* Lookup IGIF in OI by force for initial OI scrub. */
2447 dev->od_igif_inoi = 1;
2450 /* Don't take inode_lock here since scandir() callbacks
2451 * can call VFS functions which may manully take the
2452 * inode lock itself like iterate_dir(). Since this
2453 * is the case it is best to leave the scandir()
2454 * callbacks to managing the inode lock.
2456 scandir(info, dev, dentry, filldir);
2458 dput(item->oii_dentry);
2462 if (list_empty(&dev->od_ios_list))
2465 item = list_entry(dev->od_ios_list.next,
2466 struct osd_ios_item, oii_list);
2467 list_del_init(&item->oii_list);
2469 LASSERT(item->oii_scandir != NULL);
2470 scandir = item->oii_scandir;
2471 filldir = item->oii_filldir;
2472 dentry = item->oii_dentry;
2475 /* There maybe the case that the object has been removed, but its OI
2476 * mapping is still in the OI file, such as the "CATALOGS" after MDT
2477 * file-level backup/restore. So here cleanup the stale OI mappings. */
2478 while (map->olm_name != NULL) {
2479 struct dentry *child;
2481 if (fid_is_zero(&map->olm_fid)) {
2486 child = osd_lookup_one_len_unlocked(dev, map->olm_name,
2487 osd_sb(dev)->s_root,
2489 if (PTR_ERR(child) == -ENOENT ||
2490 (!IS_ERR(child) && !child->d_inode))
2491 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
2492 NULL, DTO_INDEX_DELETE,
2499 if (!list_empty(&dev->od_index_restore_list)) {
2502 OBD_ALLOC_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2504 CERROR("%s: not enough RAM for rebuild index\n",
2507 while (!list_empty(&dev->od_index_restore_list)) {
2508 struct lustre_index_restore_unit *liru;
2510 liru = list_entry(dev->od_index_restore_list.next,
2511 struct lustre_index_restore_unit,
2513 list_del(&liru->liru_link);
2515 osd_index_restore(info->oti_env, dev, liru,
2516 buf, INDEX_BACKUP_BUFSIZE);
2517 OBD_FREE(liru, liru->liru_len);
2521 OBD_FREE_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2527 char *osd_lf_fid2name(const struct lu_fid *fid)
2529 const struct osd_lf_map *map = osd_lf_maps;
2531 while (map->olm_name != NULL) {
2532 if (!lu_fid_eq(fid, &map->olm_fid)) {
2537 if (map->olm_flags & OLF_SHOW_NAME)
2538 return map->olm_name;
2546 /* OI scrub start/stop */
2548 int osd_scrub_start(const struct lu_env *env, struct osd_device *dev,
2551 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2555 if (dev->od_dt_dev.dd_rdonly)
2558 /* od_otable_mutex: prevent curcurrent start/stop */
2559 mutex_lock(&dev->od_otable_mutex);
2560 rc = scrub_start(osd_scrub_main, scrub, dev, flags);
2561 if (rc == -EALREADY) {
2563 if ((scrub->os_file.sf_flags & SF_AUTO ||
2564 scrub->os_partial_scan) &&
2565 !(flags & SS_AUTO_PARTIAL))
2566 osd_scrub_join(env, dev, flags, false);
2568 mutex_unlock(&dev->od_otable_mutex);
2573 void osd_scrub_stop(struct osd_device *dev)
2575 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2577 /* od_otable_mutex: prevent curcurrent start/stop */
2578 mutex_lock(&dev->od_otable_mutex);
2579 spin_lock(&scrub->os_lock);
2580 scrub->os_paused = 1;
2581 spin_unlock(&scrub->os_lock);
2583 mutex_unlock(&dev->od_otable_mutex);
2585 osd_scrub_ois_fini(scrub, &scrub->os_inconsistent_items);
2586 osd_scrub_ois_fini(scrub, &scrub->os_stale_items);
2589 /* OI scrub setup/cleanup */
2591 static const char osd_scrub_name[] = "OI_scrub";
2593 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev,
2596 struct osd_thread_info *info = osd_oti_get(env);
2597 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2598 struct lvfs_run_ctxt *ctxt = &dev->od_scrub.os_ctxt;
2599 time64_t interval = scrub->os_auto_scrub_interval;
2600 struct scrub_file *sf = &scrub->os_file;
2601 struct super_block *sb = osd_sb(dev);
2602 struct lvfs_run_ctxt saved;
2604 struct inode *inode;
2605 struct lu_fid *fid = &info->oti_fid;
2606 struct osd_inode_id *id = &info->oti_id;
2607 struct dt_object *obj;
2612 memset(&dev->od_scrub, 0, sizeof(struct osd_scrub));
2613 OBD_SET_CTXT_MAGIC(ctxt);
2614 ctxt->pwdmnt = dev->od_mnt;
2615 ctxt->pwd = dev->od_mnt->mnt_root;
2617 init_rwsem(&scrub->os_rwsem);
2618 spin_lock_init(&scrub->os_lock);
2619 INIT_LIST_HEAD(&scrub->os_inconsistent_items);
2620 INIT_LIST_HEAD(&scrub->os_stale_items);
2621 scrub->os_name = osd_name(dev);
2622 scrub->os_auto_scrub_interval = interval;
2624 push_ctxt(&saved, ctxt);
2625 filp = filp_open(osd_scrub_name, O_RDWR |
2626 (dev->od_dt_dev.dd_rdonly ? 0 : O_CREAT), 0644);
2628 pop_ctxt(&saved, ctxt);
2629 RETURN(PTR_ERR(filp));
2632 inode = file_inode(filp);
2633 ldiskfs_set_inode_flag(inode, LDISKFS_INODE_JOURNAL_DATA);
2634 if (!dev->od_dt_dev.dd_rdonly) {
2635 /* 'What the @fid is' is not imporatant, because the object
2636 * has no OI mapping, and only is visible inside the OSD.*/
2637 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2638 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
2640 filp_close(filp, NULL);
2641 pop_ctxt(&saved, ctxt);
2646 osd_id_gen(id, inode->i_ino, inode->i_generation);
2647 osd_add_oi_cache(info, dev, id, fid);
2648 filp_close(filp, NULL);
2649 pop_ctxt(&saved, ctxt);
2651 obj = lu2dt(lu_object_find_slice(env, osd2lu_dev(dev), fid, NULL));
2652 if (IS_ERR_OR_NULL(obj))
2653 RETURN(obj ? PTR_ERR(obj) : -ENOENT);
2655 #ifndef HAVE_S_UUID_AS_UUID_T
2656 memcpy(dev->od_uuid.b, sb->s_uuid, sizeof(dev->od_uuid));
2658 uuid_copy(&dev->od_uuid, &sb->s_uuid);
2660 scrub->os_obj = obj;
2661 rc = scrub_file_load(env, scrub);
2662 if (rc == -ENOENT || rc == -EFAULT) {
2663 scrub_file_init(scrub, dev->od_uuid);
2664 /* If the "/O" dir does not exist when mount (indicated by
2665 * osd_device::od_maybe_new), neither for the "/OI_scrub",
2666 * then it is quite probably that the device is a new one,
2667 * under such case, mark it as SIF_NO_HANDLE_OLD_FID.
2669 * For the rare case that "/O" and "OI_scrub" both lost on
2670 * an old device, it can be found and cleared later.
2672 * For the system with "SIF_NO_HANDLE_OLD_FID", we do not
2673 * need to check "filter_fid_18_23" and to convert it to
2674 * "filter_fid" for each object, and all the IGIF should
2675 * have their FID mapping in OI files already. */
2676 if (dev->od_maybe_new && rc == -ENOENT)
2677 sf->sf_internal_flags = SIF_NO_HANDLE_OLD_FID;
2679 } else if (rc < 0) {
2680 GOTO(cleanup_obj, rc);
2682 if (!uuid_equal(&sf->sf_uuid, &dev->od_uuid)) {
2684 "%s: UUID has been changed from %pU to %pU\n",
2685 osd_dev2name(dev), &sf->sf_uuid, &dev->od_uuid);
2686 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
2689 } else if (sf->sf_status == SS_SCANNING) {
2690 sf->sf_status = SS_CRASHED;
2694 if ((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) {
2695 LCONSOLE_WARN("%s: invalid oi count %d, set it to %d\n",
2696 osd_dev2name(dev), sf->sf_oi_count,
2698 sf->sf_oi_count = osd_oi_count;
2703 if (sf->sf_pos_last_checkpoint != 0)
2704 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
2706 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
2709 rc = scrub_file_store(env, scrub);
2711 GOTO(cleanup_obj, rc);
2714 /* Initialize OI files. */
2715 rc = osd_oi_init(info, dev, restored);
2717 GOTO(cleanup_obj, rc);
2719 if (!dev->od_dt_dev.dd_rdonly)
2720 osd_initial_OI_scrub(info, dev);
2722 if (sf->sf_flags & SF_UPGRADE ||
2723 !(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID ||
2724 sf->sf_success_count > 0)) {
2725 dev->od_igif_inoi = 0;
2726 dev->od_check_ff = dev->od_is_ost;
2728 dev->od_igif_inoi = 1;
2729 dev->od_check_ff = 0;
2732 if (sf->sf_flags & SF_INCONSISTENT)
2733 /* The 'od_igif_inoi' will be set under the
2735 * 1) new created system, or
2736 * 2) restored from file-level backup, or
2737 * 3) the upgrading completed.
2739 * The 'od_igif_inoi' may be cleared by OI scrub
2740 * later if found that the system is upgrading. */
2741 dev->od_igif_inoi = 1;
2743 if (!dev->od_dt_dev.dd_rdonly &&
2744 dev->od_scrub.os_scrub.os_auto_scrub_interval != AS_NEVER &&
2745 ((sf->sf_status == SS_PAUSED) ||
2746 (sf->sf_status == SS_CRASHED &&
2747 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2748 SF_UPGRADE | SF_AUTO)) ||
2749 (sf->sf_status == SS_INIT &&
2750 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2752 rc = osd_scrub_start(env, dev, SS_AUTO_FULL);
2755 GOTO(cleanup_oi, rc);
2757 /* it is possible that dcache entries may keep objects after they are
2758 * deleted by OSD. While it looks safe this can cause object data to
2759 * stay until umount causing failures in tests calculating free space,
2760 * e.g. replay-ost-single. Since those dcache entries are not used
2761 * anymore let's just free them after use here */
2762 shrink_dcache_sb(sb);
2766 osd_oi_fini(info, dev);
2768 dt_object_put_nocache(env, scrub->os_obj);
2769 scrub->os_obj = NULL;
2774 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
2776 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2778 LASSERT(dev->od_otable_it == NULL);
2780 if (scrub->os_obj != NULL) {
2781 osd_scrub_stop(dev);
2782 dt_object_put_nocache(env, scrub->os_obj);
2783 scrub->os_obj = NULL;
2787 /* object table based iteration APIs */
2789 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
2790 struct dt_object *dt, __u32 attr)
2792 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
2793 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
2794 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
2795 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2796 struct osd_otable_it *it;
2801 /* od_otable_mutex: prevent curcurrent init/fini */
2802 mutex_lock(&dev->od_otable_mutex);
2803 if (dev->od_otable_it != NULL)
2804 GOTO(out, it = ERR_PTR(-EALREADY));
2808 GOTO(out, it = ERR_PTR(-ENOMEM));
2810 dev->od_otable_it = it;
2812 it->ooi_cache.ooc_consumer_idx = -1;
2813 if (flags & DOIF_OUTUSED)
2814 it->ooi_used_outside = 1;
2816 if (flags & DOIF_RESET)
2819 if (valid & DOIV_ERROR_HANDLE) {
2820 if (flags & DOIF_FAILOUT)
2821 start |= SS_SET_FAILOUT;
2823 start |= SS_CLEAR_FAILOUT;
2826 if (valid & DOIV_DRYRUN) {
2827 if (flags & DOIF_DRYRUN)
2828 start |= SS_SET_DRYRUN;
2830 start |= SS_CLEAR_DRYRUN;
2833 rc = scrub_start(osd_scrub_main, scrub, dev, start & ~SS_AUTO_PARTIAL);
2834 if (rc == -EALREADY) {
2835 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2836 } else if (rc < 0) {
2837 dev->od_otable_it = NULL;
2841 /* We have to start from the begining. */
2842 it->ooi_cache.ooc_pos_preload =
2843 LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2849 mutex_unlock(&dev->od_otable_mutex);
2850 return (struct dt_it *)it;
2853 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2855 struct osd_otable_it *it = (struct osd_otable_it *)di;
2856 struct osd_device *dev = it->ooi_dev;
2858 /* od_otable_mutex: prevent curcurrent init/fini */
2859 mutex_lock(&dev->od_otable_mutex);
2860 scrub_stop(&dev->od_scrub.os_scrub);
2861 LASSERT(dev->od_otable_it == it);
2863 dev->od_otable_it = NULL;
2864 mutex_unlock(&dev->od_otable_mutex);
2868 static int osd_otable_it_get(const struct lu_env *env,
2869 struct dt_it *di, const struct dt_key *key)
2874 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2879 osd_otable_it_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
2881 spin_lock(&scrub->os_lock);
2882 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2883 scrub->os_waiting || !scrub->os_running)
2884 it->ooi_waiting = 0;
2886 it->ooi_waiting = 1;
2887 spin_unlock(&scrub->os_lock);
2889 return !it->ooi_waiting;
2892 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2894 struct osd_otable_it *it = (struct osd_otable_it *)di;
2895 struct osd_device *dev = it->ooi_dev;
2896 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2897 struct osd_otable_cache *ooc = &it->ooi_cache;
2901 LASSERT(it->ooi_user_ready);
2904 if (!scrub->os_running && !it->ooi_used_outside)
2907 if (ooc->ooc_cached_items > 0) {
2908 ooc->ooc_cached_items--;
2909 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2910 ~OSD_OTABLE_IT_CACHE_MASK;
2914 if (it->ooi_all_cached) {
2915 wait_var_event(scrub, !scrub->os_running);
2919 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2920 spin_lock(&scrub->os_lock);
2921 scrub->os_waiting = 0;
2923 spin_unlock(&scrub->os_lock);
2926 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2927 wait_var_event(scrub, osd_otable_it_wakeup(scrub, it));
2929 if (!scrub->os_running && !it->ooi_used_outside)
2932 rc = osd_otable_it_preload(env, it);
2939 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2940 const struct dt_it *di)
2945 static int osd_otable_it_key_size(const struct lu_env *env,
2946 const struct dt_it *di)
2948 return sizeof(__u64);
2951 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2952 struct dt_rec *rec, __u32 attr)
2954 struct osd_otable_it *it = (struct osd_otable_it *)di;
2955 struct osd_otable_cache *ooc = &it->ooi_cache;
2957 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2959 /* Filter out Invald FID already. */
2960 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2961 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2962 PFID((struct lu_fid *)rec),
2963 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2968 static __u64 osd_otable_it_store(const struct lu_env *env,
2969 const struct dt_it *di)
2971 struct osd_otable_it *it = (struct osd_otable_it *)di;
2972 struct osd_otable_cache *ooc = &it->ooi_cache;
2975 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2976 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2978 hash = ooc->ooc_pos_preload;
2983 * Set the OSD layer iteration start position as the specified hash.
2985 static int osd_otable_it_load(const struct lu_env *env,
2986 const struct dt_it *di, __u64 hash)
2988 struct osd_otable_it *it = (struct osd_otable_it *)di;
2989 struct osd_device *dev = it->ooi_dev;
2990 struct osd_otable_cache *ooc = &it->ooi_cache;
2991 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2992 struct osd_iit_param *param = &it->ooi_iit_param;
2996 /* Forbid to set iteration position after iteration started. */
2997 if (it->ooi_user_ready)
3000 LASSERT(!scrub->os_partial_scan);
3002 if (hash > OSD_OTABLE_MAX_HASH)
3003 hash = OSD_OTABLE_MAX_HASH;
3005 /* The hash is the last checkpoint position,
3006 * we will start from the next one. */
3007 ooc->ooc_pos_preload = hash + 1;
3008 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
3009 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
3011 it->ooi_user_ready = 1;
3012 if (!scrub->os_full_speed)
3015 memset(param, 0, sizeof(*param));
3016 param->sb = osd_sb(dev);
3017 param->start = ooc->ooc_pos_preload;
3018 param->bg = (ooc->ooc_pos_preload - 1) /
3019 LDISKFS_INODES_PER_GROUP(param->sb);
3020 param->offset = (ooc->ooc_pos_preload - 1) %
3021 LDISKFS_INODES_PER_GROUP(param->sb);
3022 param->gbase = 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
3024 /* Unplug OSD layer iteration by the first next() call. */
3025 rc = osd_otable_it_next(env, (struct dt_it *)it);
3030 static int osd_otable_it_key_rec(const struct lu_env *env,
3031 const struct dt_it *di, void *key_rec)
3036 const struct dt_index_operations osd_otable_ops = {
3038 .init = osd_otable_it_init,
3039 .fini = osd_otable_it_fini,
3040 .get = osd_otable_it_get,
3041 .put = osd_otable_it_put,
3042 .next = osd_otable_it_next,
3043 .key = osd_otable_it_key,
3044 .key_size = osd_otable_it_key_size,
3045 .rec = osd_otable_it_rec,
3046 .store = osd_otable_it_store,
3047 .load = osd_otable_it_load,
3048 .key_rec = osd_otable_it_key_rec,
3052 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
3054 struct osd_scrub *scrub = &dev->od_scrub;
3056 scrub_dump(m, &scrub->os_scrub);
3057 seq_printf(m, "lf_scanned: %llu\n"
3059 "lf_failed: %llu\n",
3060 scrub->os_lf_scanned,
3061 scrub->os_scrub.os_file.sf_param & SP_DRYRUN ?
3062 "inconsistent" : "repaired",
3063 scrub->os_lf_repaired,
3064 scrub->os_lf_failed);
3067 typedef int (*scan_dir_helper_t)(const struct lu_env *env,
3068 struct osd_device *dev, struct inode *dir,
3069 struct osd_it_ea *oie);
3071 static int osd_scan_dir(const struct lu_env *env, struct osd_device *dev,
3072 struct inode *inode, scan_dir_helper_t cb)
3074 struct osd_it_ea *oie;
3079 oie = osd_it_dir_init(env, dev, inode, LUDA_TYPE);
3081 RETURN(PTR_ERR(oie));
3083 oie->oie_file->f_pos = 0;
3084 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3090 while (oie->oie_it_dirent <= oie->oie_rd_dirent) {
3091 if (!name_is_dot_or_dotdot(oie->oie_dirent->oied_name,
3092 oie->oie_dirent->oied_namelen))
3093 cb(env, dev, inode, oie);
3095 oie->oie_dirent = (void *)oie->oie_dirent +
3096 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
3097 oie->oie_dirent->oied_namelen);
3099 oie->oie_it_dirent++;
3100 if (oie->oie_it_dirent <= oie->oie_rd_dirent)
3103 if (oie->oie_file->f_pos ==
3104 ldiskfs_get_htree_eof(oie->oie_file))
3107 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3116 osd_it_dir_fini(env, oie, inode);
3120 static int osd_remove_ml_file(struct osd_thread_info *info,
3121 struct osd_device *dev, struct inode *dir,
3122 struct inode *inode, struct osd_it_ea *oie)
3125 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3126 struct dentry dentry;
3131 if (scrub->os_file.sf_param & SP_DRYRUN)
3134 th = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
3135 osd_dto_credits_noquota[DTO_INDEX_DELETE] +
3136 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
3138 RETURN(PTR_ERR(th));
3140 /* Should be created by the VFS layer */
3141 dentry.d_inode = dir;
3142 dentry.d_sb = dir->i_sb;
3143 rc = osd_obj_del_entry(info, dev, &dentry, oie->oie_dirent->oied_name,
3144 oie->oie_dirent->oied_namelen, th);
3146 mark_inode_dirty(inode);
3147 ldiskfs_journal_stop(th);
3151 static int osd_scan_ml_file(const struct lu_env *env, struct osd_device *dev,
3152 struct inode *dir, struct osd_it_ea *oie)
3154 struct osd_thread_info *info = osd_oti_get(env);
3155 struct osd_inode_id id;
3156 struct inode *inode;
3157 struct osd_obj_seq *oseq;
3158 struct ost_id *ostid = &info->oti_ostid;
3159 struct lu_fid *fid = &oie->oie_dirent->oied_fid;
3165 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3167 if (!fid_is_sane(fid))
3168 inode = osd_iget_fid(info, dev, &id, fid);
3170 inode = osd_iget(info, dev, &id);
3173 RETURN(PTR_ERR(inode));
3175 fid_to_ostid(fid, ostid);
3176 oseq = osd_seq_load(info, dev, ostid_seq(ostid));
3178 RETURN(PTR_ERR(oseq));
3180 dirn = ostid_id(ostid) & (oseq->oos_subdir_count - 1);
3181 LASSERT(oseq->oos_dirs[dirn] != NULL);
3183 osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
3184 if (((strlen(oseq->oos_root->d_name.name) !=
3185 info->oti_seq_dirent->oied_namelen) ||
3186 strncmp(oseq->oos_root->d_name.name,
3187 info->oti_seq_dirent->oied_name,
3188 info->oti_seq_dirent->oied_namelen) != 0) ||
3189 ((strlen(oseq->oos_dirs[dirn]->d_name.name) !=
3190 info->oti_dir_dirent->oied_namelen) ||
3191 strncmp(oseq->oos_dirs[dirn]->d_name.name,
3192 info->oti_dir_dirent->oied_name,
3193 info->oti_dir_dirent->oied_namelen) != 0) ||
3194 ((strlen(name) != oie->oie_dirent->oied_namelen) ||
3195 strncmp(oie->oie_dirent->oied_name, name,
3196 oie->oie_dirent->oied_namelen) != 0)) {
3197 CDEBUG(D_LFSCK, "%s: the file O/%s/%s/%s is corrupted\n",
3198 osd_name(dev), info->oti_seq_dirent->oied_name,
3199 info->oti_dir_dirent->oied_name,
3200 oie->oie_dirent->oied_name);
3202 rc = osd_remove_ml_file(info, dev, dir, inode, oie);
3209 static int osd_scan_ml_file_dir(const struct lu_env *env,
3210 struct osd_device *dev, struct inode *dir,
3211 struct osd_it_ea *oie)
3213 struct osd_thread_info *info = osd_oti_get(env);
3214 struct inode *inode;
3215 struct osd_inode_id id;
3220 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3221 inode = osd_iget(info, dev, &id);
3223 RETURN(PTR_ERR(inode));
3225 if (!S_ISDIR(inode->i_mode))
3228 info->oti_dir_dirent = oie->oie_dirent;
3229 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file);
3230 info->oti_dir_dirent = NULL;
3237 static int osd_scan_ml_file_seq(const struct lu_env *env,
3238 struct osd_device *dev, struct inode *dir,
3239 struct osd_it_ea *oie)
3241 struct osd_thread_info *info = osd_oti_get(env);
3242 struct inode *inode;
3243 struct osd_inode_id id;
3248 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3249 inode = osd_iget(info, dev, &id);
3251 RETURN(PTR_ERR(inode));
3253 if (!S_ISDIR(inode->i_mode))
3256 info->oti_seq_dirent = oie->oie_dirent;
3257 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file_dir);
3258 info->oti_seq_dirent = NULL;
3265 static int osd_scan_ml_file_main(const struct lu_env *env,
3266 struct osd_device *dev)
3268 return osd_scan_dir(env, dev, dev->od_ost_map->om_root->d_inode,
3269 osd_scan_ml_file_seq);