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 (CFS_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 || CFS_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 * OI records from request and current are the same
479 * checking inode generation at osd_iget()
482 inode = osd_iget(info, dev, lid);
484 ops = DTO_INDEX_DELETE;
487 if (converted && !IS_ERR(inode)) {
488 sf->sf_items_updated++;
492 if (!scrub->os_partial_scan) {
493 spin_lock(&scrub->os_lock);
494 scrub->os_full_speed = 1;
495 spin_unlock(&scrub->os_lock);
497 sf->sf_flags |= SF_INCONSISTENT;
499 /* XXX: If the device is restored from file-level backup, then
500 * some IGIFs may have been already in OI files, and some
501 * may be not yet. Means upgrading from 1.8 may be partly
502 * processed, but some clients may hold some immobilized
503 * IGIFs, and use them to access related objects. Under
504 * such case, OSD does not know whether an given IGIF has
505 * been processed or to be processed, and it also cannot
506 * generate local ino#/gen# directly from the immobilized
507 * IGIF because of the backup/restore. Then force OSD to
508 * lookup the given IGIF in OI files, and if no entry,
509 * then ask the client to retry after upgrading completed.
510 * No better choice. */
511 dev->od_igif_inoi = 1;
514 rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops, false,
515 (val == SCRUB_NEXT_OSTOBJ ||
516 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0,
519 if (scrub->os_in_prior)
520 sf->sf_items_updated_prior++;
522 sf->sf_items_updated++;
524 if (ops == DTO_INDEX_INSERT && val == 0 && !exist) {
525 int idx = osd_oi_fid2idx(dev, fid);
527 sf->sf_flags |= SF_RECREATED;
528 if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
529 ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
537 sf->sf_items_failed++;
538 if (sf->sf_pos_first_inconsistent == 0 ||
539 sf->sf_pos_first_inconsistent > lid->oii_ino)
540 sf->sf_pos_first_inconsistent = lid->oii_ino;
542 osd_scrub_oi_mark_stale(scrub, oii);
544 "%s: fix inconsistent OI "DFID" -> %u/%u failed: %d\n",
545 osd_dev2name(dev), PFID(fid), lid->oii_ino,
549 if (!oii && !CFS_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_STALE)) {
550 osd_scrub_oi_resurrect(scrub, fid);
552 "%s: resurrect OI "DFID" -> %u/%u\n",
553 osd_dev2name(dev), PFID(fid), lid->oii_ino,
556 /* release fixed inconsistent item */
558 "%s: inconsistent OI "DFID" -> %u/%u %s\n",
559 osd_dev2name(dev), PFID(fid), lid->oii_ino,
560 lid->oii_gen, ops == DTO_INDEX_DELETE ?
561 "deleted" : "fixed");
562 spin_lock(&scrub->os_lock);
563 list_del_init(&oii->oii_list);
564 spin_unlock(&scrub->os_lock);
571 /* There may be conflict unlink during the OI scrub,
572 * if happend, then remove the new added OI mapping. */
573 if (ops == DTO_INDEX_INSERT && !IS_ERR_OR_NULL(inode) &&
574 unlikely(ldiskfs_test_inode_state(inode,
575 LDISKFS_STATE_LUSTRE_DESTROY)))
576 osd_scrub_refresh_mapping(info, dev, fid, lid,
577 DTO_INDEX_DELETE, false,
578 (val == SCRUB_NEXT_OSTOBJ ||
579 val == SCRUB_NEXT_OSTOBJ_OLD) ?
580 OI_KNOWN_ON_OST : 0, NULL);
582 up_write(&scrub->os_rwsem);
584 if (!IS_ERR_OR_NULL(inode))
587 RETURN(sf->sf_param & SP_FAILOUT ? rc : 0);
590 /* iteration engine */
592 typedef int (*osd_iit_next_policy)(struct osd_thread_info *info,
593 struct osd_device *dev,
594 struct osd_iit_param *param,
595 struct osd_idmap_cache **oic,
598 typedef int (*osd_iit_exec_policy)(struct osd_thread_info *info,
599 struct osd_device *dev,
600 struct osd_iit_param *param,
601 struct osd_idmap_cache *oic,
602 bool *noslot, int rc);
604 static int osd_iit_next(struct osd_iit_param *param, __u64 *pos)
609 param->offset = ldiskfs_find_next_bit(param->bitmap->b_data,
610 LDISKFS_INODES_PER_GROUP(param->sb), param->offset);
611 if (param->offset >= LDISKFS_INODES_PER_GROUP(param->sb)) {
612 *pos = 1 + (param->bg+1) * LDISKFS_INODES_PER_GROUP(param->sb);
613 return SCRUB_NEXT_BREAK;
616 offset = param->offset++;
617 if (unlikely(*pos == param->gbase + offset && *pos != param->start)) {
618 /* We should NOT find the same object more than once. */
619 CERROR("%s: scan the same object multiple times at the pos: "
620 "group = %u, base = %u, offset = %u, start = %u\n",
621 osd_sb2name(param->sb), (__u32)param->bg, param->gbase,
622 offset, param->start);
626 *pos = param->gbase + offset;
631 * \retval SCRUB_NEXT_OSTOBJ_OLD: FID-on-OST
632 * \retval 0: FID-on-MDT
634 static int osd_scrub_check_local_fldb(struct osd_thread_info *info,
635 struct osd_device *dev,
638 /* XXX: The initial OI scrub will scan the top level /O to generate
639 * a small local FLDB according to the <seq>. If the given FID
640 * is in the local FLDB, then it is FID-on-OST; otherwise it's
641 * quite possible for FID-on-MDT. */
643 return SCRUB_NEXT_OSTOBJ_OLD;
648 static int osd_scrub_get_fid(struct osd_thread_info *info,
649 struct osd_device *dev, struct inode *inode,
650 struct lu_fid *fid, bool scrub)
652 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
653 bool has_lma = false;
656 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
657 &info->oti_ost_attrs);
660 if (lma->lma_compat & LMAC_NOT_IN_OI ||
661 lma->lma_incompat & LMAI_AGENT)
662 return SCRUB_NEXT_CONTINUE;
664 *fid = lma->lma_self_fid;
668 if (lma->lma_compat & LMAC_FID_ON_OST)
669 return SCRUB_NEXT_OSTOBJ;
671 if (fid_is_idif(fid))
672 return SCRUB_NEXT_OSTOBJ_OLD;
674 /* For local object. */
675 if (fid_is_internal(fid))
678 /* For external visible MDT-object with non-normal FID. */
679 if (fid_is_namespace_visible(fid) && !fid_is_norm(fid))
682 /* For the object with normal FID, it may be MDT-object,
683 * or may be 2.4 OST-object, need further distinguish.
684 * Fall through to next section. */
687 if (rc == -ENODATA || rc == 0) {
688 rc = osd_get_idif(info, inode, &info->oti_obj_dentry, fid);
691 /* It is 2.3 or older OST-object. */
692 rc = SCRUB_NEXT_OSTOBJ_OLD;
698 /* It is FID-on-OST, but we do not know how
699 * to generate its FID, ignore it directly. */
700 rc = SCRUB_NEXT_CONTINUE;
702 /* It is 2.4 or newer OST-object. */
703 rc = SCRUB_NEXT_OSTOBJ_OLD;
711 if (dev->od_scrub.os_scrub.os_convert_igif) {
712 lu_igif_build(fid, inode->i_ino,
713 inode->i_generation);
715 rc = SCRUB_NEXT_NOLMA;
719 /* It may be FID-on-OST, or may be FID for
720 * non-MDT0, anyway, we do not know how to
721 * generate its FID, ignore it directly. */
722 rc = SCRUB_NEXT_CONTINUE;
727 /* For OI scrub case only: the object has LMA but has no ff
728 * (or ff crashed). It may be MDT-object, may be OST-object
729 * with crashed ff. The last check is local FLDB. */
730 rc = osd_scrub_check_local_fldb(info, dev, fid);
736 static int osd_iit_iget(struct osd_thread_info *info, struct osd_device *dev,
737 struct lu_fid *fid, struct osd_inode_id *lid, __u32 pos,
738 struct super_block *sb, bool scrub)
744 /* Not handle the backend root object and agent parent object.
745 * They are neither visible to namespace nor have OI mappings. */
746 if (unlikely(pos == osd_sb(dev)->s_root->d_inode->i_ino ||
747 is_remote_parent_ino(dev, pos)))
748 RETURN(SCRUB_NEXT_CONTINUE);
750 /* Skip project quota inode since it is greater than s_first_ino. */
751 #ifdef HAVE_PROJECT_QUOTA
752 if (ldiskfs_has_feature_project(sb) &&
753 pos == le32_to_cpu(LDISKFS_SB(sb)->s_es->s_prj_quota_inum))
754 RETURN(SCRUB_NEXT_CONTINUE);
757 osd_id_gen(lid, pos, OSD_OII_NOGEN);
758 inode = osd_iget(info, dev, lid);
761 /* The inode may be removed after bitmap searching, or the
762 * file is new created without inode initialized yet.
763 * LU-15754: After "new primitive: discard_new_inode()" change
764 * in the kernel find_inode_fast() returns -ESTALE, but
765 * iget_locked replaces it to the NULL and finally
766 * ldiskfs_inode_attach_jinode() returns -ENOMEM
767 * Let's skip an inode if -ENOMEM returned.
769 if (rc == -ENOENT || rc == -ESTALE || rc == -ENOMEM)
770 RETURN(SCRUB_NEXT_CONTINUE);
772 CDEBUG(D_LFSCK, "%s: fail to read inode, ino# = %u: "
773 "rc = %d\n", osd_dev2name(dev), pos, rc);
777 if (dev->od_is_ost && S_ISREG(inode->i_mode) && inode->i_nlink > 1)
778 dev->od_scrub.os_scrub.os_has_ml_file = 1;
781 ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB)) {
782 /* Only skip it for the first OI scrub accessing. */
783 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
784 GOTO(put, rc = SCRUB_NEXT_NOSCRUB);
787 rc = osd_scrub_get_fid(info, dev, inode, fid, scrub);
796 static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
797 struct osd_iit_param *param,
798 struct osd_idmap_cache **oic, const bool noslot)
800 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
802 struct osd_inode_id *lid;
805 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0)
806 wait_var_event_timeout(
808 !list_empty(&scrub->os_inconsistent_items) ||
809 kthread_should_stop(),
810 cfs_time_seconds(cfs_fail_val));
812 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_CRASH)) {
813 spin_lock(&scrub->os_lock);
814 scrub->os_running = 0;
815 spin_unlock(&scrub->os_lock);
816 return SCRUB_NEXT_CRASH;
819 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_FATAL))
820 return SCRUB_NEXT_FATAL;
822 if (kthread_should_stop())
823 return SCRUB_NEXT_EXIT;
825 if (!list_empty(&scrub->os_inconsistent_items)) {
826 spin_lock(&scrub->os_lock);
827 if (likely(!list_empty(&scrub->os_inconsistent_items))) {
828 struct osd_inconsistent_item *oii;
830 oii = list_entry(scrub->os_inconsistent_items.next,
831 struct osd_inconsistent_item, oii_list);
833 *oic = &oii->oii_cache;
834 scrub->os_in_prior = 1;
835 spin_unlock(&scrub->os_lock);
839 spin_unlock(&scrub->os_lock);
843 return SCRUB_NEXT_WAIT;
845 rc = osd_iit_next(param, &scrub->os_pos_current);
849 *oic = &dev->od_scrub.os_oic;
850 fid = &(*oic)->oic_fid;
851 lid = &(*oic)->oic_lid;
852 rc = osd_iit_iget(info, dev, fid, lid,
853 scrub->os_pos_current, param->sb, true);
857 static int osd_preload_next(struct osd_thread_info *info,
858 struct osd_device *dev, struct osd_iit_param *param,
859 struct osd_idmap_cache **oic, const bool noslot)
861 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
862 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
865 if (scrub->os_running &&
866 ooc->ooc_pos_preload >= scrub->os_pos_current)
867 return SCRUB_NEXT_EXIT;
869 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
873 rc = osd_iit_iget(info, dev,
874 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
875 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
876 ooc->ooc_pos_preload, param->sb, false);
881 osd_scrub_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
883 spin_lock(&scrub->os_lock);
884 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
885 !list_empty(&scrub->os_inconsistent_items) ||
886 it->ooi_waiting || kthread_should_stop())
887 scrub->os_waiting = 0;
889 scrub->os_waiting = 1;
890 spin_unlock(&scrub->os_lock);
892 return !scrub->os_waiting;
895 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
896 struct osd_iit_param *param,
897 struct osd_idmap_cache *oic, bool *noslot, int rc)
899 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
900 struct scrub_file *sf = &scrub->os_file;
901 struct osd_otable_it *it = dev->od_otable_it;
902 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
905 case SCRUB_NEXT_NOSCRUB:
906 down_write(&scrub->os_rwsem);
907 scrub->os_new_checked++;
908 sf->sf_items_noscrub++;
909 up_write(&scrub->os_rwsem);
910 case SCRUB_NEXT_CONTINUE:
911 case SCRUB_NEXT_WAIT:
915 rc = osd_scrub_check_update(info, dev, oic, rc);
917 spin_lock(&scrub->os_lock);
918 scrub->os_in_prior = 0;
919 spin_unlock(&scrub->os_lock);
923 rc = scrub_checkpoint(info->oti_env, scrub);
925 CDEBUG(D_LFSCK, "%s: fail to checkpoint, pos = %llu: "
926 "rc = %d\n", osd_scrub2name(scrub),
927 scrub->os_pos_current, rc);
928 /* Continue, as long as the scrub itself can go ahead. */
931 if (scrub->os_in_prior) {
932 spin_lock(&scrub->os_lock);
933 scrub->os_in_prior = 0;
934 spin_unlock(&scrub->os_lock);
939 if (it != NULL && it->ooi_waiting && ooc != NULL &&
940 ooc->ooc_pos_preload < scrub->os_pos_current) {
941 spin_lock(&scrub->os_lock);
944 spin_unlock(&scrub->os_lock);
947 if (rc == SCRUB_NEXT_CONTINUE)
950 if (scrub->os_full_speed || !ooc || osd_scrub_has_window(scrub, ooc)) {
956 wait_var_event(scrub, osd_scrub_wakeup(scrub, it));
958 if (!ooc || osd_scrub_has_window(scrub, ooc))
965 static int osd_preload_exec(struct osd_thread_info *info,
966 struct osd_device *dev, struct osd_iit_param *param,
967 struct osd_idmap_cache *oic, bool *noslot, int rc)
969 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
972 ooc->ooc_cached_items++;
973 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
974 ~OSD_OTABLE_IT_CACHE_MASK;
976 return rc > 0 ? 0 : rc;
979 #define SCRUB_IT_ALL 1
980 #define SCRUB_IT_CRASH 2
982 static void osd_scrub_join(const struct lu_env *env, struct osd_device *dev,
983 __u32 flags, bool inconsistent)
985 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
986 struct scrub_file *sf = &scrub->os_file;
990 LASSERT(!(flags & SS_AUTO_PARTIAL));
992 down_write(&scrub->os_rwsem);
993 spin_lock(&scrub->os_lock);
994 scrub->os_in_join = 1;
995 if (flags & SS_SET_FAILOUT)
996 sf->sf_param |= SP_FAILOUT;
997 else if (flags & SS_CLEAR_FAILOUT)
998 sf->sf_param &= ~SP_FAILOUT;
1000 if (flags & SS_SET_DRYRUN)
1001 sf->sf_param |= SP_DRYRUN;
1002 else if (flags & SS_CLEAR_DRYRUN)
1003 sf->sf_param &= ~SP_DRYRUN;
1005 if (flags & SS_RESET) {
1006 scrub_file_reset(scrub, dev->od_uuid,
1007 inconsistent ? SF_INCONSISTENT : 0);
1008 sf->sf_status = SS_SCANNING;
1011 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
1012 scrub->os_full_speed = 1;
1014 scrub->os_full_speed = 0;
1016 if (flags & SS_AUTO_FULL) {
1017 sf->sf_flags |= SF_AUTO;
1018 scrub->os_full_speed = 1;
1020 spin_unlock(&scrub->os_lock);
1022 scrub->os_new_checked = 0;
1023 if (sf->sf_pos_last_checkpoint != 0)
1024 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
1026 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
1028 scrub->os_pos_current = sf->sf_pos_latest_start;
1029 sf->sf_time_latest_start = ktime_get_real_seconds();
1030 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
1031 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
1032 rc = scrub_file_store(env, scrub);
1034 spin_lock(&scrub->os_lock);
1035 scrub->os_waiting = 0;
1036 scrub->os_paused = 0;
1037 scrub->os_partial_scan = 0;
1038 scrub->os_in_join = 0;
1039 scrub->os_full_scrub = 0;
1040 spin_unlock(&scrub->os_lock);
1042 up_write(&scrub->os_rwsem);
1044 CDEBUG(D_LFSCK, "%s: joined in the OI scrub with flag %u: rc = %d\n",
1045 osd_scrub2name(scrub), flags, rc);
1050 static int osd_inode_iteration(struct osd_thread_info *info,
1051 struct osd_device *dev, __u32 max, bool preload)
1053 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1054 struct scrub_file *sf = &scrub->os_file;
1055 osd_iit_next_policy next;
1056 osd_iit_exec_policy exec;
1059 struct osd_iit_param *param;
1068 param = &dev->od_scrub.os_iit_param;
1069 memset(param, 0, sizeof(*param));
1070 param->sb = osd_sb(dev);
1072 while (scrub->os_partial_scan && !scrub->os_in_join) {
1073 struct osd_idmap_cache *oic = NULL;
1075 rc = osd_scrub_next(info, dev, param, &oic, noslot);
1077 case SCRUB_NEXT_EXIT:
1079 case SCRUB_NEXT_CRASH:
1080 RETURN(SCRUB_IT_CRASH);
1081 case SCRUB_NEXT_FATAL:
1083 case SCRUB_NEXT_WAIT: {
1084 struct kstatfs *ksfs = &info->oti_ksfs;
1087 if (dev->od_full_scrub_ratio == OFSR_NEVER ||
1088 unlikely(sf->sf_items_updated_prior == 0))
1091 if (dev->od_full_scrub_ratio == OFSR_DIRECTLY ||
1092 scrub->os_full_scrub) {
1093 osd_scrub_join(info->oti_env, dev,
1094 SS_AUTO_FULL | SS_RESET, true);
1098 rc = param->sb->s_op->statfs(param->sb->s_root, ksfs);
1100 __u64 used = ksfs->f_files - ksfs->f_ffree;
1102 used = div64_u64(used, sf->sf_items_updated_prior);
1103 /* If we hit too much inconsistent OI
1104 * mappings during the partial scan,
1105 * then scan the device completely. */
1106 if (used < dev->od_full_scrub_ratio) {
1107 osd_scrub_join(info->oti_env, dev,
1108 SS_AUTO_FULL | SS_RESET, true);
1114 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) &&
1118 saved_flags = sf->sf_flags;
1119 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
1120 SF_UPGRADE | SF_AUTO);
1121 sf->sf_status = SS_COMPLETED;
1124 kthread_should_stop() ||
1125 !scrub->os_partial_scan ||
1126 scrub->os_in_join ||
1127 !list_empty(&scrub->os_inconsistent_items));
1128 sf->sf_flags = saved_flags;
1129 sf->sf_status = SS_SCANNING;
1131 if (kthread_should_stop())
1134 if (!scrub->os_partial_scan || scrub->os_in_join)
1140 LASSERTF(rc == 0, "rc = %d\n", rc);
1142 osd_scrub_exec(info, dev, param, oic, &noslot, rc);
1149 wait_var_event(scrub,
1150 kthread_should_stop() ||
1151 !scrub->os_in_join);
1153 if (kthread_should_stop())
1159 next = osd_scrub_next;
1160 exec = osd_scrub_exec;
1161 pos = &scrub->os_pos_current;
1162 count = &scrub->os_new_checked;
1163 param->start = *pos;
1164 param->bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param->sb);
1166 (*pos - 1) % LDISKFS_INODES_PER_GROUP(param->sb);
1168 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1170 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1172 next = osd_preload_next;
1173 exec = osd_preload_exec;
1174 pos = &ooc->ooc_pos_preload;
1175 count = &ooc->ooc_cached_items;
1176 param = &dev->od_otable_it->ooi_iit_param;
1180 limit = le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count);
1181 while (*pos <= limit && *count < max) {
1182 struct ldiskfs_group_desc *desc;
1183 bool next_group = false;
1185 desc = ldiskfs_get_group_desc(param->sb, param->bg, NULL);
1189 if (desc->bg_flags & cpu_to_le16(LDISKFS_BG_INODE_UNINIT)) {
1194 param->bitmap = ldiskfs_read_inode_bitmap(param->sb, param->bg);
1195 if (IS_ERR_OR_NULL(param->bitmap)) {
1196 if (param->bitmap) {
1197 rc = PTR_ERR(param->bitmap);
1198 param->bitmap = NULL;
1202 CERROR("%s: fail to read bitmap for %u, scrub will stop, urgent mode: rc = %d\n",
1203 osd_scrub2name(scrub), (__u32)param->bg, rc);
1208 struct osd_idmap_cache *oic = NULL;
1211 ldiskfs_itable_unused_count(param->sb, desc) >=
1212 LDISKFS_INODES_PER_GROUP(param->sb)) {
1217 rc = next(info, dev, param, &oic, noslot);
1219 case SCRUB_NEXT_BREAK:
1222 case SCRUB_NEXT_EXIT:
1223 brelse(param->bitmap);
1225 case SCRUB_NEXT_CRASH:
1226 brelse(param->bitmap);
1227 RETURN(SCRUB_IT_CRASH);
1228 case SCRUB_NEXT_FATAL:
1229 brelse(param->bitmap);
1233 rc = exec(info, dev, param, oic, &noslot, rc);
1234 } while (!rc && *pos <= limit && *count < max);
1237 if (param->bitmap) {
1238 brelse(param->bitmap);
1239 param->bitmap = NULL;
1249 param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1250 *pos = param->gbase;
1251 param->start = *pos;
1256 RETURN(SCRUB_IT_ALL);
1262 static int osd_otable_it_preload(const struct lu_env *env,
1263 struct osd_otable_it *it)
1265 struct osd_device *dev = it->ooi_dev;
1266 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1267 struct osd_otable_cache *ooc = &it->ooi_cache;
1271 rc = osd_inode_iteration(osd_oti_get(env), dev,
1272 OSD_OTABLE_IT_CACHE_SIZE, true);
1273 if (rc == SCRUB_IT_ALL)
1274 it->ooi_all_cached = 1;
1276 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1277 spin_lock(&scrub->os_lock);
1278 scrub->os_waiting = 0;
1280 spin_unlock(&scrub->os_lock);
1283 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1286 static int osd_scan_ml_file_main(const struct lu_env *env,
1287 struct osd_device *dev);
1289 static int osd_scrub_main(void *args)
1292 struct osd_device *dev = (struct osd_device *)args;
1293 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1297 rc = lu_env_init(&env, LCT_LOCAL | LCT_DT_THREAD);
1299 CDEBUG(D_LFSCK, "%s: OI scrub fail to init env: rc = %d\n",
1300 osd_scrub2name(scrub), rc);
1304 rc = scrub_thread_prep(&env, scrub, dev->od_uuid,
1305 LDISKFS_FIRST_INO(osd_sb(dev)) + 1);
1307 CDEBUG(D_LFSCK, "%s: OI scrub fail to scrub prep: rc = %d\n",
1308 osd_scrub2name(scrub), rc);
1312 if (!scrub->os_full_speed && !scrub->os_partial_scan) {
1313 struct osd_otable_it *it = dev->od_otable_it;
1314 struct osd_otable_cache *ooc = &it->ooi_cache;
1316 wait_var_event(scrub,
1317 it->ooi_user_ready || kthread_should_stop());
1318 if (kthread_should_stop())
1321 scrub->os_pos_current = ooc->ooc_pos_preload;
1324 CDEBUG(D_LFSCK, "%s: OI scrub start, flags = 0x%x, pos = %llu\n",
1325 osd_scrub2name(scrub), scrub->os_start_flags,
1326 scrub->os_pos_current);
1328 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1329 if (unlikely(rc == SCRUB_IT_CRASH)) {
1330 spin_lock(&scrub->os_lock);
1331 scrub->os_running = 0;
1332 spin_unlock(&scrub->os_lock);
1333 GOTO(out, rc = -EINVAL);
1336 if (scrub->os_has_ml_file) {
1337 ret = osd_scan_ml_file_main(&env, dev);
1346 dev->od_igif_inoi = 1;
1347 dev->od_check_ff = 0;
1349 rc = scrub_thread_post(&env, &dev->od_scrub.os_scrub, rc);
1350 CDEBUG(D_LFSCK, "%s: OI scrub: stop, pos = %llu: rc = %d\n",
1351 osd_scrub2name(scrub), scrub->os_pos_current, rc);
1354 osd_scrub_ois_fini(scrub, &scrub->os_inconsistent_items);
1358 spin_lock(&scrub->os_lock);
1359 scrub->os_running = 0;
1360 spin_unlock(&scrub->os_lock);
1361 if (xchg(&scrub->os_task, NULL) == NULL)
1362 /* scrub_stop() is waiting, we need to synchronize */
1363 wait_var_event(scrub, kthread_should_stop());
1368 /* initial OI scrub */
1370 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1371 struct dentry *, filldir_t filldir);
1373 #ifdef HAVE_FILLDIR_USE_CTX
1375 osd_ios_varfid_fill(struct dir_context *buf, const char *name, int namelen,
1376 loff_t offset, __u64 ino, unsigned int d_type);
1379 osd_ios_lf_fill(struct dir_context *buf, const char *name, int namelen,
1380 loff_t offset, __u64 ino, unsigned int d_type);
1383 osd_ios_dl_fill(struct dir_context *buf, const char *name, int namelen,
1384 loff_t offset, __u64 ino, unsigned int d_type);
1387 osd_ios_uld_fill(struct dir_context *buf, const char *name, int namelen,
1388 loff_t offset, __u64 ino, unsigned int d_type);
1390 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1391 loff_t offset, __u64 ino, unsigned int d_type);
1392 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1393 loff_t offset, __u64 ino, unsigned int d_type);
1394 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1395 loff_t offset, __u64 ino, unsigned int d_type);
1396 static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
1397 loff_t offset, __u64 ino, unsigned int d_type);
1401 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1402 struct dentry *dentry, filldir_t filldir);
1404 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1405 struct dentry *dentry, filldir_t filldir);
1408 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1409 struct dentry *dentry, filldir_t filldir);
1413 struct lu_fid olm_fid;
1416 scandir_t olm_scandir;
1417 filldir_t olm_filldir;
1420 /* Add the new introduced local files in the list in the future. */
1421 static const struct osd_lf_map osd_lf_maps[] = {
1424 .olm_name = CATLIST,
1426 .f_seq = FID_SEQ_LOCAL_FILE,
1427 .f_oid = LLOG_CATALOGS_OID,
1429 .olm_flags = OLF_SHOW_NAME,
1430 .olm_namelen = sizeof(CATLIST) - 1,
1435 .olm_name = MOUNT_CONFIGS_DIR,
1437 .f_seq = FID_SEQ_LOCAL_FILE,
1438 .f_oid = MGS_CONFIGS_OID,
1440 .olm_flags = OLF_SCAN_SUBITEMS,
1441 .olm_namelen = sizeof(MOUNT_CONFIGS_DIR) - 1,
1442 .olm_scandir = osd_ios_general_scan,
1443 .olm_filldir = osd_ios_varfid_fill,
1446 /* NIDTBL_VERSIONS */
1448 .olm_name = MGS_NIDTBL_DIR,
1449 .olm_flags = OLF_SCAN_SUBITEMS,
1450 .olm_namelen = sizeof(MGS_NIDTBL_DIR) - 1,
1451 .olm_scandir = osd_ios_general_scan,
1452 .olm_filldir = osd_ios_varfid_fill,
1457 .olm_name = MDT_ORPHAN_DIR,
1458 .olm_namelen = sizeof(MDT_ORPHAN_DIR) - 1,
1465 .f_seq = FID_SEQ_ROOT,
1466 .f_oid = FID_OID_ROOT,
1468 .olm_flags = OLF_SCAN_SUBITEMS | OLF_HIDE_FID,
1469 .olm_namelen = sizeof("ROOT") - 1,
1470 .olm_scandir = osd_ios_ROOT_scan,
1473 /* changelog_catalog */
1475 .olm_name = CHANGELOG_CATALOG,
1476 .olm_namelen = sizeof(CHANGELOG_CATALOG) - 1,
1479 /* changelog_users */
1481 .olm_name = CHANGELOG_USERS,
1482 .olm_namelen = sizeof(CHANGELOG_USERS) - 1,
1489 .f_seq = FID_SEQ_LOCAL_FILE,
1490 .f_oid = FLD_INDEX_OID,
1492 .olm_flags = OLF_SHOW_NAME,
1493 .olm_namelen = sizeof("fld") - 1,
1498 .olm_name = LAST_RCVD,
1500 .f_seq = FID_SEQ_LOCAL_FILE,
1501 .f_oid = LAST_RECV_OID,
1503 .olm_flags = OLF_SHOW_NAME,
1504 .olm_namelen = sizeof(LAST_RCVD) - 1,
1509 .olm_name = REPLY_DATA,
1511 .f_seq = FID_SEQ_LOCAL_FILE,
1512 .f_oid = REPLY_DATA_OID,
1514 .olm_flags = OLF_SHOW_NAME,
1515 .olm_namelen = sizeof(REPLY_DATA) - 1,
1520 .olm_name = LOV_OBJID,
1522 .f_seq = FID_SEQ_LOCAL_FILE,
1523 .f_oid = MDD_LOV_OBJ_OID,
1525 .olm_flags = OLF_SHOW_NAME,
1526 .olm_namelen = sizeof(LOV_OBJID) - 1,
1531 .olm_name = LOV_OBJSEQ,
1533 .f_seq = FID_SEQ_LOCAL_FILE,
1534 .f_oid = MDD_LOV_OBJ_OSEQ,
1536 .olm_flags = OLF_SHOW_NAME,
1537 .olm_namelen = sizeof(LOV_OBJSEQ) - 1,
1542 .olm_name = QMT_DIR,
1543 .olm_flags = OLF_SCAN_SUBITEMS,
1544 .olm_namelen = sizeof(QMT_DIR) - 1,
1545 .olm_scandir = osd_ios_general_scan,
1546 .olm_filldir = osd_ios_varfid_fill,
1551 .olm_name = QSD_DIR,
1552 .olm_flags = OLF_SCAN_SUBITEMS,
1553 .olm_namelen = sizeof(QSD_DIR) - 1,
1554 .olm_scandir = osd_ios_general_scan,
1555 .olm_filldir = osd_ios_varfid_fill,
1560 .olm_name = "seq_ctl",
1562 .f_seq = FID_SEQ_LOCAL_FILE,
1563 .f_oid = FID_SEQ_CTL_OID,
1565 .olm_flags = OLF_SHOW_NAME,
1566 .olm_namelen = sizeof("seq_ctl") - 1,
1571 .olm_name = "seq_srv",
1573 .f_seq = FID_SEQ_LOCAL_FILE,
1574 .f_oid = FID_SEQ_SRV_OID,
1576 .olm_flags = OLF_SHOW_NAME,
1577 .olm_namelen = sizeof("seq_srv") - 1,
1582 .olm_name = HEALTH_CHECK,
1584 .f_seq = FID_SEQ_LOCAL_FILE,
1585 .f_oid = OFD_HEALTH_CHECK_OID,
1587 .olm_flags = OLF_SHOW_NAME,
1588 .olm_namelen = sizeof(HEALTH_CHECK) - 1,
1593 .olm_name = LFSCK_DIR,
1594 .olm_flags = OLF_SCAN_SUBITEMS,
1595 .olm_namelen = sizeof(LFSCK_DIR) - 1,
1596 .olm_scandir = osd_ios_general_scan,
1597 .olm_filldir = osd_ios_varfid_fill,
1600 /* lfsck_bookmark */
1602 .olm_name = LFSCK_BOOKMARK,
1603 .olm_namelen = sizeof(LFSCK_BOOKMARK) - 1,
1608 .olm_name = LFSCK_LAYOUT,
1609 .olm_namelen = sizeof(LFSCK_LAYOUT) - 1,
1612 /* lfsck_namespace */
1614 .olm_name = LFSCK_NAMESPACE,
1615 .olm_namelen = sizeof(LFSCK_NAMESPACE) - 1,
1618 /* OBJECTS, upgrade from old device */
1620 .olm_name = OBJECTS,
1621 .olm_flags = OLF_SCAN_SUBITEMS,
1622 .olm_namelen = sizeof(OBJECTS) - 1,
1623 .olm_scandir = osd_ios_OBJECTS_scan,
1626 /* lquota_v2.user, upgrade from old device */
1628 .olm_name = "lquota_v2.user",
1629 .olm_namelen = sizeof("lquota_v2.user") - 1,
1632 /* lquota_v2.group, upgrade from old device */
1634 .olm_name = "lquota_v2.group",
1635 .olm_namelen = sizeof("lquota_v2.group") - 1,
1638 /* LAST_GROUP, upgrade from old device */
1640 .olm_name = "LAST_GROUP",
1642 .f_seq = FID_SEQ_LOCAL_FILE,
1643 .f_oid = OFD_LAST_GROUP_OID,
1645 .olm_flags = OLF_SHOW_NAME,
1646 .olm_namelen = sizeof("LAST_GROUP") - 1,
1649 /* committed batchid for cross-MDT operation */
1651 .olm_name = "BATCHID",
1653 .f_seq = FID_SEQ_LOCAL_FILE,
1654 .f_oid = BATCHID_COMMITTED_OID,
1656 .olm_flags = OLF_SHOW_NAME,
1657 .olm_namelen = sizeof("BATCHID") - 1,
1660 /* OSP update logs update_log{_dir} use f_seq = FID_SEQ_UPDATE_LOG{_DIR}
1661 * and f_oid = index for their log files. See lu_update_log{_dir}_fid()
1662 * for more details. */
1666 .olm_name = "update_log",
1668 .f_seq = FID_SEQ_UPDATE_LOG,
1670 .olm_flags = OLF_SHOW_NAME | OLF_IDX_IN_FID,
1671 .olm_namelen = sizeof("update_log") - 1,
1674 /* update_log_dir */
1676 .olm_name = "update_log_dir",
1678 .f_seq = FID_SEQ_UPDATE_LOG_DIR,
1680 .olm_flags = OLF_SHOW_NAME | OLF_SCAN_SUBITEMS |
1682 .olm_namelen = sizeof("update_log_dir") - 1,
1683 .olm_scandir = osd_ios_general_scan,
1684 .olm_filldir = osd_ios_uld_fill,
1689 .olm_name = "lost+found",
1691 .f_seq = FID_SEQ_LOCAL_FILE,
1692 .f_oid = OSD_LPF_OID,
1694 .olm_flags = OLF_SCAN_SUBITEMS,
1695 .olm_namelen = sizeof("lost+found") - 1,
1696 .olm_scandir = osd_ios_general_scan,
1697 .olm_filldir = osd_ios_lf_fill,
1702 .olm_name = HSM_ACTIONS,
1707 .olm_name = LUSTRE_NODEMAP_NAME,
1712 .olm_name = INDEX_BACKUP_DIR,
1714 .f_seq = FID_SEQ_LOCAL_FILE,
1715 .f_oid = INDEX_BACKUP_OID,
1717 .olm_flags = OLF_SCAN_SUBITEMS | OLF_NOT_BACKUP,
1718 .olm_namelen = sizeof(INDEX_BACKUP_DIR) - 1,
1719 .olm_scandir = osd_ios_general_scan,
1720 .olm_filldir = osd_ios_varfid_fill,
1728 /* Add the new introduced files under .lustre/ in the list in the future. */
1729 static const struct osd_lf_map osd_dl_maps[] = {
1734 .f_seq = FID_SEQ_DOT_LUSTRE,
1735 .f_oid = FID_OID_DOT_LUSTRE_OBF,
1737 .olm_namelen = sizeof("fid") - 1,
1740 /* .lustre/lost+found */
1742 .olm_name = "lost+found",
1744 .f_seq = FID_SEQ_DOT_LUSTRE,
1745 .f_oid = FID_OID_DOT_LUSTRE_LPF,
1747 .olm_namelen = sizeof("lost+found") - 1,
1755 struct osd_ios_item {
1756 struct list_head oii_list;
1757 struct dentry *oii_dentry;
1758 scandir_t oii_scandir;
1759 filldir_t oii_filldir;
1762 struct osd_ios_filldir_buf {
1763 /* please keep it as first member */
1764 struct dir_context ctx;
1765 struct osd_thread_info *oifb_info;
1766 struct osd_device *oifb_dev;
1767 struct dentry *oifb_dentry;
1772 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1773 scandir_t scandir, filldir_t filldir)
1775 struct osd_ios_item *item;
1778 OBD_ALLOC_PTR(item);
1782 INIT_LIST_HEAD(&item->oii_list);
1783 item->oii_dentry = dget(dentry);
1784 item->oii_scandir = scandir;
1785 item->oii_filldir = filldir;
1786 list_add_tail(&item->oii_list, &dev->od_ios_list);
1791 static bool osd_index_need_recreate(const struct lu_env *env,
1792 struct osd_device *dev, struct inode *inode)
1794 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1795 struct iam_container *bag = &iam->od_container;
1799 rc = iam_container_init(bag, &iam->od_descr, inode);
1803 rc = iam_container_setup(bag);
1804 iam_container_fini(bag);
1811 static void osd_ios_index_register(const struct lu_env *env,
1812 struct osd_device *osd,
1813 const struct lu_fid *fid,
1814 struct inode *inode)
1816 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1817 struct iam_container *bag = &iam->od_container;
1818 struct super_block *sb = osd_sb(osd);
1819 struct iam_descr *descr;
1825 /* Index must be a regular file. */
1826 if (!S_ISREG(inode->i_mode))
1829 /* Index's size must be block aligned. */
1830 if (inode->i_size < sb->s_blocksize ||
1831 (inode->i_size & (sb->s_blocksize - 1)) != 0)
1834 iam_container_init(bag, &iam->od_descr, inode);
1835 rc = iam_container_setup(bag);
1839 descr = bag->ic_descr;
1840 /* May be regular file with IAM_LFIX_ROOT_MAGIC matched
1841 * coincidentally, or corrupted index object, skip it. */
1842 if (descr->id_ptr_size != 4)
1845 keysize = descr->id_key_size;
1846 recsize = descr->id_rec_size;
1847 rc = osd_index_register(osd, fid, keysize, recsize);
1852 iam_container_fini(bag);
1854 CDEBUG(D_LFSCK, "%s: index object "DFID" (%u/%u) registered\n",
1855 osd_name(osd), PFID(fid), keysize, recsize);
1858 static void osd_index_restore(const struct lu_env *env, struct osd_device *dev,
1859 struct lustre_index_restore_unit *liru,
1860 void *buf, int bufsize)
1862 struct osd_thread_info *info = osd_oti_get(env);
1863 struct osd_inode_id *id = &info->oti_id;
1864 struct lu_fid *tgt_fid = &liru->liru_cfid;
1865 struct inode *bak_inode = NULL;
1866 struct ldiskfs_dir_entry_2 *de = NULL;
1867 struct buffer_head *bh = NULL;
1868 struct dentry *dentry;
1870 struct lu_fid bak_fid;
1874 lustre_fid2lbx(name, tgt_fid, bufsize);
1875 dentry = osd_child_dentry_by_inode(env, dev->od_index_backup_inode,
1876 name, strlen(name));
1877 bh = osd_ldiskfs_find_entry(dev->od_index_backup_inode,
1878 &dentry->d_name, &de, NULL, NULL);
1880 GOTO(log, rc = PTR_ERR(bh));
1882 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
1884 bak_inode = osd_iget_fid(info, dev, id, &bak_fid);
1885 if (IS_ERR(bak_inode))
1886 GOTO(log, rc = PTR_ERR(bak_inode));
1889 /* The OI mapping for index may be invalid, since it will be
1890 * re-created, not update the OI mapping, just cache it in RAM. */
1891 osd_id_gen(id, liru->liru_clid, OSD_OII_NOGEN);
1892 osd_add_oi_cache(info, dev, id, tgt_fid);
1893 rc = lustre_index_restore(env, &dev->od_dt_dev, &liru->liru_pfid,
1894 tgt_fid, &bak_fid, liru->liru_name,
1895 &dev->od_index_backup_list, &dev->od_lock,
1900 CDEBUG(D_WARNING, "%s: restore index '%s' with "DFID": rc = %d\n",
1901 osd_name(dev), liru->liru_name, PFID(tgt_fid), rc);
1905 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1907 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1908 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1909 * reference the inode, or fixed if it is missing or references another inode.
1912 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1913 struct inode *parent, struct inode *inode,
1914 const struct lu_fid *fid, const char *name,
1915 int namelen, int flags)
1917 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1918 struct osd_inode_id *id = &info->oti_id;
1919 struct osd_inode_id *id2 = &info->oti_id2;
1920 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1921 struct scrub_file *sf = &scrub->os_file;
1927 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode: rc = -2\n",
1928 osd_name(dev), namelen, name);
1932 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
1933 &info->oti_ost_attrs);
1934 if (rc != 0 && rc != -ENODATA) {
1935 CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
1936 "rc = %d\n", osd_name(dev), rc);
1941 osd_id_gen(id, inode->i_ino, inode->i_generation);
1942 if (rc == -ENODATA) {
1943 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID) {
1944 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1947 if (flags & OLF_IDX_IN_FID) {
1948 LASSERT(dev->od_index >= 0);
1950 tfid.f_oid = dev->od_index;
1953 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1955 CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
1956 "scrub: rc = %d\n", osd_name(dev), rc);
1961 if (lma->lma_compat & LMAC_NOT_IN_OI)
1964 tfid = lma->lma_self_fid;
1965 if (lma->lma_compat & LMAC_IDX_BACKUP &&
1966 osd_index_need_recreate(info->oti_env, dev, inode)) {
1967 struct lu_fid *pfid = &info->oti_fid3;
1969 if (is_root_inode(parent)) {
1970 lu_local_obj_fid(pfid, OSD_FS_ROOT_OID);
1972 rc = osd_scrub_get_fid(info, dev, parent, pfid,
1978 rc = lustre_liru_new(&dev->od_index_restore_list, pfid,
1979 &tfid, inode->i_ino, name, namelen);
1984 if (!(flags & OLF_NOT_BACKUP))
1985 osd_ios_index_register(info->oti_env, dev, &tfid,
1989 /* Since this called from iterate_dir() the inode lock will be taken */
1990 rc = osd_oi_lookup(info, dev, &tfid, id2, OI_LOCKED);
1995 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1996 DTO_INDEX_INSERT, true, 0, NULL);
2003 if (osd_id_eq_strict(id, id2))
2006 if (!(sf->sf_flags & SF_INCONSISTENT)) {
2007 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
2008 rc = scrub_file_store(info->oti_env, scrub);
2013 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
2014 DTO_INDEX_UPDATE, true, 0, NULL);
2022 * It scans the /lost+found, and for the OST-object (with filter_fid
2023 * or filter_fid_18_23), move them back to its proper /O/<seq>/d<x>.
2025 #ifdef HAVE_FILLDIR_USE_CTX
2026 static FILLDIR_TYPE do_osd_ios_lf_fill(struct dir_context *buf,
2028 static int osd_ios_lf_fill(void *buf,
2030 const char *name, int namelen,
2031 loff_t offset, __u64 ino, unsigned int d_type)
2033 struct osd_ios_filldir_buf *fill_buf =
2034 (struct osd_ios_filldir_buf *)buf;
2035 struct osd_thread_info *info = fill_buf->oifb_info;
2036 struct osd_device *dev = fill_buf->oifb_dev;
2037 struct lu_fid *fid = &info->oti_fid;
2038 struct osd_scrub *scrub = &dev->od_scrub;
2039 struct dentry *parent = fill_buf->oifb_dentry;
2040 struct dentry *child;
2041 struct inode *dir = parent->d_inode;
2042 struct inode *inode;
2046 fill_buf->oifb_items++;
2048 /* skip any '.' started names */
2052 scrub->os_lf_scanned++;
2053 child = osd_lookup_one_len(dev, name, parent, namelen);
2054 if (IS_ERR(child)) {
2055 rc = PTR_ERR(child);
2056 CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
2057 osd_name(dev), namelen, name, rc);
2059 } else if (!child->d_inode) {
2061 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode\n",
2062 osd_name(dev), namelen, name);
2066 inode = child->d_inode;
2067 if (S_ISDIR(inode->i_mode)) {
2068 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2071 CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
2072 "rc = %d\n", osd_name(dev), namelen, name, rc);
2076 if (!S_ISREG(inode->i_mode))
2079 rc = osd_scrub_get_fid(info, dev, inode, fid, true);
2080 if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
2081 rc = osd_obj_map_recover(info, dev, dir, child, fid);
2083 CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
2084 "/lost+found.\n", namelen, name, PFID(fid));
2085 scrub->os_lf_repaired++;
2087 CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
2089 osd_name(dev), namelen, name, PFID(fid), rc);
2093 /* XXX: For MDT-objects, we can move them from /lost+found to namespace
2094 * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
2095 * can process them in furtuer. */
2101 scrub->os_lf_failed++;
2103 /* skip the failure to make the scanning to continue. */
2106 WRAP_FILLDIR_FN(do_, osd_ios_lf_fill)
2108 #ifdef HAVE_FILLDIR_USE_CTX
2109 static FILLDIR_TYPE do_osd_ios_varfid_fill(struct dir_context *buf,
2111 static int osd_ios_varfid_fill(void *buf,
2113 const char *name, int namelen,
2114 loff_t offset, __u64 ino, unsigned int d_type)
2116 struct osd_ios_filldir_buf *fill_buf =
2117 (struct osd_ios_filldir_buf *)buf;
2118 struct osd_device *dev = fill_buf->oifb_dev;
2119 struct dentry *child;
2123 fill_buf->oifb_items++;
2125 /* skip any '.' started names */
2129 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2131 RETURN(PTR_ERR(child));
2133 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2134 fill_buf->oifb_dentry->d_inode, child->d_inode,
2135 NULL, name, namelen, 0);
2136 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
2137 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2138 osd_ios_varfid_fill);
2143 WRAP_FILLDIR_FN(do_, osd_ios_varfid_fill)
2145 #ifdef HAVE_FILLDIR_USE_CTX
2146 static FILLDIR_TYPE do_osd_ios_dl_fill(struct dir_context *buf,
2148 static int osd_ios_dl_fill(void *buf,
2150 const char *name, int namelen,
2151 loff_t offset, __u64 ino, unsigned int d_type)
2153 struct osd_ios_filldir_buf *fill_buf =
2154 (struct osd_ios_filldir_buf *)buf;
2155 struct osd_device *dev = fill_buf->oifb_dev;
2156 const struct osd_lf_map *map;
2157 struct dentry *child;
2161 fill_buf->oifb_items++;
2163 /* skip any '.' started names */
2167 for (map = osd_dl_maps; map->olm_name != NULL; map++) {
2168 if (map->olm_namelen != namelen)
2171 if (strncmp(map->olm_name, name, namelen) == 0)
2175 if (map->olm_name == NULL)
2178 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2180 RETURN(PTR_ERR(child));
2182 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2183 fill_buf->oifb_dentry->d_inode, child->d_inode,
2184 &map->olm_fid, name, namelen, map->olm_flags);
2189 WRAP_FILLDIR_FN(do_, osd_ios_dl_fill)
2191 #ifdef HAVE_FILLDIR_USE_CTX
2192 static FILLDIR_TYPE do_osd_ios_uld_fill(struct dir_context *buf,
2194 static int osd_ios_uld_fill(void *buf,
2196 const char *name, int namelen,
2197 loff_t offset, __u64 ino, unsigned int d_type)
2199 struct osd_ios_filldir_buf *fill_buf =
2200 (struct osd_ios_filldir_buf *)buf;
2201 struct osd_device *dev = fill_buf->oifb_dev;
2202 struct dentry *child;
2207 fill_buf->oifb_items++;
2209 /* skip any non-DFID format name */
2213 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2215 RETURN(PTR_ERR(child));
2217 /* skip the start '[' */
2218 sscanf(&name[1], SFID, RFID(&tfid));
2219 if (fid_is_sane(&tfid))
2220 rc = osd_ios_scan_one(fill_buf->oifb_info, fill_buf->oifb_dev,
2221 fill_buf->oifb_dentry->d_inode,
2222 child->d_inode, &tfid, name, namelen, 0);
2229 WRAP_FILLDIR_FN(do_, osd_ios_uld_fill)
2231 #ifdef HAVE_FILLDIR_USE_CTX
2232 static FILLDIR_TYPE do_osd_ios_root_fill(struct dir_context *buf,
2234 static int osd_ios_root_fill(void *buf,
2236 const char *name, int namelen,
2237 loff_t offset, __u64 ino, unsigned int d_type)
2239 struct osd_ios_filldir_buf *fill_buf =
2240 (struct osd_ios_filldir_buf *)buf;
2241 struct osd_device *dev = fill_buf->oifb_dev;
2242 const struct osd_lf_map *map;
2243 struct dentry *child;
2247 fill_buf->oifb_items++;
2249 /* skip any '.' started names */
2253 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
2254 if (map->olm_namelen != namelen)
2257 if (strncmp(map->olm_name, name, namelen) == 0)
2261 if (map->olm_name == NULL)
2264 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2266 RETURN(PTR_ERR(child));
2267 else if (!child->d_inode)
2268 GOTO(out_put, rc = -ENOENT);
2270 if (!(map->olm_flags & OLF_NO_OI))
2271 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2272 fill_buf->oifb_dentry->d_inode, child->d_inode,
2273 &map->olm_fid, name, namelen, map->olm_flags);
2274 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
2275 rc = osd_ios_new_item(dev, child, map->olm_scandir,
2283 WRAP_FILLDIR_FN(do_, osd_ios_root_fill)
2286 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
2287 struct dentry *dentry, filldir_t filldir)
2289 struct osd_ios_filldir_buf buf = {
2290 .ctx.actor = filldir,
2293 .oifb_dentry = dentry
2301 path.dentry = dget(dentry);
2302 path.mnt = mntget(dev->od_mnt);
2304 filp = dentry_open(&path, O_RDONLY, current_cred());
2307 RETURN(PTR_ERR(filp));
2309 filp->f_mode |= FMODE_64BITHASH | FMODE_NONOTIFY;
2310 filp->f_flags |= O_NOATIME;
2315 rc = iterate_dir(filp, &buf.ctx);
2316 } while (rc >= 0 && buf.oifb_items > 0 &&
2317 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
2324 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
2325 struct dentry *dentry, filldir_t filldir)
2327 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2328 struct scrub_file *sf = &scrub->os_file;
2329 struct dentry *child;
2333 /* It is existing MDT0 device. We only allow the case of object without
2334 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
2335 * can generate IGIF mode FID for the object and related OI mapping. If
2336 * it is on other MDTs, then becuase file-level backup/restore, related
2337 * OI mapping may be invalid already, we do not know which is the right
2338 * FID for the object. We only allow IGIF objects to reside on the MDT0.
2340 * XXX: For the case of object on non-MDT0 device with neither LMA nor
2341 * "fid" xattr, then something crashed. We cannot re-generate the
2342 * FID directly, instead, the OI scrub will scan the OI structure
2343 * and try to re-generate the LMA from the OI mapping. But if the
2344 * OI mapping crashed or lost also, then we have to give up under
2345 * double failure cases.
2347 spin_lock(&scrub->os_lock);
2348 scrub->os_convert_igif = 1;
2349 spin_unlock(&scrub->os_lock);
2350 child = osd_lookup_one_len_unlocked(dev, dot_lustre_name, dentry,
2351 strlen(dot_lustre_name));
2352 if (IS_ERR(child)) {
2353 if (PTR_ERR(child) != -ENOENT)
2354 RETURN(PTR_ERR(child));
2358 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
2359 * so the client will get IGIF for the ".lustre" object when
2362 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
2363 * it does not know whether there are some old clients cached
2364 * the ".lustre" IGIF during the upgrading. Two choices:
2366 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
2367 * It will allow the old connected clients to access the
2368 * ".lustre" with cached IGIF. But it will cause others
2369 * on the MDT failed to check "fid_is_dot_lustre()".
2371 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
2372 * for ".lustre" in spite of whether there are some clients
2373 * cached the ".lustre" IGIF or not. It enables the check
2374 * "fid_is_dot_lustre()" on the MDT, although it will cause
2375 * that the old connected clients cannot access the ".lustre"
2376 * with the cached IGIF.
2378 * Usually, it is rare case for the old connected clients
2379 * to access the ".lustre" with cached IGIF. So we prefer
2380 * to the solution 2).
2382 inode_lock(dentry->d_inode);
2383 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2384 child->d_inode, &LU_DOT_LUSTRE_FID,
2386 strlen(dot_lustre_name), 0);
2387 inode_unlock(dentry->d_inode);
2388 if (rc == -ENOENT) {
2390 /* It is 1.8 MDT device. */
2391 if (!(sf->sf_flags & SF_UPGRADE)) {
2392 scrub_file_reset(scrub, dev->od_uuid,
2394 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2395 rc = scrub_file_store(info->oti_env, scrub);
2399 } else if (rc == 0) {
2400 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2409 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
2410 struct dentry *dentry, filldir_t filldir)
2412 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2413 struct scrub_file *sf = &scrub->os_file;
2414 struct dentry *child;
2418 if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
2419 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2420 rc = scrub_file_store(info->oti_env, scrub);
2425 child = osd_lookup_one_len_unlocked(dev, ADMIN_USR, dentry,
2427 if (IS_ERR(child)) {
2428 rc = PTR_ERR(child);
2430 inode_lock(dentry->d_inode);
2431 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2432 child->d_inode, NULL, ADMIN_USR,
2433 strlen(ADMIN_USR), 0);
2434 inode_unlock(dentry->d_inode);
2438 if (rc != 0 && rc != -ENOENT)
2441 child = osd_lookup_one_len_unlocked(dev, ADMIN_GRP, dentry,
2444 GOTO(out, rc = PTR_ERR(child));
2446 inode_lock(dentry->d_inode);
2447 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2448 child->d_inode, NULL, ADMIN_GRP,
2449 strlen(ADMIN_GRP), 0);
2450 inode_unlock(dentry->d_inode);
2453 RETURN(rc == -ENOENT ? 0 : rc);
2456 static void osd_initial_OI_scrub(struct osd_thread_info *info,
2457 struct osd_device *dev)
2459 struct osd_ios_item *item = NULL;
2460 scandir_t scandir = osd_ios_general_scan;
2461 filldir_t filldir = osd_ios_root_fill;
2462 struct dentry *dentry = osd_sb(dev)->s_root;
2463 const struct osd_lf_map *map = osd_lf_maps;
2466 /* Lookup IGIF in OI by force for initial OI scrub. */
2467 dev->od_igif_inoi = 1;
2470 /* Don't take inode_lock here since scandir() callbacks
2471 * can call VFS functions which may manully take the
2472 * inode lock itself like iterate_dir(). Since this
2473 * is the case it is best to leave the scandir()
2474 * callbacks to managing the inode lock.
2476 scandir(info, dev, dentry, filldir);
2478 dput(item->oii_dentry);
2482 if (list_empty(&dev->od_ios_list))
2485 item = list_entry(dev->od_ios_list.next,
2486 struct osd_ios_item, oii_list);
2487 list_del_init(&item->oii_list);
2489 LASSERT(item->oii_scandir != NULL);
2490 scandir = item->oii_scandir;
2491 filldir = item->oii_filldir;
2492 dentry = item->oii_dentry;
2495 /* There maybe the case that the object has been removed, but its OI
2496 * mapping is still in the OI file, such as the "CATALOGS" after MDT
2497 * file-level backup/restore. So here cleanup the stale OI mappings. */
2498 while (map->olm_name != NULL) {
2499 struct dentry *child;
2501 if (fid_is_zero(&map->olm_fid)) {
2506 child = osd_lookup_one_len_unlocked(dev, map->olm_name,
2507 osd_sb(dev)->s_root,
2509 if (PTR_ERR(child) == -ENOENT ||
2510 (!IS_ERR(child) && !child->d_inode))
2511 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
2512 NULL, DTO_INDEX_DELETE,
2519 if (!list_empty(&dev->od_index_restore_list)) {
2522 OBD_ALLOC_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2524 CERROR("%s: not enough RAM for rebuild index\n",
2527 while (!list_empty(&dev->od_index_restore_list)) {
2528 struct lustre_index_restore_unit *liru;
2530 liru = list_entry(dev->od_index_restore_list.next,
2531 struct lustre_index_restore_unit,
2533 list_del(&liru->liru_link);
2535 osd_index_restore(info->oti_env, dev, liru,
2536 buf, INDEX_BACKUP_BUFSIZE);
2537 OBD_FREE(liru, liru->liru_len);
2541 OBD_FREE_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2547 char *osd_lf_fid2name(const struct lu_fid *fid)
2549 const struct osd_lf_map *map = osd_lf_maps;
2551 while (map->olm_name != NULL) {
2552 if (!lu_fid_eq(fid, &map->olm_fid)) {
2557 if (map->olm_flags & OLF_SHOW_NAME)
2558 return map->olm_name;
2566 /* OI scrub start/stop */
2568 int osd_scrub_start(const struct lu_env *env, struct osd_device *dev,
2571 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2575 if (dev->od_dt_dev.dd_rdonly)
2578 /* od_otable_mutex: prevent curcurrent start/stop */
2579 mutex_lock(&dev->od_otable_mutex);
2580 rc = scrub_start(osd_scrub_main, scrub, dev, flags);
2581 if (rc == -EALREADY) {
2583 if ((scrub->os_file.sf_flags & SF_AUTO ||
2584 scrub->os_partial_scan) &&
2585 !(flags & SS_AUTO_PARTIAL))
2586 osd_scrub_join(env, dev, flags, false);
2588 mutex_unlock(&dev->od_otable_mutex);
2593 void osd_scrub_stop(struct osd_device *dev)
2595 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2597 /* od_otable_mutex: prevent curcurrent start/stop */
2598 mutex_lock(&dev->od_otable_mutex);
2599 spin_lock(&scrub->os_lock);
2600 scrub->os_paused = 1;
2601 spin_unlock(&scrub->os_lock);
2603 mutex_unlock(&dev->od_otable_mutex);
2605 osd_scrub_ois_fini(scrub, &scrub->os_inconsistent_items);
2606 osd_scrub_ois_fini(scrub, &scrub->os_stale_items);
2609 /* OI scrub setup/cleanup */
2611 static const char osd_scrub_name[] = "OI_scrub";
2613 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev,
2616 struct osd_thread_info *info = osd_oti_get(env);
2617 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2618 struct lvfs_run_ctxt *ctxt = &dev->od_scrub.os_ctxt;
2619 time64_t interval = scrub->os_auto_scrub_interval;
2620 struct scrub_file *sf = &scrub->os_file;
2621 struct super_block *sb = osd_sb(dev);
2622 struct lvfs_run_ctxt saved;
2624 struct inode *inode;
2625 struct lu_fid *fid = &info->oti_fid;
2626 struct osd_inode_id *id = &info->oti_id;
2627 struct dt_object *obj;
2632 memset(&dev->od_scrub, 0, sizeof(struct osd_scrub));
2633 OBD_SET_CTXT_MAGIC(ctxt);
2634 ctxt->pwdmnt = dev->od_mnt;
2635 ctxt->pwd = dev->od_mnt->mnt_root;
2637 init_rwsem(&scrub->os_rwsem);
2638 spin_lock_init(&scrub->os_lock);
2639 INIT_LIST_HEAD(&scrub->os_inconsistent_items);
2640 INIT_LIST_HEAD(&scrub->os_stale_items);
2641 scrub->os_name = osd_name(dev);
2642 scrub->os_auto_scrub_interval = interval;
2644 push_ctxt(&saved, ctxt);
2645 filp = filp_open(osd_scrub_name,
2646 (dev->od_dt_dev.dd_rdonly ? O_RDONLY :
2650 pop_ctxt(&saved, ctxt);
2651 RETURN(PTR_ERR(filp));
2654 inode = file_inode(filp);
2655 ldiskfs_set_inode_flag(inode, LDISKFS_INODE_JOURNAL_DATA);
2656 if (!dev->od_dt_dev.dd_rdonly) {
2657 /* 'What the @fid is' is not imporatant, because the object
2658 * has no OI mapping, and only is visible inside the OSD.*/
2659 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2660 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
2662 filp_close(filp, NULL);
2663 pop_ctxt(&saved, ctxt);
2668 osd_id_gen(id, inode->i_ino, inode->i_generation);
2669 osd_add_oi_cache(info, dev, id, fid);
2670 filp_close(filp, NULL);
2671 pop_ctxt(&saved, ctxt);
2673 obj = lu2dt(lu_object_find_slice(env, osd2lu_dev(dev), fid, NULL));
2674 if (IS_ERR_OR_NULL(obj))
2675 RETURN(obj ? PTR_ERR(obj) : -ENOENT);
2677 guid_copy(&dev->od_uuid, (guid_t *)&sb->s_uuid);
2678 scrub->os_obj = obj;
2679 rc = scrub_file_load(env, scrub);
2680 if (rc == -ENOENT || rc == -EFAULT) {
2681 scrub_file_init(scrub, dev->od_uuid);
2682 /* If the "/O" dir does not exist when mount (indicated by
2683 * osd_device::od_maybe_new), neither for the "/OI_scrub",
2684 * then it is quite probably that the device is a new one,
2685 * under such case, mark it as SIF_NO_HANDLE_OLD_FID.
2687 * For the rare case that "/O" and "OI_scrub" both lost on
2688 * an old device, it can be found and cleared later.
2690 * For the system with "SIF_NO_HANDLE_OLD_FID", we do not
2691 * need to check "filter_fid_18_23" and to convert it to
2692 * "filter_fid" for each object, and all the IGIF should
2693 * have their FID mapping in OI files already. */
2694 if (dev->od_maybe_new && rc == -ENOENT)
2695 sf->sf_internal_flags = SIF_NO_HANDLE_OLD_FID;
2697 } else if (rc < 0) {
2698 GOTO(cleanup_obj, rc);
2700 if (!guid_equal(&sf->sf_uuid, &dev->od_uuid)) {
2702 "%s: UUID has been changed from %pU to %pU\n",
2703 osd_dev2name(dev), &sf->sf_uuid, &dev->od_uuid);
2704 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
2707 } else if (sf->sf_status == SS_SCANNING) {
2708 sf->sf_status = SS_CRASHED;
2712 if ((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) {
2713 LCONSOLE_WARN("%s: invalid oi count %d, set it to %d\n",
2714 osd_dev2name(dev), sf->sf_oi_count,
2716 sf->sf_oi_count = osd_oi_count;
2721 if (sf->sf_pos_last_checkpoint != 0)
2722 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
2724 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
2727 rc = scrub_file_store(env, scrub);
2729 GOTO(cleanup_obj, rc);
2732 /* Initialize OI files. */
2733 rc = osd_oi_init(info, dev, restored);
2735 GOTO(cleanup_obj, rc);
2737 if (!dev->od_dt_dev.dd_rdonly)
2738 osd_initial_OI_scrub(info, dev);
2740 if (sf->sf_flags & SF_UPGRADE ||
2741 !(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID ||
2742 sf->sf_success_count > 0)) {
2743 dev->od_igif_inoi = 0;
2744 dev->od_check_ff = dev->od_is_ost;
2746 dev->od_igif_inoi = 1;
2747 dev->od_check_ff = 0;
2750 if (sf->sf_flags & SF_INCONSISTENT)
2751 /* The 'od_igif_inoi' will be set under the
2753 * 1) new created system, or
2754 * 2) restored from file-level backup, or
2755 * 3) the upgrading completed.
2757 * The 'od_igif_inoi' may be cleared by OI scrub
2758 * later if found that the system is upgrading. */
2759 dev->od_igif_inoi = 1;
2761 if (!dev->od_dt_dev.dd_rdonly &&
2762 dev->od_scrub.os_scrub.os_auto_scrub_interval != AS_NEVER &&
2763 ((sf->sf_status == SS_PAUSED) ||
2764 (sf->sf_status == SS_CRASHED &&
2765 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2766 SF_UPGRADE | SF_AUTO)) ||
2767 (sf->sf_status == SS_INIT &&
2768 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2770 rc = osd_scrub_start(env, dev, SS_AUTO_FULL);
2773 GOTO(cleanup_oi, rc);
2775 /* it is possible that dcache entries may keep objects after they are
2776 * deleted by OSD. While it looks safe this can cause object data to
2777 * stay until umount causing failures in tests calculating free space,
2778 * e.g. replay-ost-single. Since those dcache entries are not used
2779 * anymore let's just free them after use here */
2780 shrink_dcache_sb(sb);
2784 osd_oi_fini(info, dev);
2786 dt_object_put_nocache(env, scrub->os_obj);
2787 scrub->os_obj = NULL;
2792 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
2794 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2796 LASSERT(dev->od_otable_it == NULL);
2798 if (scrub->os_obj != NULL) {
2799 osd_scrub_stop(dev);
2800 dt_object_put_nocache(env, scrub->os_obj);
2801 scrub->os_obj = NULL;
2805 /* object table based iteration APIs */
2807 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
2808 struct dt_object *dt, __u32 attr)
2810 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
2811 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
2812 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
2813 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2814 struct osd_otable_it *it;
2819 /* od_otable_mutex: prevent curcurrent init/fini */
2820 mutex_lock(&dev->od_otable_mutex);
2821 if (dev->od_otable_it != NULL)
2822 GOTO(out, it = ERR_PTR(-EALREADY));
2826 GOTO(out, it = ERR_PTR(-ENOMEM));
2828 dev->od_otable_it = it;
2830 it->ooi_cache.ooc_consumer_idx = -1;
2831 if (flags & DOIF_OUTUSED)
2832 it->ooi_used_outside = 1;
2834 if (flags & DOIF_RESET)
2837 if (valid & DOIV_ERROR_HANDLE) {
2838 if (flags & DOIF_FAILOUT)
2839 start |= SS_SET_FAILOUT;
2841 start |= SS_CLEAR_FAILOUT;
2844 if (valid & DOIV_DRYRUN) {
2845 if (flags & DOIF_DRYRUN)
2846 start |= SS_SET_DRYRUN;
2848 start |= SS_CLEAR_DRYRUN;
2851 rc = scrub_start(osd_scrub_main, scrub, dev, start & ~SS_AUTO_PARTIAL);
2852 if (rc == -EALREADY) {
2853 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2854 } else if (rc < 0) {
2855 dev->od_otable_it = NULL;
2859 /* We have to start from the begining. */
2860 it->ooi_cache.ooc_pos_preload =
2861 LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2867 mutex_unlock(&dev->od_otable_mutex);
2868 return (struct dt_it *)it;
2871 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2873 struct osd_otable_it *it = (struct osd_otable_it *)di;
2874 struct osd_device *dev = it->ooi_dev;
2876 /* od_otable_mutex: prevent curcurrent init/fini */
2877 mutex_lock(&dev->od_otable_mutex);
2878 scrub_stop(&dev->od_scrub.os_scrub);
2879 LASSERT(dev->od_otable_it == it);
2881 dev->od_otable_it = NULL;
2882 mutex_unlock(&dev->od_otable_mutex);
2886 static int osd_otable_it_get(const struct lu_env *env,
2887 struct dt_it *di, const struct dt_key *key)
2892 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2897 osd_otable_it_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
2899 spin_lock(&scrub->os_lock);
2900 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2901 scrub->os_waiting || !scrub->os_running)
2902 it->ooi_waiting = 0;
2904 it->ooi_waiting = 1;
2905 spin_unlock(&scrub->os_lock);
2907 return !it->ooi_waiting;
2910 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2912 struct osd_otable_it *it = (struct osd_otable_it *)di;
2913 struct osd_device *dev = it->ooi_dev;
2914 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2915 struct osd_otable_cache *ooc = &it->ooi_cache;
2919 LASSERT(it->ooi_user_ready);
2922 if (!scrub->os_running && !it->ooi_used_outside)
2925 if (ooc->ooc_cached_items > 0) {
2926 ooc->ooc_cached_items--;
2927 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2928 ~OSD_OTABLE_IT_CACHE_MASK;
2932 if (it->ooi_all_cached) {
2933 wait_var_event(scrub, !scrub->os_running);
2937 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2938 spin_lock(&scrub->os_lock);
2939 scrub->os_waiting = 0;
2941 spin_unlock(&scrub->os_lock);
2944 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2945 wait_var_event(scrub, osd_otable_it_wakeup(scrub, it));
2947 if (!scrub->os_running && !it->ooi_used_outside)
2950 rc = osd_otable_it_preload(env, it);
2957 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2958 const struct dt_it *di)
2963 static int osd_otable_it_key_size(const struct lu_env *env,
2964 const struct dt_it *di)
2966 return sizeof(__u64);
2969 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2970 struct dt_rec *rec, __u32 attr)
2972 struct osd_otable_it *it = (struct osd_otable_it *)di;
2973 struct osd_otable_cache *ooc = &it->ooi_cache;
2975 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2977 /* Filter out Invald FID already. */
2978 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2979 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2980 PFID((struct lu_fid *)rec),
2981 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2986 static __u64 osd_otable_it_store(const struct lu_env *env,
2987 const struct dt_it *di)
2989 struct osd_otable_it *it = (struct osd_otable_it *)di;
2990 struct osd_otable_cache *ooc = &it->ooi_cache;
2993 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2994 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2996 hash = ooc->ooc_pos_preload;
3001 * Set the OSD layer iteration start position as the specified hash.
3003 static int osd_otable_it_load(const struct lu_env *env,
3004 const struct dt_it *di, __u64 hash)
3006 struct osd_otable_it *it = (struct osd_otable_it *)di;
3007 struct osd_device *dev = it->ooi_dev;
3008 struct osd_otable_cache *ooc = &it->ooi_cache;
3009 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3010 struct osd_iit_param *param = &it->ooi_iit_param;
3014 /* Forbid to set iteration position after iteration started. */
3015 if (it->ooi_user_ready)
3018 LASSERT(!scrub->os_partial_scan);
3020 if (hash > OSD_OTABLE_MAX_HASH)
3021 hash = OSD_OTABLE_MAX_HASH;
3023 /* The hash is the last checkpoint position,
3024 * we will start from the next one. */
3025 ooc->ooc_pos_preload = hash + 1;
3026 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
3027 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
3029 it->ooi_user_ready = 1;
3030 if (!scrub->os_full_speed)
3033 memset(param, 0, sizeof(*param));
3034 param->sb = osd_sb(dev);
3035 param->start = ooc->ooc_pos_preload;
3036 param->bg = (ooc->ooc_pos_preload - 1) /
3037 LDISKFS_INODES_PER_GROUP(param->sb);
3038 param->offset = (ooc->ooc_pos_preload - 1) %
3039 LDISKFS_INODES_PER_GROUP(param->sb);
3040 param->gbase = 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
3042 /* Unplug OSD layer iteration by the first next() call. */
3043 rc = osd_otable_it_next(env, (struct dt_it *)it);
3048 static int osd_otable_it_key_rec(const struct lu_env *env,
3049 const struct dt_it *di, void *key_rec)
3054 const struct dt_index_operations osd_otable_ops = {
3056 .init = osd_otable_it_init,
3057 .fini = osd_otable_it_fini,
3058 .get = osd_otable_it_get,
3059 .put = osd_otable_it_put,
3060 .next = osd_otable_it_next,
3061 .key = osd_otable_it_key,
3062 .key_size = osd_otable_it_key_size,
3063 .rec = osd_otable_it_rec,
3064 .store = osd_otable_it_store,
3065 .load = osd_otable_it_load,
3066 .key_rec = osd_otable_it_key_rec,
3070 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
3072 struct osd_scrub *scrub = &dev->od_scrub;
3074 scrub_dump(m, &scrub->os_scrub);
3075 seq_printf(m, "lf_scanned: %llu\n"
3077 "lf_failed: %llu\n",
3078 scrub->os_lf_scanned,
3079 scrub->os_scrub.os_file.sf_param & SP_DRYRUN ?
3080 "inconsistent" : "repaired",
3081 scrub->os_lf_repaired,
3082 scrub->os_lf_failed);
3085 typedef int (*scan_dir_helper_t)(const struct lu_env *env,
3086 struct osd_device *dev, struct inode *dir,
3087 struct osd_it_ea *oie);
3089 static int osd_scan_dir(const struct lu_env *env, struct osd_device *dev,
3090 struct inode *inode, scan_dir_helper_t cb)
3092 struct osd_it_ea *oie;
3097 oie = osd_it_dir_init(env, dev, inode, LUDA_TYPE);
3099 RETURN(PTR_ERR(oie));
3101 oie->oie_file->f_pos = 0;
3102 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3108 while (oie->oie_it_dirent <= oie->oie_rd_dirent) {
3109 if (!name_is_dot_or_dotdot(oie->oie_dirent->oied_name,
3110 oie->oie_dirent->oied_namelen))
3111 cb(env, dev, inode, oie);
3113 oie->oie_dirent = (void *)oie->oie_dirent +
3114 round_up(sizeof(struct osd_it_ea_dirent) +
3115 oie->oie_dirent->oied_namelen, 8);
3117 oie->oie_it_dirent++;
3118 if (oie->oie_it_dirent <= oie->oie_rd_dirent)
3121 if (oie->oie_file->f_pos ==
3122 ldiskfs_get_htree_eof(oie->oie_file))
3125 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3134 osd_it_dir_fini(env, oie, inode);
3138 static int osd_remove_ml_file(struct osd_thread_info *info,
3139 struct osd_device *dev, struct inode *dir,
3140 struct inode *inode, struct osd_it_ea *oie)
3143 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3144 struct dentry dentry;
3149 if (scrub->os_file.sf_param & SP_DRYRUN)
3152 th = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
3153 osd_dto_credits_noquota[DTO_INDEX_DELETE] +
3154 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
3156 RETURN(PTR_ERR(th));
3158 /* Should be created by the VFS layer */
3159 dentry.d_inode = dir;
3160 dentry.d_sb = dir->i_sb;
3161 rc = osd_obj_del_entry(info, dev, &dentry, oie->oie_dirent->oied_name,
3162 oie->oie_dirent->oied_namelen, th);
3164 mark_inode_dirty(inode);
3165 ldiskfs_journal_stop(th);
3169 static int osd_scan_ml_file(const struct lu_env *env, struct osd_device *dev,
3170 struct inode *dir, struct osd_it_ea *oie)
3172 struct osd_thread_info *info = osd_oti_get(env);
3173 struct osd_inode_id id;
3174 struct inode *inode;
3175 struct osd_obj_seq *oseq;
3176 struct ost_id *ostid = &info->oti_ostid;
3177 struct lu_fid *fid = &oie->oie_dirent->oied_fid;
3183 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3185 if (!fid_is_sane(fid))
3186 inode = osd_iget_fid(info, dev, &id, fid);
3188 inode = osd_iget(info, dev, &id);
3191 RETURN(PTR_ERR(inode));
3193 fid_to_ostid(fid, ostid);
3194 oseq = osd_seq_load(info, dev, ostid_seq(ostid));
3196 RETURN(PTR_ERR(oseq));
3198 dirn = ostid_id(ostid) & (oseq->oos_subdir_count - 1);
3199 LASSERT(oseq->oos_dirs[dirn] != NULL);
3201 osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
3202 if (((strlen(oseq->oos_root->d_name.name) !=
3203 info->oti_seq_dirent->oied_namelen) ||
3204 strncmp(oseq->oos_root->d_name.name,
3205 info->oti_seq_dirent->oied_name,
3206 info->oti_seq_dirent->oied_namelen) != 0) ||
3207 ((strlen(oseq->oos_dirs[dirn]->d_name.name) !=
3208 info->oti_dir_dirent->oied_namelen) ||
3209 strncmp(oseq->oos_dirs[dirn]->d_name.name,
3210 info->oti_dir_dirent->oied_name,
3211 info->oti_dir_dirent->oied_namelen) != 0) ||
3212 ((strlen(name) != oie->oie_dirent->oied_namelen) ||
3213 strncmp(oie->oie_dirent->oied_name, name,
3214 oie->oie_dirent->oied_namelen) != 0)) {
3215 CDEBUG(D_LFSCK, "%s: the file O/%s/%s/%s is corrupted\n",
3216 osd_name(dev), info->oti_seq_dirent->oied_name,
3217 info->oti_dir_dirent->oied_name,
3218 oie->oie_dirent->oied_name);
3220 rc = osd_remove_ml_file(info, dev, dir, inode, oie);
3227 static int osd_scan_ml_file_dir(const struct lu_env *env,
3228 struct osd_device *dev, struct inode *dir,
3229 struct osd_it_ea *oie)
3231 struct osd_thread_info *info = osd_oti_get(env);
3232 struct inode *inode;
3233 struct osd_inode_id id;
3238 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3239 inode = osd_iget(info, dev, &id);
3241 RETURN(PTR_ERR(inode));
3243 if (!S_ISDIR(inode->i_mode))
3246 info->oti_dir_dirent = oie->oie_dirent;
3247 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file);
3248 info->oti_dir_dirent = NULL;
3255 static int osd_scan_ml_file_seq(const struct lu_env *env,
3256 struct osd_device *dev, struct inode *dir,
3257 struct osd_it_ea *oie)
3259 struct osd_thread_info *info = osd_oti_get(env);
3260 struct inode *inode;
3261 struct osd_inode_id id;
3266 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3267 inode = osd_iget(info, dev, &id);
3269 RETURN(PTR_ERR(inode));
3271 if (!S_ISDIR(inode->i_mode))
3274 info->oti_seq_dirent = oie->oie_dirent;
3275 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file_dir);
3276 info->oti_seq_dirent = NULL;
3283 static int osd_scan_ml_file_main(const struct lu_env *env,
3284 struct osd_device *dev)
3286 return osd_scan_dir(env, dev, dev->od_ost_map->om_root->d_inode,
3287 osd_scan_ml_file_seq);