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 bool osd_scrub_oi_resurrect(struct lustre_scrub *scrub,
142 const struct lu_fid *fid)
144 struct osd_inconsistent_item *oii;
145 bool resurrected = false;
147 if (list_empty(&scrub->os_stale_items))
150 spin_lock(&scrub->os_lock);
151 list_for_each_entry(oii, &scrub->os_stale_items, oii_list) {
152 if (lu_fid_eq(fid, &oii->oii_cache.oic_fid)) {
153 list_del(&oii->oii_list);
159 spin_unlock(&scrub->os_lock);
164 static void osd_scrub_ois_fini(struct lustre_scrub *scrub,
165 struct list_head *list)
167 struct osd_inconsistent_item *oii;
168 struct osd_inconsistent_item *tmp;
170 spin_lock(&scrub->os_lock);
171 list_for_each_entry_safe(oii, tmp, list, oii_list) {
172 list_del(&oii->oii_list);
175 spin_unlock(&scrub->os_lock);
178 static inline int osd_scrub_has_window(struct lustre_scrub *scrub,
179 struct osd_otable_cache *ooc)
181 return scrub->os_pos_current < ooc->ooc_pos_preload + SCRUB_WINDOW_SIZE;
185 * update/insert/delete the specified OI mapping (@fid @id) according to the ops
187 * \retval 1, changed nothing
188 * \retval 0, changed successfully
189 * \retval -ve, on error
191 int osd_scrub_refresh_mapping(struct osd_thread_info *info,
192 struct osd_device *dev,
193 const struct lu_fid *fid,
194 const struct osd_inode_id *id,
196 enum oi_check_flags flags, bool *exist)
202 if (dev->od_scrub.os_scrub.os_file.sf_param & SP_DRYRUN && !force)
205 /* DTO_INDEX_INSERT is enough for other two ops:
206 * delete/update, but save stack. */
207 th = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
208 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
211 CWARN("%s: fail to start trans for scrub op %d "
212 DFID" => %u/%u: rc = %d\n", osd_name(dev), ops,
213 PFID(fid), id ? id->oii_ino : -1, id ? id->oii_gen : -1,
219 case DTO_INDEX_UPDATE:
220 rc = osd_oi_update(info, dev, fid, id, th, flags);
221 if (unlikely(rc == -ENOENT)) {
222 /* Some unlink thread may removed the OI mapping. */
226 case DTO_INDEX_INSERT:
227 rc = osd_oi_insert(info, dev, fid, id, th, flags, exist);
228 if (unlikely(rc == -EEXIST)) {
230 /* XXX: There are trouble things when adding OI
231 * mapping for IGIF object, which may cause
232 * multiple objects to be mapped to the same
233 * IGIF formatted FID. Consider the following
236 * 1) The MDT is upgrading from 1.8 device.
237 * The OI scrub generates IGIF FID1 for the
238 * OBJ1 and adds the OI mapping.
240 * 2) For some reason, the OI scrub does not
241 * process all the IGIF objects completely.
243 * 3) The MDT is backuped and restored against
246 * 4) When the MDT mounts up, the OI scrub will
247 * try to rebuild the OI files. For some IGIF
248 * object, OBJ2, which was not processed by the
249 * OI scrub before the backup/restore, and the
250 * new generated IGIF formatted FID may be just
251 * the FID1, the same as OBJ1.
253 * Under such case, the OI scrub cannot know how
254 * to generate new FID for the OBJ2.
256 * Currently, we do nothing for that. One possible
257 * solution is to generate new normal FID for the
260 * Anyway, it is rare, only exists in theory. */
263 case DTO_INDEX_DELETE:
264 rc = osd_oi_delete(info, dev, fid, th, flags);
266 /* It is normal that the unlink thread has removed the
267 * OI mapping already. */
272 LASSERTF(0, "Unexpected ops %d\n", ops);
276 ldiskfs_journal_stop(th);
278 CDEBUG(D_LFSCK, "%s: fail to refresh OI map for scrub op %d "
279 DFID" => %u/%u: rc = %d\n", osd_name(dev), ops,
280 PFID(fid), id ? id->oii_ino : -1, id ? id->oii_gen : -1,
287 osd_scrub_check_update(struct osd_thread_info *info, struct osd_device *dev,
288 struct osd_idmap_cache *oic, int val)
290 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
291 struct scrub_file *sf = &scrub->os_file;
292 struct lu_fid *fid = &oic->oic_fid;
293 struct osd_inode_id *lid = &oic->oic_lid;
294 struct osd_inode_id *lid2 = &info->oti_id;
295 struct osd_inconsistent_item *oii = NULL;
296 struct inode *inode = NULL;
297 int ops = DTO_INDEX_UPDATE;
299 bool bad_inode = false;
304 down_write(&scrub->os_rwsem);
305 /* remove IDIF support to simplify logic */
306 if (val == SCRUB_NEXT_OSTOBJ_OLD)
307 GOTO(out, rc = -EOPNOTSUPP);
309 if (val == SCRUB_NEXT_OSTOBJ)
310 flags = OI_KNOWN_ON_OST;
312 scrub->os_new_checked++;
316 if (scrub->os_in_prior) {
317 oii = list_entry(oic, struct osd_inconsistent_item,
319 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_STALE))
320 GOTO(out, rc = -ESTALE);
323 if (lid->oii_ino < sf->sf_pos_latest_start && !oii)
325 if (lid->oii_ino < LDISKFS_FIRST_INO(osd_sb(dev)))
326 GOTO(out, rc = -ENOENT);
328 if (fid_is_igif(fid))
332 inode = osd_iget(info, dev, lid);
335 /* someone removed the inode. */
336 if (rc == -ENOENT || rc == -ESTALE)
340 } else if (val == SCRUB_NEXT_NOLMA) {
341 if (!scrub->os_convert_igif ||
342 CFS_FAIL_CHECK(OBD_FAIL_FID_NOLMA))
345 /* set LMA if missing */
346 sf->sf_flags |= SF_UPGRADE;
347 if (!(sf->sf_param & SP_DRYRUN)) {
348 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
354 /* checking existing mapping */
355 rc = osd_oi_lookup(info, dev, fid, lid2, flags);
357 /* insert if mapping doesn't exist */
359 ops = DTO_INDEX_INSERT;
360 else if (rc != -ESTALE)
366 if (val == SCRUB_NEXT_OSTOBJ)
367 sf->sf_flags |= SF_INCONSISTENT;
368 } else if (osd_id_eq(lid, lid2)) {
369 /* mapping matches */
371 /* delete mapping if it's stale */
372 rc = osd_scrub_refresh_mapping(info, dev, fid, lid,
373 DTO_INDEX_DELETE, false, flags, NULL);
375 "%s: delete stale OI "DFID" -> %u/%u: rc = %d\n",
376 osd_dev2name(dev), PFID(fid), lid->oii_ino,
381 struct inode *inode2;
384 /* mapping mismatch */
385 if (!scrub->os_partial_scan) {
386 spin_lock(&scrub->os_lock);
387 scrub->os_full_speed = 1;
388 spin_unlock(&scrub->os_lock);
390 sf->sf_flags |= SF_INCONSISTENT;
392 /* if new inode is bad, keep existing mapping */
396 /* verify existing mapping */
397 inode2 = osd_iget(info, dev, lid2);
398 if (IS_ERR(inode2)) {
399 rc = PTR_ERR(inode2);
400 if (rc == -ENOENT || rc == -ESTALE)
405 rc = osd_get_lma(info, inode2, &info->oti_obj_dentry,
406 &info->oti_ost_attrs);
414 /* if inode2 looks better, keep existing mapping */
415 fid2 = &info->oti_ost_attrs.loa_lma.lma_self_fid;
416 if ((rc == 0 && lu_fid_eq(fid, fid2)) &&
417 ((inode->i_size == 0 && inode2->i_size > 0 &&
418 inode_get_mtime_sec(inode) == inode_get_mtime_sec(inode2)) ||
419 inode_get_mtime_sec(inode) < inode_get_mtime_sec(inode2))) {
425 /* otherwise delete existing mapping */
426 CDEBUG(D_LFSCK, "%s: delete stale OI "DFID" -> %u/%u\n",
427 osd_dev2name(dev), PFID(fid), lid2->oii_ino,
429 rc = osd_scrub_refresh_mapping(info, dev, fid, lid2,
430 DTO_INDEX_DELETE, false, flags, NULL);
433 /* and then insert new one */
434 ops = DTO_INDEX_INSERT;
436 LASSERT(ops == DTO_INDEX_INSERT || ops == DTO_INDEX_UPDATE);
437 CDEBUG(D_LFSCK, "%s: %s OI "DFID" -> %u/%u\n",
438 osd_dev2name(dev), ops == DTO_INDEX_INSERT ? "insert" : "update",
439 PFID(fid), lid->oii_ino, lid->oii_gen);
440 rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops, false, flags,
443 if (scrub->os_in_prior)
444 sf->sf_items_updated_prior++;
446 sf->sf_items_updated++;
448 if (ops == DTO_INDEX_INSERT && val == 0 && !exist) {
449 int idx = osd_oi_fid2idx(dev, fid);
451 sf->sf_flags |= SF_RECREATED;
452 if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
453 ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
459 sf->sf_items_failed++;
460 if (lid->oii_ino >= LDISKFS_FIRST_INO(osd_sb(dev)) &&
461 (sf->sf_pos_first_inconsistent == 0 ||
462 sf->sf_pos_first_inconsistent > lid->oii_ino))
463 sf->sf_pos_first_inconsistent = lid->oii_ino;
465 if (!oii && !CFS_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_STALE)) {
466 if (osd_scrub_oi_resurrect(scrub, fid))
468 "%s: resurrect OI "DFID" -> %u/%u\n",
469 osd_dev2name(dev), PFID(fid),
470 lid->oii_ino, lid->oii_gen);
472 /* release fixed inconsistent item */
474 "%s: inconsistent OI "DFID" -> %u/%u %s\n",
475 osd_dev2name(dev), PFID(fid), lid->oii_ino,
476 lid->oii_gen, bad_inode ? "deleted" : "fixed");
477 spin_lock(&scrub->os_lock);
478 list_del_init(&oii->oii_list);
479 spin_unlock(&scrub->os_lock);
488 /* something strange with item, moving to stale */
489 osd_scrub_oi_mark_stale(scrub, oii);
491 "%s: fix inconsistent OI "DFID" -> %u/%u failed: %d\n",
492 osd_dev2name(dev), PFID(fid), lid->oii_ino,
495 up_write(&scrub->os_rwsem);
497 if (!IS_ERR_OR_NULL(inode))
500 RETURN(sf->sf_param & SP_FAILOUT ? rc : 0);
503 /* iteration engine */
505 typedef int (*osd_iit_next_policy)(struct osd_thread_info *info,
506 struct osd_device *dev,
507 struct osd_iit_param *param,
508 struct osd_idmap_cache **oic,
511 typedef int (*osd_iit_exec_policy)(struct osd_thread_info *info,
512 struct osd_device *dev,
513 struct osd_iit_param *param,
514 struct osd_idmap_cache *oic,
515 bool *noslot, int rc);
517 static int osd_iit_next(struct osd_iit_param *param, __u64 *pos)
522 param->offset = ldiskfs_find_next_bit(param->bitmap->b_data,
523 LDISKFS_INODES_PER_GROUP(param->sb), param->offset);
524 if (param->offset >= LDISKFS_INODES_PER_GROUP(param->sb)) {
525 *pos = 1 + (param->bg+1) * LDISKFS_INODES_PER_GROUP(param->sb);
526 return SCRUB_NEXT_BREAK;
529 offset = param->offset++;
530 if (unlikely(*pos == param->gbase + offset && *pos != param->start)) {
531 /* We should NOT find the same object more than once. */
532 CERROR("%s: scan the same object multiple times at the pos: "
533 "group = %u, base = %u, offset = %u, start = %u\n",
534 osd_sb2name(param->sb), (__u32)param->bg, param->gbase,
535 offset, param->start);
539 *pos = param->gbase + offset;
544 * \retval SCRUB_NEXT_OSTOBJ_OLD: FID-on-OST
545 * \retval 0: FID-on-MDT
547 static int osd_scrub_check_local_fldb(struct osd_thread_info *info,
548 struct osd_device *dev,
551 /* XXX: The initial OI scrub will scan the top level /O to generate
552 * a small local FLDB according to the <seq>. If the given FID
553 * is in the local FLDB, then it is FID-on-OST; otherwise it's
554 * quite possible for FID-on-MDT. */
556 return SCRUB_NEXT_OSTOBJ_OLD;
561 static int osd_scrub_get_fid(struct osd_thread_info *info,
562 struct osd_device *dev, struct inode *inode,
563 struct lu_fid *fid, bool scrub)
565 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
566 bool has_lma = false;
569 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
570 &info->oti_ost_attrs);
573 if (lma->lma_compat & LMAC_NOT_IN_OI ||
574 lma->lma_incompat & LMAI_AGENT)
575 return SCRUB_NEXT_CONTINUE;
577 *fid = lma->lma_self_fid;
581 if (lma->lma_compat & LMAC_FID_ON_OST)
582 return SCRUB_NEXT_OSTOBJ;
584 if (fid_is_idif(fid))
585 return SCRUB_NEXT_OSTOBJ_OLD;
587 /* For local object. */
588 if (fid_is_internal(fid))
591 /* For external visible MDT-object with non-normal FID. */
592 if (fid_is_namespace_visible(fid) && !fid_is_norm(fid))
595 /* For the object with normal FID, it may be MDT-object,
596 * or may be 2.4 OST-object, need further distinguish.
597 * Fall through to next section. */
600 if (rc == -ENODATA || rc == 0) {
601 rc = osd_get_idif(info, inode, &info->oti_obj_dentry, fid);
604 /* It is 2.3 or older OST-object. */
605 rc = SCRUB_NEXT_OSTOBJ_OLD;
611 /* It is FID-on-OST, but we do not know how
612 * to generate its FID, ignore it directly. */
613 rc = SCRUB_NEXT_CONTINUE;
615 /* It is 2.4 or newer OST-object. */
616 rc = SCRUB_NEXT_OSTOBJ_OLD;
624 if (dev->od_scrub.os_scrub.os_convert_igif) {
625 lu_igif_build(fid, inode->i_ino,
626 inode->i_generation);
628 rc = SCRUB_NEXT_NOLMA;
632 /* It may be FID-on-OST, or may be FID for
633 * non-MDT0, anyway, we do not know how to
634 * generate its FID, ignore it directly. */
635 rc = SCRUB_NEXT_CONTINUE;
640 /* For OI scrub case only: the object has LMA but has no ff
641 * (or ff crashed). It may be MDT-object, may be OST-object
642 * with crashed ff. The last check is local FLDB. */
643 rc = osd_scrub_check_local_fldb(info, dev, fid);
649 static int osd_iit_iget(struct osd_thread_info *info, struct osd_device *dev,
650 struct lu_fid *fid, struct osd_inode_id *lid, __u32 pos,
651 struct super_block *sb, bool scrub)
657 /* Not handle the backend root object and agent parent object.
658 * They are neither visible to namespace nor have OI mappings. */
659 if (unlikely(pos == osd_sb(dev)->s_root->d_inode->i_ino ||
660 is_remote_parent_ino(dev, pos)))
661 RETURN(SCRUB_NEXT_CONTINUE);
663 /* Skip project quota inode since it is greater than s_first_ino. */
664 #ifdef HAVE_PROJECT_QUOTA
665 if (ldiskfs_has_feature_project(sb) &&
666 pos == le32_to_cpu(LDISKFS_SB(sb)->s_es->s_prj_quota_inum))
667 RETURN(SCRUB_NEXT_CONTINUE);
670 osd_id_gen(lid, pos, OSD_OII_NOGEN);
671 inode = osd_iget(info, dev, lid);
674 /* The inode may be removed after bitmap searching, or the
675 * file is new created without inode initialized yet.
676 * LU-15754: After "new primitive: discard_new_inode()" change
677 * in the kernel find_inode_fast() returns -ESTALE, but
678 * iget_locked replaces it to the NULL and finally
679 * ldiskfs_inode_attach_jinode() returns -ENOMEM
680 * Let's skip an inode if -ENOMEM returned.
682 if (rc == -ENOENT || rc == -ESTALE || rc == -ENOMEM)
683 RETURN(SCRUB_NEXT_CONTINUE);
685 CDEBUG(D_LFSCK, "%s: fail to read inode, ino# = %u: "
686 "rc = %d\n", osd_dev2name(dev), pos, rc);
690 if (dev->od_is_ost && S_ISREG(inode->i_mode) && inode->i_nlink > 1)
691 dev->od_scrub.os_scrub.os_has_ml_file = 1;
694 ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB)) {
695 /* Only skip it for the first OI scrub accessing. */
696 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
697 GOTO(put, rc = SCRUB_NEXT_NOSCRUB);
700 rc = osd_scrub_get_fid(info, dev, inode, fid, scrub);
709 static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
710 struct osd_iit_param *param,
711 struct osd_idmap_cache **oic, const bool noslot)
713 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
715 struct osd_inode_id *lid;
718 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0)
719 wait_var_event_timeout(
721 !list_empty(&scrub->os_inconsistent_items) ||
722 kthread_should_stop(),
723 cfs_time_seconds(cfs_fail_val));
725 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_CRASH)) {
726 spin_lock(&scrub->os_lock);
727 scrub->os_running = 0;
728 spin_unlock(&scrub->os_lock);
729 return SCRUB_NEXT_CRASH;
732 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_FATAL))
733 return SCRUB_NEXT_FATAL;
735 if (kthread_should_stop())
736 return SCRUB_NEXT_EXIT;
738 if (!list_empty(&scrub->os_inconsistent_items)) {
739 spin_lock(&scrub->os_lock);
740 if (likely(!list_empty(&scrub->os_inconsistent_items))) {
741 struct osd_inconsistent_item *oii;
743 oii = list_first_entry(&scrub->os_inconsistent_items,
744 struct osd_inconsistent_item,
747 *oic = &oii->oii_cache;
748 scrub->os_in_prior = 1;
749 spin_unlock(&scrub->os_lock);
753 spin_unlock(&scrub->os_lock);
757 return SCRUB_NEXT_WAIT;
759 rc = osd_iit_next(param, &scrub->os_pos_current);
763 *oic = &dev->od_scrub.os_oic;
764 fid = &(*oic)->oic_fid;
765 lid = &(*oic)->oic_lid;
766 rc = osd_iit_iget(info, dev, fid, lid,
767 scrub->os_pos_current, param->sb, true);
771 static int osd_preload_next(struct osd_thread_info *info,
772 struct osd_device *dev, struct osd_iit_param *param,
773 struct osd_idmap_cache **oic, const bool noslot)
775 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
776 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
779 if (scrub->os_running &&
780 ooc->ooc_pos_preload >= scrub->os_pos_current)
781 return SCRUB_NEXT_EXIT;
783 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
787 rc = osd_iit_iget(info, dev,
788 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
789 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
790 ooc->ooc_pos_preload, param->sb, false);
795 osd_scrub_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
797 spin_lock(&scrub->os_lock);
798 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
799 !list_empty(&scrub->os_inconsistent_items) ||
800 it->ooi_waiting || kthread_should_stop())
801 scrub->os_waiting = 0;
803 scrub->os_waiting = 1;
804 spin_unlock(&scrub->os_lock);
806 return !scrub->os_waiting;
809 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
810 struct osd_iit_param *param,
811 struct osd_idmap_cache *oic, bool *noslot, int rc)
813 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
814 struct scrub_file *sf = &scrub->os_file;
815 struct osd_otable_it *it = dev->od_otable_it;
816 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
819 case SCRUB_NEXT_NOSCRUB:
820 down_write(&scrub->os_rwsem);
821 scrub->os_new_checked++;
822 sf->sf_items_noscrub++;
823 up_write(&scrub->os_rwsem);
824 case SCRUB_NEXT_CONTINUE:
825 case SCRUB_NEXT_WAIT:
829 rc = osd_scrub_check_update(info, dev, oic, rc);
831 spin_lock(&scrub->os_lock);
832 scrub->os_in_prior = 0;
833 spin_unlock(&scrub->os_lock);
837 rc = scrub_checkpoint(info->oti_env, scrub);
839 CDEBUG(D_LFSCK, "%s: fail to checkpoint, pos = %llu: "
840 "rc = %d\n", osd_scrub2name(scrub),
841 scrub->os_pos_current, rc);
842 /* Continue, as long as the scrub itself can go ahead. */
845 if (scrub->os_in_prior) {
846 spin_lock(&scrub->os_lock);
847 scrub->os_in_prior = 0;
848 spin_unlock(&scrub->os_lock);
853 if (it != NULL && it->ooi_waiting && ooc != NULL &&
854 ooc->ooc_pos_preload < scrub->os_pos_current) {
855 spin_lock(&scrub->os_lock);
858 spin_unlock(&scrub->os_lock);
861 if (rc == SCRUB_NEXT_CONTINUE)
864 if (scrub->os_full_speed || !ooc || osd_scrub_has_window(scrub, ooc)) {
870 wait_var_event(scrub, osd_scrub_wakeup(scrub, it));
872 if (!ooc || osd_scrub_has_window(scrub, ooc))
879 static int osd_preload_exec(struct osd_thread_info *info,
880 struct osd_device *dev, struct osd_iit_param *param,
881 struct osd_idmap_cache *oic, bool *noslot, int rc)
883 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
886 ooc->ooc_cached_items++;
887 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
888 ~OSD_OTABLE_IT_CACHE_MASK;
890 return rc > 0 ? 0 : rc;
893 #define SCRUB_IT_ALL 1
894 #define SCRUB_IT_CRASH 2
896 static void osd_scrub_join(const struct lu_env *env, struct osd_device *dev,
897 __u32 flags, bool inconsistent)
899 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
900 struct scrub_file *sf = &scrub->os_file;
904 LASSERT(!(flags & SS_AUTO_PARTIAL));
906 down_write(&scrub->os_rwsem);
907 spin_lock(&scrub->os_lock);
908 scrub->os_in_join = 1;
909 if (flags & SS_SET_FAILOUT)
910 sf->sf_param |= SP_FAILOUT;
911 else if (flags & SS_CLEAR_FAILOUT)
912 sf->sf_param &= ~SP_FAILOUT;
914 if (flags & SS_SET_DRYRUN)
915 sf->sf_param |= SP_DRYRUN;
916 else if (flags & SS_CLEAR_DRYRUN)
917 sf->sf_param &= ~SP_DRYRUN;
919 if (flags & SS_RESET) {
920 scrub_file_reset(scrub, dev->od_uuid,
921 inconsistent ? SF_INCONSISTENT : 0);
922 sf->sf_status = SS_SCANNING;
925 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
926 scrub->os_full_speed = 1;
928 scrub->os_full_speed = 0;
930 if (flags & SS_AUTO_FULL) {
931 sf->sf_flags |= SF_AUTO;
932 scrub->os_full_speed = 1;
934 spin_unlock(&scrub->os_lock);
936 scrub->os_new_checked = 0;
937 if (sf->sf_pos_last_checkpoint != 0)
938 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
940 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
942 scrub->os_pos_current = sf->sf_pos_latest_start;
943 sf->sf_time_latest_start = ktime_get_real_seconds();
944 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
945 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
946 rc = scrub_file_store(env, scrub);
948 spin_lock(&scrub->os_lock);
949 scrub->os_waiting = 0;
950 scrub->os_paused = 0;
951 scrub->os_partial_scan = 0;
952 scrub->os_in_join = 0;
953 scrub->os_full_scrub = 0;
954 spin_unlock(&scrub->os_lock);
956 up_write(&scrub->os_rwsem);
958 CDEBUG(D_LFSCK, "%s: joined in the OI scrub with flag %u: rc = %d\n",
959 osd_scrub2name(scrub), flags, rc);
964 static int osd_inode_iteration(struct osd_thread_info *info,
965 struct osd_device *dev, __u32 max, bool preload)
967 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
968 struct scrub_file *sf = &scrub->os_file;
969 osd_iit_next_policy next;
970 osd_iit_exec_policy exec;
973 struct osd_iit_param *param;
982 param = &dev->od_scrub.os_iit_param;
983 memset(param, 0, sizeof(*param));
984 param->sb = osd_sb(dev);
986 while (scrub->os_partial_scan && !scrub->os_in_join) {
987 struct osd_idmap_cache *oic = NULL;
989 rc = osd_scrub_next(info, dev, param, &oic, noslot);
991 case SCRUB_NEXT_EXIT:
993 case SCRUB_NEXT_CRASH:
994 RETURN(SCRUB_IT_CRASH);
995 case SCRUB_NEXT_FATAL:
997 case SCRUB_NEXT_WAIT: {
998 struct kstatfs *ksfs = &info->oti_ksfs;
1001 if (dev->od_full_scrub_ratio == OFSR_NEVER ||
1002 unlikely(sf->sf_items_updated_prior == 0))
1005 if (dev->od_full_scrub_ratio == OFSR_DIRECTLY ||
1006 scrub->os_full_scrub) {
1007 osd_scrub_join(info->oti_env, dev,
1008 SS_AUTO_FULL | SS_RESET, true);
1012 rc = param->sb->s_op->statfs(param->sb->s_root, ksfs);
1014 __u64 used = ksfs->f_files - ksfs->f_ffree;
1016 used = div64_u64(used, sf->sf_items_updated_prior);
1017 /* If we hit too much inconsistent OI
1018 * mappings during the partial scan,
1019 * then scan the device completely. */
1020 if (used < dev->od_full_scrub_ratio) {
1021 osd_scrub_join(info->oti_env, dev,
1022 SS_AUTO_FULL | SS_RESET, true);
1028 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) &&
1032 saved_flags = sf->sf_flags;
1033 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
1034 SF_UPGRADE | SF_AUTO);
1035 sf->sf_status = SS_COMPLETED;
1038 kthread_should_stop() ||
1039 !scrub->os_partial_scan ||
1040 scrub->os_in_join ||
1041 !list_empty(&scrub->os_inconsistent_items));
1042 sf->sf_flags = saved_flags;
1043 sf->sf_status = SS_SCANNING;
1045 if (kthread_should_stop())
1048 if (!scrub->os_partial_scan || scrub->os_in_join)
1054 LASSERTF(rc == 0, "rc = %d\n", rc);
1056 osd_scrub_exec(info, dev, param, oic, &noslot, rc);
1063 wait_var_event(scrub,
1064 kthread_should_stop() ||
1065 !scrub->os_in_join);
1067 if (kthread_should_stop())
1073 next = osd_scrub_next;
1074 exec = osd_scrub_exec;
1075 pos = &scrub->os_pos_current;
1076 count = &scrub->os_new_checked;
1077 param->start = *pos;
1078 param->bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param->sb);
1080 (*pos - 1) % LDISKFS_INODES_PER_GROUP(param->sb);
1082 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1084 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1086 next = osd_preload_next;
1087 exec = osd_preload_exec;
1088 pos = &ooc->ooc_pos_preload;
1089 count = &ooc->ooc_cached_items;
1090 param = &dev->od_otable_it->ooi_iit_param;
1094 limit = le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count);
1095 while (*pos <= limit && *count < max) {
1096 struct ldiskfs_group_desc *desc;
1097 bool next_group = false;
1099 desc = ldiskfs_get_group_desc(param->sb, param->bg, NULL);
1103 if (desc->bg_flags & cpu_to_le16(LDISKFS_BG_INODE_UNINIT)) {
1108 param->bitmap = ldiskfs_read_inode_bitmap(param->sb, param->bg);
1109 if (IS_ERR_OR_NULL(param->bitmap)) {
1110 if (param->bitmap) {
1111 rc = PTR_ERR(param->bitmap);
1112 param->bitmap = NULL;
1116 CERROR("%s: fail to read bitmap for %u, scrub will stop, urgent mode: rc = %d\n",
1117 osd_scrub2name(scrub), (__u32)param->bg, rc);
1122 struct osd_idmap_cache *oic = NULL;
1125 ldiskfs_itable_unused_count(param->sb, desc) >=
1126 LDISKFS_INODES_PER_GROUP(param->sb)) {
1131 rc = next(info, dev, param, &oic, noslot);
1133 case SCRUB_NEXT_BREAK:
1136 case SCRUB_NEXT_EXIT:
1137 brelse(param->bitmap);
1139 case SCRUB_NEXT_CRASH:
1140 brelse(param->bitmap);
1141 RETURN(SCRUB_IT_CRASH);
1142 case SCRUB_NEXT_FATAL:
1143 brelse(param->bitmap);
1147 rc = exec(info, dev, param, oic, &noslot, rc);
1148 } while (!rc && *pos <= limit && *count < max);
1151 if (param->bitmap) {
1152 brelse(param->bitmap);
1153 param->bitmap = NULL;
1163 param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1164 *pos = param->gbase;
1165 param->start = *pos;
1170 RETURN(SCRUB_IT_ALL);
1176 static int osd_otable_it_preload(const struct lu_env *env,
1177 struct osd_otable_it *it)
1179 struct osd_device *dev = it->ooi_dev;
1180 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1181 struct osd_otable_cache *ooc = &it->ooi_cache;
1185 rc = osd_inode_iteration(osd_oti_get(env), dev,
1186 OSD_OTABLE_IT_CACHE_SIZE, true);
1187 if (rc == SCRUB_IT_ALL)
1188 it->ooi_all_cached = 1;
1190 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1191 spin_lock(&scrub->os_lock);
1192 scrub->os_waiting = 0;
1194 spin_unlock(&scrub->os_lock);
1197 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1200 static int osd_scan_ml_file_main(const struct lu_env *env,
1201 struct osd_device *dev);
1203 static int osd_scrub_main(void *args)
1206 struct osd_device *dev = (struct osd_device *)args;
1207 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1211 rc = lu_env_init(&env, LCT_LOCAL | LCT_DT_THREAD);
1213 CDEBUG(D_LFSCK, "%s: OI scrub fail to init env: rc = %d\n",
1214 osd_scrub2name(scrub), rc);
1218 rc = scrub_thread_prep(&env, scrub, dev->od_uuid,
1219 LDISKFS_FIRST_INO(osd_sb(dev)) + 1);
1221 CDEBUG(D_LFSCK, "%s: OI scrub fail to scrub prep: rc = %d\n",
1222 osd_scrub2name(scrub), rc);
1226 if (!scrub->os_full_speed && !scrub->os_partial_scan) {
1227 struct osd_otable_it *it = dev->od_otable_it;
1228 struct osd_otable_cache *ooc = &it->ooi_cache;
1230 wait_var_event(scrub,
1231 it->ooi_user_ready || kthread_should_stop());
1232 if (kthread_should_stop())
1235 scrub->os_pos_current = ooc->ooc_pos_preload;
1238 CDEBUG(D_LFSCK, "%s: OI scrub start, flags = 0x%x, pos = %llu%s\n",
1239 osd_scrub2name(scrub), scrub->os_start_flags,
1240 scrub->os_pos_current,
1241 scrub->os_file.sf_param & SP_DRYRUN ? " dryrun mode" : "");
1243 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1244 if (unlikely(rc == SCRUB_IT_CRASH)) {
1245 spin_lock(&scrub->os_lock);
1246 scrub->os_running = 0;
1247 spin_unlock(&scrub->os_lock);
1248 GOTO(out, rc = -EINVAL);
1251 if (scrub->os_has_ml_file) {
1252 ret = osd_scan_ml_file_main(&env, dev);
1261 dev->od_igif_inoi = 1;
1262 dev->od_check_ff = 0;
1264 rc = scrub_thread_post(&env, &dev->od_scrub.os_scrub, rc);
1265 CDEBUG(D_LFSCK, "%s: OI scrub: stop, pos = %llu: rc = %d%s\n",
1266 osd_scrub2name(scrub), scrub->os_pos_current, rc,
1267 scrub->os_file.sf_param & SP_DRYRUN ? " dryrun mode" : "");
1271 osd_scrub_ois_fini(scrub, &scrub->os_inconsistent_items);
1275 spin_lock(&scrub->os_lock);
1276 scrub->os_running = 0;
1277 spin_unlock(&scrub->os_lock);
1278 if (xchg(&scrub->os_task, NULL) == NULL)
1279 /* scrub_stop() is waiting, we need to synchronize */
1280 wait_var_event(scrub, kthread_should_stop());
1285 /* initial OI scrub */
1287 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1288 struct dentry *, filldir_t filldir);
1290 #ifdef HAVE_FILLDIR_USE_CTX
1292 osd_ios_varfid_fill(struct dir_context *buf, const char *name, int namelen,
1293 loff_t offset, __u64 ino, unsigned int d_type);
1296 osd_ios_lf_fill(struct dir_context *buf, const char *name, int namelen,
1297 loff_t offset, __u64 ino, unsigned int d_type);
1300 osd_ios_dl_fill(struct dir_context *buf, const char *name, int namelen,
1301 loff_t offset, __u64 ino, unsigned int d_type);
1304 osd_ios_uld_fill(struct dir_context *buf, const char *name, int namelen,
1305 loff_t offset, __u64 ino, unsigned int d_type);
1307 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1308 loff_t offset, __u64 ino, unsigned int d_type);
1309 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1310 loff_t offset, __u64 ino, unsigned int d_type);
1311 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1312 loff_t offset, __u64 ino, unsigned int d_type);
1313 static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
1314 loff_t offset, __u64 ino, unsigned int d_type);
1318 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1319 struct dentry *dentry, filldir_t filldir);
1321 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1322 struct dentry *dentry, filldir_t filldir);
1325 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1326 struct dentry *dentry, filldir_t filldir);
1330 struct lu_fid olm_fid;
1333 scandir_t olm_scandir;
1334 filldir_t olm_filldir;
1337 /* Add the new introduced local files in the list in the future. */
1338 static const struct osd_lf_map osd_lf_maps[] = {
1341 .olm_name = CATLIST,
1343 .f_seq = FID_SEQ_LOCAL_FILE,
1344 .f_oid = LLOG_CATALOGS_OID,
1346 .olm_flags = OLF_SHOW_NAME,
1347 .olm_namelen = sizeof(CATLIST) - 1,
1352 .olm_name = MOUNT_CONFIGS_DIR,
1354 .f_seq = FID_SEQ_LOCAL_FILE,
1355 .f_oid = MGS_CONFIGS_OID,
1357 .olm_flags = OLF_SCAN_SUBITEMS,
1358 .olm_namelen = sizeof(MOUNT_CONFIGS_DIR) - 1,
1359 .olm_scandir = osd_ios_general_scan,
1360 .olm_filldir = osd_ios_varfid_fill,
1363 /* NIDTBL_VERSIONS */
1365 .olm_name = MGS_NIDTBL_DIR,
1366 .olm_flags = OLF_SCAN_SUBITEMS,
1367 .olm_namelen = sizeof(MGS_NIDTBL_DIR) - 1,
1368 .olm_scandir = osd_ios_general_scan,
1369 .olm_filldir = osd_ios_varfid_fill,
1374 .olm_name = MDT_ORPHAN_DIR,
1375 .olm_namelen = sizeof(MDT_ORPHAN_DIR) - 1,
1382 .f_seq = FID_SEQ_ROOT,
1383 .f_oid = FID_OID_ROOT,
1385 .olm_flags = OLF_SCAN_SUBITEMS | OLF_HIDE_FID,
1386 .olm_namelen = sizeof("ROOT") - 1,
1387 .olm_scandir = osd_ios_ROOT_scan,
1390 /* changelog_catalog */
1392 .olm_name = CHANGELOG_CATALOG,
1393 .olm_namelen = sizeof(CHANGELOG_CATALOG) - 1,
1396 /* changelog_users */
1398 .olm_name = CHANGELOG_USERS,
1399 .olm_namelen = sizeof(CHANGELOG_USERS) - 1,
1406 .f_seq = FID_SEQ_LOCAL_FILE,
1407 .f_oid = FLD_INDEX_OID,
1409 .olm_flags = OLF_SHOW_NAME,
1410 .olm_namelen = sizeof("fld") - 1,
1415 .olm_name = LAST_RCVD,
1417 .f_seq = FID_SEQ_LOCAL_FILE,
1418 .f_oid = LAST_RECV_OID,
1420 .olm_flags = OLF_SHOW_NAME,
1421 .olm_namelen = sizeof(LAST_RCVD) - 1,
1426 .olm_name = REPLY_DATA,
1428 .f_seq = FID_SEQ_LOCAL_FILE,
1429 .f_oid = REPLY_DATA_OID,
1431 .olm_flags = OLF_SHOW_NAME,
1432 .olm_namelen = sizeof(REPLY_DATA) - 1,
1437 .olm_name = LOV_OBJID,
1439 .f_seq = FID_SEQ_LOCAL_FILE,
1440 .f_oid = MDD_LOV_OBJ_OID,
1442 .olm_flags = OLF_SHOW_NAME,
1443 .olm_namelen = sizeof(LOV_OBJID) - 1,
1448 .olm_name = LOV_OBJSEQ,
1450 .f_seq = FID_SEQ_LOCAL_FILE,
1451 .f_oid = MDD_LOV_OBJ_OSEQ,
1453 .olm_flags = OLF_SHOW_NAME,
1454 .olm_namelen = sizeof(LOV_OBJSEQ) - 1,
1459 .olm_name = QMT_DIR,
1460 .olm_flags = OLF_SCAN_SUBITEMS,
1461 .olm_namelen = sizeof(QMT_DIR) - 1,
1462 .olm_scandir = osd_ios_general_scan,
1463 .olm_filldir = osd_ios_varfid_fill,
1468 .olm_name = QSD_DIR,
1469 .olm_flags = OLF_SCAN_SUBITEMS,
1470 .olm_namelen = sizeof(QSD_DIR) - 1,
1471 .olm_scandir = osd_ios_general_scan,
1472 .olm_filldir = osd_ios_varfid_fill,
1477 .olm_name = "seq_ctl",
1479 .f_seq = FID_SEQ_LOCAL_FILE,
1480 .f_oid = FID_SEQ_CTL_OID,
1482 .olm_flags = OLF_SHOW_NAME,
1483 .olm_namelen = sizeof("seq_ctl") - 1,
1488 .olm_name = "seq_srv",
1490 .f_seq = FID_SEQ_LOCAL_FILE,
1491 .f_oid = FID_SEQ_SRV_OID,
1493 .olm_flags = OLF_SHOW_NAME,
1494 .olm_namelen = sizeof("seq_srv") - 1,
1499 .olm_name = HEALTH_CHECK,
1501 .f_seq = FID_SEQ_LOCAL_FILE,
1502 .f_oid = OFD_HEALTH_CHECK_OID,
1504 .olm_flags = OLF_SHOW_NAME,
1505 .olm_namelen = sizeof(HEALTH_CHECK) - 1,
1510 .olm_name = LFSCK_DIR,
1511 .olm_flags = OLF_SCAN_SUBITEMS,
1512 .olm_namelen = sizeof(LFSCK_DIR) - 1,
1513 .olm_scandir = osd_ios_general_scan,
1514 .olm_filldir = osd_ios_varfid_fill,
1517 /* lfsck_bookmark */
1519 .olm_name = LFSCK_BOOKMARK,
1520 .olm_namelen = sizeof(LFSCK_BOOKMARK) - 1,
1525 .olm_name = LFSCK_LAYOUT,
1526 .olm_namelen = sizeof(LFSCK_LAYOUT) - 1,
1529 /* lfsck_namespace */
1531 .olm_name = LFSCK_NAMESPACE,
1532 .olm_namelen = sizeof(LFSCK_NAMESPACE) - 1,
1535 /* OBJECTS, upgrade from old device */
1537 .olm_name = OBJECTS,
1538 .olm_flags = OLF_SCAN_SUBITEMS,
1539 .olm_namelen = sizeof(OBJECTS) - 1,
1540 .olm_scandir = osd_ios_OBJECTS_scan,
1543 /* lquota_v2.user, upgrade from old device */
1545 .olm_name = "lquota_v2.user",
1546 .olm_namelen = sizeof("lquota_v2.user") - 1,
1549 /* lquota_v2.group, upgrade from old device */
1551 .olm_name = "lquota_v2.group",
1552 .olm_namelen = sizeof("lquota_v2.group") - 1,
1555 /* LAST_GROUP, upgrade from old device */
1557 .olm_name = "LAST_GROUP",
1559 .f_seq = FID_SEQ_LOCAL_FILE,
1560 .f_oid = OFD_LAST_GROUP_OID,
1562 .olm_flags = OLF_SHOW_NAME,
1563 .olm_namelen = sizeof("LAST_GROUP") - 1,
1566 /* committed batchid for cross-MDT operation */
1568 .olm_name = "BATCHID",
1570 .f_seq = FID_SEQ_LOCAL_FILE,
1571 .f_oid = BATCHID_COMMITTED_OID,
1573 .olm_flags = OLF_SHOW_NAME,
1574 .olm_namelen = sizeof("BATCHID") - 1,
1577 /* OSP update logs update_log{_dir} use f_seq = FID_SEQ_UPDATE_LOG{_DIR}
1578 * and f_oid = index for their log files. See lu_update_log{_dir}_fid()
1579 * for more details. */
1583 .olm_name = "update_log",
1585 .f_seq = FID_SEQ_UPDATE_LOG,
1587 .olm_flags = OLF_SHOW_NAME | OLF_IDX_IN_FID,
1588 .olm_namelen = sizeof("update_log") - 1,
1591 /* update_log_dir */
1593 .olm_name = "update_log_dir",
1595 .f_seq = FID_SEQ_UPDATE_LOG_DIR,
1597 .olm_flags = OLF_SHOW_NAME | OLF_SCAN_SUBITEMS |
1599 .olm_namelen = sizeof("update_log_dir") - 1,
1600 .olm_scandir = osd_ios_general_scan,
1601 .olm_filldir = osd_ios_uld_fill,
1606 .olm_name = "lost+found",
1608 .f_seq = FID_SEQ_LOCAL_FILE,
1609 .f_oid = OSD_LPF_OID,
1611 .olm_flags = OLF_SCAN_SUBITEMS,
1612 .olm_namelen = sizeof("lost+found") - 1,
1613 .olm_scandir = osd_ios_general_scan,
1614 .olm_filldir = osd_ios_lf_fill,
1619 .olm_name = HSM_ACTIONS,
1624 .olm_name = LUSTRE_NODEMAP_NAME,
1629 .olm_name = INDEX_BACKUP_DIR,
1631 .f_seq = FID_SEQ_LOCAL_FILE,
1632 .f_oid = INDEX_BACKUP_OID,
1634 .olm_flags = OLF_SCAN_SUBITEMS | OLF_NOT_BACKUP,
1635 .olm_namelen = sizeof(INDEX_BACKUP_DIR) - 1,
1636 .olm_scandir = osd_ios_general_scan,
1637 .olm_filldir = osd_ios_varfid_fill,
1645 /* Add the new introduced files under .lustre/ in the list in the future. */
1646 static const struct osd_lf_map osd_dl_maps[] = {
1651 .f_seq = FID_SEQ_DOT_LUSTRE,
1652 .f_oid = FID_OID_DOT_LUSTRE_OBF,
1654 .olm_namelen = sizeof("fid") - 1,
1657 /* .lustre/lost+found */
1659 .olm_name = "lost+found",
1661 .f_seq = FID_SEQ_DOT_LUSTRE,
1662 .f_oid = FID_OID_DOT_LUSTRE_LPF,
1664 .olm_namelen = sizeof("lost+found") - 1,
1672 struct osd_ios_item {
1673 struct list_head oii_list;
1674 struct dentry *oii_dentry;
1675 scandir_t oii_scandir;
1676 filldir_t oii_filldir;
1679 struct osd_ios_filldir_buf {
1680 /* please keep it as first member */
1681 struct dir_context ctx;
1682 struct osd_thread_info *oifb_info;
1683 struct osd_device *oifb_dev;
1684 struct dentry *oifb_dentry;
1689 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1690 scandir_t scandir, filldir_t filldir)
1692 struct osd_ios_item *item;
1695 OBD_ALLOC_PTR(item);
1699 INIT_LIST_HEAD(&item->oii_list);
1700 item->oii_dentry = dget(dentry);
1701 item->oii_scandir = scandir;
1702 item->oii_filldir = filldir;
1703 list_add_tail(&item->oii_list, &dev->od_ios_list);
1708 static bool osd_index_need_recreate(const struct lu_env *env,
1709 struct osd_device *dev, struct inode *inode)
1711 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1712 struct iam_container *bag = &iam->od_container;
1716 rc = iam_container_init(bag, &iam->od_descr, inode);
1720 rc = iam_container_setup(bag);
1721 iam_container_fini(bag);
1728 static void osd_ios_index_register(const struct lu_env *env,
1729 struct osd_device *osd,
1730 const struct lu_fid *fid,
1731 struct inode *inode)
1733 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1734 struct iam_container *bag = &iam->od_container;
1735 struct super_block *sb = osd_sb(osd);
1736 struct iam_descr *descr;
1742 /* Index must be a regular file. */
1743 if (!S_ISREG(inode->i_mode))
1746 /* Index's size must be block aligned. */
1747 if (inode->i_size < sb->s_blocksize ||
1748 (inode->i_size & (sb->s_blocksize - 1)) != 0)
1751 iam_container_init(bag, &iam->od_descr, inode);
1752 rc = iam_container_setup(bag);
1756 descr = bag->ic_descr;
1757 /* May be regular file with IAM_LFIX_ROOT_MAGIC matched
1758 * coincidentally, or corrupted index object, skip it. */
1759 if (descr->id_ptr_size != 4)
1762 keysize = descr->id_key_size;
1763 recsize = descr->id_rec_size;
1764 rc = osd_index_register(osd, fid, keysize, recsize);
1769 iam_container_fini(bag);
1771 CDEBUG(D_LFSCK, "%s: index object "DFID" (%u/%u) registered\n",
1772 osd_name(osd), PFID(fid), keysize, recsize);
1775 static void osd_index_restore(const struct lu_env *env, struct osd_device *dev,
1776 struct lustre_index_restore_unit *liru,
1777 void *buf, int bufsize)
1779 struct osd_thread_info *info = osd_oti_get(env);
1780 struct osd_inode_id *id = &info->oti_id;
1781 struct lu_fid *tgt_fid = &liru->liru_cfid;
1782 struct inode *bak_inode = NULL;
1783 struct ldiskfs_dir_entry_2 *de = NULL;
1784 struct buffer_head *bh = NULL;
1785 struct dentry *dentry;
1787 struct lu_fid bak_fid;
1791 lustre_fid2lbx(name, tgt_fid, bufsize);
1792 dentry = osd_child_dentry_by_inode(env, dev->od_index_backup_inode,
1793 name, strlen(name));
1794 bh = osd_ldiskfs_find_entry(dev->od_index_backup_inode,
1795 &dentry->d_name, &de, NULL, NULL);
1797 GOTO(log, rc = PTR_ERR(bh));
1799 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
1801 bak_inode = osd_iget_fid(info, dev, id, &bak_fid);
1802 if (IS_ERR(bak_inode))
1803 GOTO(log, rc = PTR_ERR(bak_inode));
1806 /* The OI mapping for index may be invalid, since it will be
1807 * re-created, not update the OI mapping, just cache it in RAM. */
1808 osd_id_gen(id, liru->liru_clid, OSD_OII_NOGEN);
1809 osd_add_oi_cache(info, dev, id, tgt_fid);
1810 rc = lustre_index_restore(env, &dev->od_dt_dev, &liru->liru_pfid,
1811 tgt_fid, &bak_fid, liru->liru_name,
1812 &dev->od_index_backup_list, &dev->od_lock,
1817 CDEBUG(D_WARNING, "%s: restore index '%s' with "DFID": rc = %d\n",
1818 osd_name(dev), liru->liru_name, PFID(tgt_fid), rc);
1822 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1824 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1825 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1826 * reference the inode, or fixed if it is missing or references another inode.
1829 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1830 struct inode *parent, struct inode *inode,
1831 const struct lu_fid *fid, const char *name,
1832 int namelen, int flags)
1834 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1835 struct osd_inode_id *id = &info->oti_id;
1836 struct osd_inode_id *id2 = &info->oti_id2;
1837 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1838 struct scrub_file *sf = &scrub->os_file;
1844 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode: rc = -2\n",
1845 osd_name(dev), namelen, name);
1849 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
1850 &info->oti_ost_attrs);
1851 if (rc != 0 && rc != -ENODATA) {
1852 CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
1853 "rc = %d\n", osd_name(dev), rc);
1858 osd_id_gen(id, inode->i_ino, inode->i_generation);
1859 if (rc == -ENODATA) {
1860 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID) {
1861 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1864 if (flags & OLF_IDX_IN_FID) {
1865 LASSERT(dev->od_index >= 0);
1867 tfid.f_oid = dev->od_index;
1870 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1872 CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
1873 "scrub: rc = %d\n", osd_name(dev), rc);
1878 if (lma->lma_compat & LMAC_NOT_IN_OI)
1881 tfid = lma->lma_self_fid;
1882 if (lma->lma_compat & LMAC_IDX_BACKUP &&
1883 osd_index_need_recreate(info->oti_env, dev, inode)) {
1884 struct lu_fid *pfid = &info->oti_fid3;
1886 if (is_root_inode(parent)) {
1887 lu_local_obj_fid(pfid, OSD_FS_ROOT_OID);
1889 rc = osd_scrub_get_fid(info, dev, parent, pfid,
1895 rc = lustre_liru_new(&dev->od_index_restore_list, pfid,
1896 &tfid, inode->i_ino, name, namelen);
1901 if (!(flags & OLF_NOT_BACKUP))
1902 osd_ios_index_register(info->oti_env, dev, &tfid,
1906 /* Since this called from iterate_dir() the inode lock will be taken */
1907 rc = osd_oi_lookup(info, dev, &tfid, id2, OI_LOCKED);
1912 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1913 DTO_INDEX_INSERT, true, 0, NULL);
1920 if (osd_id_eq_strict(id, id2))
1923 if (!(sf->sf_flags & SF_INCONSISTENT)) {
1924 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
1925 rc = scrub_file_store(info->oti_env, scrub);
1930 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1931 DTO_INDEX_UPDATE, true, 0, NULL);
1939 * It scans the /lost+found, and for the OST-object (with filter_fid
1940 * or filter_fid_18_23), move them back to its proper /O/<seq>/d<x>.
1942 #ifdef HAVE_FILLDIR_USE_CTX
1943 static FILLDIR_TYPE do_osd_ios_lf_fill(struct dir_context *buf,
1945 static int osd_ios_lf_fill(void *buf,
1947 const char *name, int namelen,
1948 loff_t offset, __u64 ino, unsigned int d_type)
1950 struct osd_ios_filldir_buf *fill_buf =
1951 (struct osd_ios_filldir_buf *)buf;
1952 struct osd_thread_info *info = fill_buf->oifb_info;
1953 struct osd_device *dev = fill_buf->oifb_dev;
1954 struct lu_fid *fid = &info->oti_fid;
1955 struct osd_scrub *scrub = &dev->od_scrub;
1956 struct dentry *parent = fill_buf->oifb_dentry;
1957 struct dentry *child;
1958 struct inode *dir = parent->d_inode;
1959 struct inode *inode;
1963 fill_buf->oifb_items++;
1965 /* skip any '.' started names */
1969 scrub->os_lf_scanned++;
1970 child = osd_lookup_one_len(dev, name, parent, namelen);
1971 if (IS_ERR(child)) {
1972 rc = PTR_ERR(child);
1973 CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
1974 osd_name(dev), namelen, name, rc);
1976 } else if (!child->d_inode) {
1978 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode\n",
1979 osd_name(dev), namelen, name);
1983 inode = child->d_inode;
1984 if (S_ISDIR(inode->i_mode)) {
1985 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
1988 CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
1989 "rc = %d\n", osd_name(dev), namelen, name, rc);
1993 if (!S_ISREG(inode->i_mode))
1996 rc = osd_scrub_get_fid(info, dev, inode, fid, true);
1997 if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
1998 rc = osd_obj_map_recover(info, dev, dir, child, fid);
2000 CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
2001 "/lost+found.\n", namelen, name, PFID(fid));
2002 scrub->os_lf_repaired++;
2004 CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
2006 osd_name(dev), namelen, name, PFID(fid), rc);
2010 /* XXX: For MDT-objects, we can move them from /lost+found to namespace
2011 * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
2012 * can process them in furtuer. */
2018 scrub->os_lf_failed++;
2020 /* skip the failure to make the scanning to continue. */
2023 WRAP_FILLDIR_FN(do_, osd_ios_lf_fill)
2025 #ifdef HAVE_FILLDIR_USE_CTX
2026 static FILLDIR_TYPE do_osd_ios_varfid_fill(struct dir_context *buf,
2028 static int osd_ios_varfid_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_device *dev = fill_buf->oifb_dev;
2036 struct dentry *child;
2040 fill_buf->oifb_items++;
2042 /* skip any '.' started names */
2046 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2048 RETURN(PTR_ERR(child));
2050 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2051 fill_buf->oifb_dentry->d_inode, child->d_inode,
2052 NULL, name, namelen, 0);
2053 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
2054 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2055 osd_ios_varfid_fill);
2060 WRAP_FILLDIR_FN(do_, osd_ios_varfid_fill)
2062 #ifdef HAVE_FILLDIR_USE_CTX
2063 static FILLDIR_TYPE do_osd_ios_dl_fill(struct dir_context *buf,
2065 static int osd_ios_dl_fill(void *buf,
2067 const char *name, int namelen,
2068 loff_t offset, __u64 ino, unsigned int d_type)
2070 struct osd_ios_filldir_buf *fill_buf =
2071 (struct osd_ios_filldir_buf *)buf;
2072 struct osd_device *dev = fill_buf->oifb_dev;
2073 const struct osd_lf_map *map;
2074 struct dentry *child;
2078 fill_buf->oifb_items++;
2080 /* skip any '.' started names */
2084 for (map = osd_dl_maps; map->olm_name != NULL; map++) {
2085 if (map->olm_namelen != namelen)
2088 if (strncmp(map->olm_name, name, namelen) == 0)
2092 if (map->olm_name == NULL)
2095 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2097 RETURN(PTR_ERR(child));
2099 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2100 fill_buf->oifb_dentry->d_inode, child->d_inode,
2101 &map->olm_fid, name, namelen, map->olm_flags);
2106 WRAP_FILLDIR_FN(do_, osd_ios_dl_fill)
2108 #ifdef HAVE_FILLDIR_USE_CTX
2109 static FILLDIR_TYPE do_osd_ios_uld_fill(struct dir_context *buf,
2111 static int osd_ios_uld_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;
2124 fill_buf->oifb_items++;
2126 /* skip any non-DFID format name */
2130 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2132 RETURN(PTR_ERR(child));
2134 /* skip the start '[' */
2135 sscanf(&name[1], SFID, RFID(&tfid));
2136 if (fid_is_sane(&tfid))
2137 rc = osd_ios_scan_one(fill_buf->oifb_info, fill_buf->oifb_dev,
2138 fill_buf->oifb_dentry->d_inode,
2139 child->d_inode, &tfid, name, namelen, 0);
2146 WRAP_FILLDIR_FN(do_, osd_ios_uld_fill)
2148 #ifdef HAVE_FILLDIR_USE_CTX
2149 static FILLDIR_TYPE do_osd_ios_root_fill(struct dir_context *buf,
2151 static int osd_ios_root_fill(void *buf,
2153 const char *name, int namelen,
2154 loff_t offset, __u64 ino, unsigned int d_type)
2156 struct osd_ios_filldir_buf *fill_buf =
2157 (struct osd_ios_filldir_buf *)buf;
2158 struct osd_device *dev = fill_buf->oifb_dev;
2159 const struct osd_lf_map *map;
2160 struct dentry *child;
2164 fill_buf->oifb_items++;
2166 /* skip any '.' started names */
2170 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
2171 if (map->olm_namelen != namelen)
2174 if (strncmp(map->olm_name, name, namelen) == 0)
2178 if (map->olm_name == NULL)
2181 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2183 RETURN(PTR_ERR(child));
2184 else if (!child->d_inode)
2185 GOTO(out_put, rc = -ENOENT);
2187 if (!(map->olm_flags & OLF_NO_OI))
2188 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2189 fill_buf->oifb_dentry->d_inode, child->d_inode,
2190 &map->olm_fid, name, namelen, map->olm_flags);
2191 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
2192 rc = osd_ios_new_item(dev, child, map->olm_scandir,
2200 WRAP_FILLDIR_FN(do_, osd_ios_root_fill)
2203 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
2204 struct dentry *dentry, filldir_t filldir)
2206 struct osd_ios_filldir_buf buf = {
2207 .ctx.actor = filldir,
2210 .oifb_dentry = dentry
2218 path.dentry = dget(dentry);
2219 path.mnt = mntget(dev->od_mnt);
2221 filp = dentry_open(&path, O_RDONLY, current_cred());
2224 RETURN(PTR_ERR(filp));
2226 filp->f_mode |= FMODE_64BITHASH | FMODE_NONOTIFY;
2227 filp->f_flags |= O_NOATIME;
2232 rc = iterate_dir(filp, &buf.ctx);
2233 } while (rc >= 0 && buf.oifb_items > 0 &&
2234 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
2241 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
2242 struct dentry *dentry, filldir_t filldir)
2244 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2245 struct scrub_file *sf = &scrub->os_file;
2246 struct dentry *child;
2250 /* It is existing MDT0 device. We only allow the case of object without
2251 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
2252 * can generate IGIF mode FID for the object and related OI mapping. If
2253 * it is on other MDTs, then becuase file-level backup/restore, related
2254 * OI mapping may be invalid already, we do not know which is the right
2255 * FID for the object. We only allow IGIF objects to reside on the MDT0.
2257 * XXX: For the case of object on non-MDT0 device with neither LMA nor
2258 * "fid" xattr, then something crashed. We cannot re-generate the
2259 * FID directly, instead, the OI scrub will scan the OI structure
2260 * and try to re-generate the LMA from the OI mapping. But if the
2261 * OI mapping crashed or lost also, then we have to give up under
2262 * double failure cases.
2264 spin_lock(&scrub->os_lock);
2265 scrub->os_convert_igif = 1;
2266 spin_unlock(&scrub->os_lock);
2267 child = osd_lookup_one_len_unlocked(dev, dot_lustre_name, dentry,
2268 strlen(dot_lustre_name));
2269 if (IS_ERR(child)) {
2270 if (PTR_ERR(child) != -ENOENT)
2271 RETURN(PTR_ERR(child));
2275 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
2276 * so the client will get IGIF for the ".lustre" object when
2279 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
2280 * it does not know whether there are some old clients cached
2281 * the ".lustre" IGIF during the upgrading. Two choices:
2283 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
2284 * It will allow the old connected clients to access the
2285 * ".lustre" with cached IGIF. But it will cause others
2286 * on the MDT failed to check "fid_is_dot_lustre()".
2288 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
2289 * for ".lustre" in spite of whether there are some clients
2290 * cached the ".lustre" IGIF or not. It enables the check
2291 * "fid_is_dot_lustre()" on the MDT, although it will cause
2292 * that the old connected clients cannot access the ".lustre"
2293 * with the cached IGIF.
2295 * Usually, it is rare case for the old connected clients
2296 * to access the ".lustre" with cached IGIF. So we prefer
2297 * to the solution 2).
2299 inode_lock(dentry->d_inode);
2300 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2301 child->d_inode, &LU_DOT_LUSTRE_FID,
2303 strlen(dot_lustre_name), 0);
2304 inode_unlock(dentry->d_inode);
2305 if (rc == -ENOENT) {
2307 /* It is 1.8 MDT device. */
2308 if (!(sf->sf_flags & SF_UPGRADE)) {
2309 scrub_file_reset(scrub, dev->od_uuid,
2311 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2312 rc = scrub_file_store(info->oti_env, scrub);
2316 } else if (rc == 0) {
2317 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2326 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
2327 struct dentry *dentry, filldir_t filldir)
2329 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2330 struct scrub_file *sf = &scrub->os_file;
2331 struct dentry *child;
2335 if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
2336 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2337 rc = scrub_file_store(info->oti_env, scrub);
2342 child = osd_lookup_one_len_unlocked(dev, ADMIN_USR, dentry,
2344 if (IS_ERR(child)) {
2345 rc = PTR_ERR(child);
2347 inode_lock(dentry->d_inode);
2348 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2349 child->d_inode, NULL, ADMIN_USR,
2350 strlen(ADMIN_USR), 0);
2351 inode_unlock(dentry->d_inode);
2355 if (rc != 0 && rc != -ENOENT)
2358 child = osd_lookup_one_len_unlocked(dev, ADMIN_GRP, dentry,
2361 GOTO(out, rc = PTR_ERR(child));
2363 inode_lock(dentry->d_inode);
2364 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2365 child->d_inode, NULL, ADMIN_GRP,
2366 strlen(ADMIN_GRP), 0);
2367 inode_unlock(dentry->d_inode);
2370 RETURN(rc == -ENOENT ? 0 : rc);
2373 static void osd_initial_OI_scrub(struct osd_thread_info *info,
2374 struct osd_device *dev)
2376 struct osd_ios_item *item = NULL;
2377 scandir_t scandir = osd_ios_general_scan;
2378 filldir_t filldir = osd_ios_root_fill;
2379 struct dentry *dentry = osd_sb(dev)->s_root;
2380 const struct osd_lf_map *map = osd_lf_maps;
2383 /* Lookup IGIF in OI by force for initial OI scrub. */
2384 dev->od_igif_inoi = 1;
2387 /* Don't take inode_lock here since scandir() callbacks
2388 * can call VFS functions which may manully take the
2389 * inode lock itself like iterate_dir(). Since this
2390 * is the case it is best to leave the scandir()
2391 * callbacks to managing the inode lock.
2393 scandir(info, dev, dentry, filldir);
2395 dput(item->oii_dentry);
2399 if (list_empty(&dev->od_ios_list))
2402 item = list_first_entry(&dev->od_ios_list,
2403 struct osd_ios_item, oii_list);
2404 list_del_init(&item->oii_list);
2406 LASSERT(item->oii_scandir != NULL);
2407 scandir = item->oii_scandir;
2408 filldir = item->oii_filldir;
2409 dentry = item->oii_dentry;
2412 /* There maybe the case that the object has been removed, but its OI
2413 * mapping is still in the OI file, such as the "CATALOGS" after MDT
2414 * file-level backup/restore. So here cleanup the stale OI mappings. */
2415 while (map->olm_name != NULL) {
2416 struct dentry *child;
2418 if (fid_is_zero(&map->olm_fid)) {
2423 child = osd_lookup_one_len_unlocked(dev, map->olm_name,
2424 osd_sb(dev)->s_root,
2426 if (PTR_ERR(child) == -ENOENT ||
2427 (!IS_ERR(child) && !child->d_inode))
2428 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
2429 NULL, DTO_INDEX_DELETE,
2436 if (!list_empty(&dev->od_index_restore_list)) {
2439 OBD_ALLOC_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2441 CERROR("%s: not enough RAM for rebuild index\n",
2444 while (!list_empty(&dev->od_index_restore_list)) {
2445 struct lustre_index_restore_unit *liru;
2447 liru = list_first_entry(&dev->od_index_restore_list,
2448 struct lustre_index_restore_unit,
2450 list_del(&liru->liru_link);
2452 osd_index_restore(info->oti_env, dev, liru,
2453 buf, INDEX_BACKUP_BUFSIZE);
2454 OBD_FREE(liru, liru->liru_len);
2458 OBD_FREE_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2464 char *osd_lf_fid2name(const struct lu_fid *fid)
2466 const struct osd_lf_map *map = osd_lf_maps;
2468 while (map->olm_name != NULL) {
2469 if (!lu_fid_eq(fid, &map->olm_fid)) {
2474 if (map->olm_flags & OLF_SHOW_NAME)
2475 return map->olm_name;
2483 /* OI scrub start/stop */
2485 int osd_scrub_start(const struct lu_env *env, struct osd_device *dev,
2488 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2492 if (dev->od_dt_dev.dd_rdonly)
2495 /* od_otable_mutex: prevent curcurrent start/stop */
2496 mutex_lock(&dev->od_otable_mutex);
2497 rc = scrub_start(osd_scrub_main, scrub, dev, flags);
2498 if (rc == -EALREADY) {
2500 if ((scrub->os_file.sf_flags & SF_AUTO ||
2501 scrub->os_partial_scan) &&
2502 !(flags & SS_AUTO_PARTIAL))
2503 osd_scrub_join(env, dev, flags, false);
2505 mutex_unlock(&dev->od_otable_mutex);
2510 void osd_scrub_stop(struct osd_device *dev)
2512 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2514 /* od_otable_mutex: prevent curcurrent start/stop */
2515 mutex_lock(&dev->od_otable_mutex);
2516 spin_lock(&scrub->os_lock);
2517 scrub->os_paused = 1;
2518 spin_unlock(&scrub->os_lock);
2520 mutex_unlock(&dev->od_otable_mutex);
2522 osd_scrub_ois_fini(scrub, &scrub->os_inconsistent_items);
2523 osd_scrub_ois_fini(scrub, &scrub->os_stale_items);
2526 /* OI scrub setup/cleanup */
2528 static const char osd_scrub_name[] = "OI_scrub";
2530 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev,
2533 struct osd_thread_info *info = osd_oti_get(env);
2534 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2535 struct lvfs_run_ctxt *ctxt = &dev->od_scrub.os_ctxt;
2536 time64_t interval = scrub->os_auto_scrub_interval;
2537 struct scrub_file *sf = &scrub->os_file;
2538 struct super_block *sb = osd_sb(dev);
2539 struct lvfs_run_ctxt saved;
2541 struct inode *inode;
2542 struct lu_fid *fid = &info->oti_fid;
2543 struct osd_inode_id *id = &info->oti_id;
2544 struct dt_object *obj;
2549 memset(&dev->od_scrub, 0, sizeof(struct osd_scrub));
2550 OBD_SET_CTXT_MAGIC(ctxt);
2551 ctxt->pwdmnt = dev->od_mnt;
2552 ctxt->pwd = dev->od_mnt->mnt_root;
2554 init_rwsem(&scrub->os_rwsem);
2555 spin_lock_init(&scrub->os_lock);
2556 INIT_LIST_HEAD(&scrub->os_inconsistent_items);
2557 INIT_LIST_HEAD(&scrub->os_stale_items);
2558 scrub->os_name = osd_name(dev);
2559 scrub->os_auto_scrub_interval = interval;
2561 push_ctxt(&saved, ctxt);
2562 filp = filp_open(osd_scrub_name,
2563 (dev->od_dt_dev.dd_rdonly ? O_RDONLY :
2567 pop_ctxt(&saved, ctxt);
2568 RETURN(PTR_ERR(filp));
2571 inode = file_inode(filp);
2572 ldiskfs_set_inode_flag(inode, LDISKFS_INODE_JOURNAL_DATA);
2573 if (!dev->od_dt_dev.dd_rdonly) {
2574 /* 'What the @fid is' is not imporatant, because the object
2575 * has no OI mapping, and only is visible inside the OSD.*/
2576 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2577 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
2579 filp_close(filp, NULL);
2580 pop_ctxt(&saved, ctxt);
2585 osd_id_gen(id, inode->i_ino, inode->i_generation);
2586 osd_add_oi_cache(info, dev, id, fid);
2587 filp_close(filp, NULL);
2588 pop_ctxt(&saved, ctxt);
2590 obj = lu2dt(lu_object_find_slice(env, osd2lu_dev(dev), fid, NULL));
2591 if (IS_ERR_OR_NULL(obj))
2592 RETURN(obj ? PTR_ERR(obj) : -ENOENT);
2594 guid_copy(&dev->od_uuid, (guid_t *)&sb->s_uuid);
2595 scrub->os_obj = obj;
2596 rc = scrub_file_load(env, scrub);
2597 if (rc == -ENOENT || rc == -EFAULT) {
2598 scrub_file_init(scrub, dev->od_uuid);
2599 /* If the "/O" dir does not exist when mount (indicated by
2600 * osd_device::od_maybe_new), neither for the "/OI_scrub",
2601 * then it is quite probably that the device is a new one,
2602 * under such case, mark it as SIF_NO_HANDLE_OLD_FID.
2604 * For the rare case that "/O" and "OI_scrub" both lost on
2605 * an old device, it can be found and cleared later.
2607 * For the system with "SIF_NO_HANDLE_OLD_FID", we do not
2608 * need to check "filter_fid_18_23" and to convert it to
2609 * "filter_fid" for each object, and all the IGIF should
2610 * have their FID mapping in OI files already. */
2611 if (dev->od_maybe_new && rc == -ENOENT)
2612 sf->sf_internal_flags = SIF_NO_HANDLE_OLD_FID;
2614 } else if (rc < 0) {
2615 GOTO(cleanup_obj, rc);
2617 if (!guid_equal(&sf->sf_uuid, &dev->od_uuid)) {
2619 "%s: UUID has been changed from %pU to %pU\n",
2620 osd_dev2name(dev), &sf->sf_uuid, &dev->od_uuid);
2621 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
2624 } else if (sf->sf_status == SS_SCANNING) {
2625 sf->sf_status = SS_CRASHED;
2629 if ((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) {
2630 LCONSOLE_WARN("%s: invalid oi count %d, set it to %d\n",
2631 osd_dev2name(dev), sf->sf_oi_count,
2633 sf->sf_oi_count = osd_oi_count;
2638 if (sf->sf_pos_last_checkpoint != 0)
2639 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
2641 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
2644 rc = scrub_file_store(env, scrub);
2646 GOTO(cleanup_obj, rc);
2649 /* Initialize OI files. */
2650 rc = osd_oi_init(info, dev, restored);
2652 GOTO(cleanup_obj, rc);
2654 if (!dev->od_dt_dev.dd_rdonly)
2655 osd_initial_OI_scrub(info, dev);
2657 if (sf->sf_flags & SF_UPGRADE ||
2658 !(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID ||
2659 sf->sf_success_count > 0)) {
2660 dev->od_igif_inoi = 0;
2661 dev->od_check_ff = dev->od_is_ost;
2663 dev->od_igif_inoi = 1;
2664 dev->od_check_ff = 0;
2667 if (sf->sf_flags & SF_INCONSISTENT)
2668 /* The 'od_igif_inoi' will be set under the
2670 * 1) new created system, or
2671 * 2) restored from file-level backup, or
2672 * 3) the upgrading completed.
2674 * The 'od_igif_inoi' may be cleared by OI scrub
2675 * later if found that the system is upgrading. */
2676 dev->od_igif_inoi = 1;
2678 if (!dev->od_dt_dev.dd_rdonly &&
2679 dev->od_scrub.os_scrub.os_auto_scrub_interval != AS_NEVER &&
2680 ((sf->sf_status == SS_PAUSED) ||
2681 (sf->sf_status == SS_CRASHED &&
2682 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2683 SF_UPGRADE | SF_AUTO)) ||
2684 (sf->sf_status == SS_INIT &&
2685 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2687 rc = osd_scrub_start(env, dev, SS_AUTO_FULL);
2690 GOTO(cleanup_oi, rc);
2692 /* it is possible that dcache entries may keep objects after they are
2693 * deleted by OSD. While it looks safe this can cause object data to
2694 * stay until umount causing failures in tests calculating free space,
2695 * e.g. replay-ost-single. Since those dcache entries are not used
2696 * anymore let's just free them after use here */
2697 shrink_dcache_sb(sb);
2701 osd_oi_fini(info, dev);
2703 dt_object_put_nocache(env, scrub->os_obj);
2704 scrub->os_obj = NULL;
2709 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
2711 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2713 LASSERT(dev->od_otable_it == NULL);
2715 if (scrub->os_obj != NULL) {
2716 osd_scrub_stop(dev);
2717 dt_object_put_nocache(env, scrub->os_obj);
2718 scrub->os_obj = NULL;
2722 /* object table based iteration APIs */
2724 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
2725 struct dt_object *dt, __u32 attr)
2727 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
2728 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
2729 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
2730 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2731 struct osd_otable_it *it;
2736 /* od_otable_mutex: prevent curcurrent init/fini */
2737 mutex_lock(&dev->od_otable_mutex);
2738 if (dev->od_otable_it != NULL)
2739 GOTO(out, it = ERR_PTR(-EALREADY));
2743 GOTO(out, it = ERR_PTR(-ENOMEM));
2745 dev->od_otable_it = it;
2747 it->ooi_cache.ooc_consumer_idx = -1;
2748 if (flags & DOIF_OUTUSED)
2749 it->ooi_used_outside = 1;
2751 if (flags & DOIF_RESET)
2754 if (valid & DOIV_ERROR_HANDLE) {
2755 if (flags & DOIF_FAILOUT)
2756 start |= SS_SET_FAILOUT;
2758 start |= SS_CLEAR_FAILOUT;
2761 if (valid & DOIV_DRYRUN) {
2762 if (flags & DOIF_DRYRUN)
2763 start |= SS_SET_DRYRUN;
2765 start |= SS_CLEAR_DRYRUN;
2768 rc = scrub_start(osd_scrub_main, scrub, dev, start & ~SS_AUTO_PARTIAL);
2769 if (rc == -EALREADY) {
2770 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2771 } else if (rc < 0) {
2772 dev->od_otable_it = NULL;
2776 /* We have to start from the begining. */
2777 it->ooi_cache.ooc_pos_preload =
2778 LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2784 mutex_unlock(&dev->od_otable_mutex);
2785 return (struct dt_it *)it;
2788 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2790 struct osd_otable_it *it = (struct osd_otable_it *)di;
2791 struct osd_device *dev = it->ooi_dev;
2793 /* od_otable_mutex: prevent curcurrent init/fini */
2794 mutex_lock(&dev->od_otable_mutex);
2795 scrub_stop(&dev->od_scrub.os_scrub);
2796 LASSERT(dev->od_otable_it == it);
2798 dev->od_otable_it = NULL;
2799 mutex_unlock(&dev->od_otable_mutex);
2803 static int osd_otable_it_get(const struct lu_env *env,
2804 struct dt_it *di, const struct dt_key *key)
2809 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2814 osd_otable_it_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
2816 spin_lock(&scrub->os_lock);
2817 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2818 scrub->os_waiting || !scrub->os_running)
2819 it->ooi_waiting = 0;
2821 it->ooi_waiting = 1;
2822 spin_unlock(&scrub->os_lock);
2824 return !it->ooi_waiting;
2827 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2829 struct osd_otable_it *it = (struct osd_otable_it *)di;
2830 struct osd_device *dev = it->ooi_dev;
2831 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2832 struct osd_otable_cache *ooc = &it->ooi_cache;
2836 LASSERT(it->ooi_user_ready);
2839 if (!scrub->os_running && !it->ooi_used_outside)
2842 if (ooc->ooc_cached_items > 0) {
2843 ooc->ooc_cached_items--;
2844 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2845 ~OSD_OTABLE_IT_CACHE_MASK;
2849 if (it->ooi_all_cached) {
2850 wait_var_event(scrub, !scrub->os_running);
2854 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2855 spin_lock(&scrub->os_lock);
2856 scrub->os_waiting = 0;
2858 spin_unlock(&scrub->os_lock);
2861 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2862 wait_var_event(scrub, osd_otable_it_wakeup(scrub, it));
2864 if (!scrub->os_running && !it->ooi_used_outside)
2867 rc = osd_otable_it_preload(env, it);
2874 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2875 const struct dt_it *di)
2880 static int osd_otable_it_key_size(const struct lu_env *env,
2881 const struct dt_it *di)
2883 return sizeof(__u64);
2886 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2887 struct dt_rec *rec, __u32 attr)
2889 struct osd_otable_it *it = (struct osd_otable_it *)di;
2890 struct osd_otable_cache *ooc = &it->ooi_cache;
2892 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2894 /* Filter out Invald FID already. */
2895 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2896 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2897 PFID((struct lu_fid *)rec),
2898 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2903 static __u64 osd_otable_it_store(const struct lu_env *env,
2904 const struct dt_it *di)
2906 struct osd_otable_it *it = (struct osd_otable_it *)di;
2907 struct osd_otable_cache *ooc = &it->ooi_cache;
2910 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2911 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2913 hash = ooc->ooc_pos_preload;
2918 * Set the OSD layer iteration start position as the specified hash.
2920 static int osd_otable_it_load(const struct lu_env *env,
2921 const struct dt_it *di, __u64 hash)
2923 struct osd_otable_it *it = (struct osd_otable_it *)di;
2924 struct osd_device *dev = it->ooi_dev;
2925 struct osd_otable_cache *ooc = &it->ooi_cache;
2926 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2927 struct osd_iit_param *param = &it->ooi_iit_param;
2931 /* Forbid to set iteration position after iteration started. */
2932 if (it->ooi_user_ready)
2935 LASSERT(!scrub->os_partial_scan);
2937 if (hash > OSD_OTABLE_MAX_HASH)
2938 hash = OSD_OTABLE_MAX_HASH;
2940 /* The hash is the last checkpoint position,
2941 * we will start from the next one. */
2942 ooc->ooc_pos_preload = hash + 1;
2943 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
2944 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2946 it->ooi_user_ready = 1;
2947 if (!scrub->os_full_speed)
2950 memset(param, 0, sizeof(*param));
2951 param->sb = osd_sb(dev);
2952 param->start = ooc->ooc_pos_preload;
2953 param->bg = (ooc->ooc_pos_preload - 1) /
2954 LDISKFS_INODES_PER_GROUP(param->sb);
2955 param->offset = (ooc->ooc_pos_preload - 1) %
2956 LDISKFS_INODES_PER_GROUP(param->sb);
2957 param->gbase = 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
2959 /* Unplug OSD layer iteration by the first next() call. */
2960 rc = osd_otable_it_next(env, (struct dt_it *)it);
2965 static int osd_otable_it_key_rec(const struct lu_env *env,
2966 const struct dt_it *di, void *key_rec)
2971 const struct dt_index_operations osd_otable_ops = {
2973 .init = osd_otable_it_init,
2974 .fini = osd_otable_it_fini,
2975 .get = osd_otable_it_get,
2976 .put = osd_otable_it_put,
2977 .next = osd_otable_it_next,
2978 .key = osd_otable_it_key,
2979 .key_size = osd_otable_it_key_size,
2980 .rec = osd_otable_it_rec,
2981 .store = osd_otable_it_store,
2982 .load = osd_otable_it_load,
2983 .key_rec = osd_otable_it_key_rec,
2987 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
2989 struct osd_scrub *scrub = &dev->od_scrub;
2991 scrub_dump(m, &scrub->os_scrub);
2992 seq_printf(m, "lf_scanned: %llu\n"
2994 "lf_failed: %llu\n",
2995 scrub->os_lf_scanned,
2996 scrub->os_scrub.os_file.sf_param & SP_DRYRUN ?
2997 "inconsistent" : "repaired",
2998 scrub->os_lf_repaired,
2999 scrub->os_lf_failed);
3002 typedef int (*scan_dir_helper_t)(const struct lu_env *env,
3003 struct osd_device *dev, struct inode *dir,
3004 struct osd_it_ea *oie);
3006 static int osd_scan_dir(const struct lu_env *env, struct osd_device *dev,
3007 struct inode *inode, scan_dir_helper_t cb)
3009 struct osd_it_ea *oie;
3014 oie = osd_it_dir_init(env, dev, inode, LUDA_TYPE);
3016 RETURN(PTR_ERR(oie));
3018 oie->oie_file->f_pos = 0;
3019 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3025 while (oie->oie_it_dirent <= oie->oie_rd_dirent) {
3026 if (!name_is_dot_or_dotdot(oie->oie_dirent->oied_name,
3027 oie->oie_dirent->oied_namelen))
3028 cb(env, dev, inode, oie);
3030 oie->oie_dirent = (void *)oie->oie_dirent +
3031 round_up(sizeof(struct osd_it_ea_dirent) +
3032 oie->oie_dirent->oied_namelen, 8);
3034 oie->oie_it_dirent++;
3035 if (oie->oie_it_dirent <= oie->oie_rd_dirent)
3038 if (oie->oie_file->f_pos ==
3039 ldiskfs_get_htree_eof(oie->oie_file))
3042 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3051 osd_it_dir_fini(env, oie, inode);
3055 static int osd_remove_ml_file(struct osd_thread_info *info,
3056 struct osd_device *dev, struct inode *dir,
3057 struct inode *inode, struct osd_it_ea *oie)
3060 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3061 struct dentry dentry;
3066 if (scrub->os_file.sf_param & SP_DRYRUN)
3069 th = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
3070 osd_dto_credits_noquota[DTO_INDEX_DELETE] +
3071 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
3073 RETURN(PTR_ERR(th));
3075 /* Should be created by the VFS layer */
3076 dentry.d_inode = dir;
3077 dentry.d_sb = dir->i_sb;
3078 rc = osd_obj_del_entry(info, dev, &dentry, oie->oie_dirent->oied_name,
3079 oie->oie_dirent->oied_namelen, th);
3081 mark_inode_dirty(inode);
3082 ldiskfs_journal_stop(th);
3086 static int osd_scan_ml_file(const struct lu_env *env, struct osd_device *dev,
3087 struct inode *dir, struct osd_it_ea *oie)
3089 struct osd_thread_info *info = osd_oti_get(env);
3090 struct osd_inode_id id;
3091 struct inode *inode;
3092 struct osd_obj_seq *oseq;
3093 struct ost_id *ostid = &info->oti_ostid;
3094 struct lu_fid *fid = &oie->oie_dirent->oied_fid;
3100 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3102 if (!fid_is_sane(fid))
3103 inode = osd_iget_fid(info, dev, &id, fid);
3105 inode = osd_iget(info, dev, &id);
3108 RETURN(PTR_ERR(inode));
3110 fid_to_ostid(fid, ostid);
3111 oseq = osd_seq_load(info, dev, ostid_seq(ostid));
3113 RETURN(PTR_ERR(oseq));
3115 dirn = ostid_id(ostid) & (oseq->oos_subdir_count - 1);
3116 LASSERT(oseq->oos_dirs[dirn] != NULL);
3118 osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
3119 if (((strlen(oseq->oos_root->d_name.name) !=
3120 info->oti_seq_dirent->oied_namelen) ||
3121 strncmp(oseq->oos_root->d_name.name,
3122 info->oti_seq_dirent->oied_name,
3123 info->oti_seq_dirent->oied_namelen) != 0) ||
3124 ((strlen(oseq->oos_dirs[dirn]->d_name.name) !=
3125 info->oti_dir_dirent->oied_namelen) ||
3126 strncmp(oseq->oos_dirs[dirn]->d_name.name,
3127 info->oti_dir_dirent->oied_name,
3128 info->oti_dir_dirent->oied_namelen) != 0) ||
3129 ((strlen(name) != oie->oie_dirent->oied_namelen) ||
3130 strncmp(oie->oie_dirent->oied_name, name,
3131 oie->oie_dirent->oied_namelen) != 0)) {
3132 CDEBUG(D_LFSCK, "%s: the file O/%s/%s/%s is corrupted\n",
3133 osd_name(dev), info->oti_seq_dirent->oied_name,
3134 info->oti_dir_dirent->oied_name,
3135 oie->oie_dirent->oied_name);
3137 rc = osd_remove_ml_file(info, dev, dir, inode, oie);
3144 static int osd_scan_ml_file_dir(const struct lu_env *env,
3145 struct osd_device *dev, struct inode *dir,
3146 struct osd_it_ea *oie)
3148 struct osd_thread_info *info = osd_oti_get(env);
3149 struct inode *inode;
3150 struct osd_inode_id id;
3155 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3156 inode = osd_iget(info, dev, &id);
3158 RETURN(PTR_ERR(inode));
3160 if (!S_ISDIR(inode->i_mode))
3163 info->oti_dir_dirent = oie->oie_dirent;
3164 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file);
3165 info->oti_dir_dirent = NULL;
3172 static int osd_scan_ml_file_seq(const struct lu_env *env,
3173 struct osd_device *dev, struct inode *dir,
3174 struct osd_it_ea *oie)
3176 struct osd_thread_info *info = osd_oti_get(env);
3177 struct inode *inode;
3178 struct osd_inode_id id;
3183 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3184 inode = osd_iget(info, dev, &id);
3186 RETURN(PTR_ERR(inode));
3188 if (!S_ISDIR(inode->i_mode))
3191 info->oti_seq_dirent = oie->oie_dirent;
3192 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file_dir);
3193 info->oti_seq_dirent = NULL;
3200 static int osd_scan_ml_file_main(const struct lu_env *env,
3201 struct osd_device *dev)
3203 return osd_scan_dir(env, dev, dev->od_ost_map->om_root->d_inode,
3204 osd_scan_ml_file_seq);