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_first_entry(&scrub->os_inconsistent_items,
831 struct osd_inconsistent_item,
834 *oic = &oii->oii_cache;
835 scrub->os_in_prior = 1;
836 spin_unlock(&scrub->os_lock);
840 spin_unlock(&scrub->os_lock);
844 return SCRUB_NEXT_WAIT;
846 rc = osd_iit_next(param, &scrub->os_pos_current);
850 *oic = &dev->od_scrub.os_oic;
851 fid = &(*oic)->oic_fid;
852 lid = &(*oic)->oic_lid;
853 rc = osd_iit_iget(info, dev, fid, lid,
854 scrub->os_pos_current, param->sb, true);
858 static int osd_preload_next(struct osd_thread_info *info,
859 struct osd_device *dev, struct osd_iit_param *param,
860 struct osd_idmap_cache **oic, const bool noslot)
862 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
863 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
866 if (scrub->os_running &&
867 ooc->ooc_pos_preload >= scrub->os_pos_current)
868 return SCRUB_NEXT_EXIT;
870 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
874 rc = osd_iit_iget(info, dev,
875 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
876 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
877 ooc->ooc_pos_preload, param->sb, false);
882 osd_scrub_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
884 spin_lock(&scrub->os_lock);
885 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
886 !list_empty(&scrub->os_inconsistent_items) ||
887 it->ooi_waiting || kthread_should_stop())
888 scrub->os_waiting = 0;
890 scrub->os_waiting = 1;
891 spin_unlock(&scrub->os_lock);
893 return !scrub->os_waiting;
896 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
897 struct osd_iit_param *param,
898 struct osd_idmap_cache *oic, bool *noslot, int rc)
900 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
901 struct scrub_file *sf = &scrub->os_file;
902 struct osd_otable_it *it = dev->od_otable_it;
903 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
906 case SCRUB_NEXT_NOSCRUB:
907 down_write(&scrub->os_rwsem);
908 scrub->os_new_checked++;
909 sf->sf_items_noscrub++;
910 up_write(&scrub->os_rwsem);
911 case SCRUB_NEXT_CONTINUE:
912 case SCRUB_NEXT_WAIT:
916 rc = osd_scrub_check_update(info, dev, oic, rc);
918 spin_lock(&scrub->os_lock);
919 scrub->os_in_prior = 0;
920 spin_unlock(&scrub->os_lock);
924 rc = scrub_checkpoint(info->oti_env, scrub);
926 CDEBUG(D_LFSCK, "%s: fail to checkpoint, pos = %llu: "
927 "rc = %d\n", osd_scrub2name(scrub),
928 scrub->os_pos_current, rc);
929 /* Continue, as long as the scrub itself can go ahead. */
932 if (scrub->os_in_prior) {
933 spin_lock(&scrub->os_lock);
934 scrub->os_in_prior = 0;
935 spin_unlock(&scrub->os_lock);
940 if (it != NULL && it->ooi_waiting && ooc != NULL &&
941 ooc->ooc_pos_preload < scrub->os_pos_current) {
942 spin_lock(&scrub->os_lock);
945 spin_unlock(&scrub->os_lock);
948 if (rc == SCRUB_NEXT_CONTINUE)
951 if (scrub->os_full_speed || !ooc || osd_scrub_has_window(scrub, ooc)) {
957 wait_var_event(scrub, osd_scrub_wakeup(scrub, it));
959 if (!ooc || osd_scrub_has_window(scrub, ooc))
966 static int osd_preload_exec(struct osd_thread_info *info,
967 struct osd_device *dev, struct osd_iit_param *param,
968 struct osd_idmap_cache *oic, bool *noslot, int rc)
970 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
973 ooc->ooc_cached_items++;
974 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
975 ~OSD_OTABLE_IT_CACHE_MASK;
977 return rc > 0 ? 0 : rc;
980 #define SCRUB_IT_ALL 1
981 #define SCRUB_IT_CRASH 2
983 static void osd_scrub_join(const struct lu_env *env, struct osd_device *dev,
984 __u32 flags, bool inconsistent)
986 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
987 struct scrub_file *sf = &scrub->os_file;
991 LASSERT(!(flags & SS_AUTO_PARTIAL));
993 down_write(&scrub->os_rwsem);
994 spin_lock(&scrub->os_lock);
995 scrub->os_in_join = 1;
996 if (flags & SS_SET_FAILOUT)
997 sf->sf_param |= SP_FAILOUT;
998 else if (flags & SS_CLEAR_FAILOUT)
999 sf->sf_param &= ~SP_FAILOUT;
1001 if (flags & SS_SET_DRYRUN)
1002 sf->sf_param |= SP_DRYRUN;
1003 else if (flags & SS_CLEAR_DRYRUN)
1004 sf->sf_param &= ~SP_DRYRUN;
1006 if (flags & SS_RESET) {
1007 scrub_file_reset(scrub, dev->od_uuid,
1008 inconsistent ? SF_INCONSISTENT : 0);
1009 sf->sf_status = SS_SCANNING;
1012 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
1013 scrub->os_full_speed = 1;
1015 scrub->os_full_speed = 0;
1017 if (flags & SS_AUTO_FULL) {
1018 sf->sf_flags |= SF_AUTO;
1019 scrub->os_full_speed = 1;
1021 spin_unlock(&scrub->os_lock);
1023 scrub->os_new_checked = 0;
1024 if (sf->sf_pos_last_checkpoint != 0)
1025 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
1027 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
1029 scrub->os_pos_current = sf->sf_pos_latest_start;
1030 sf->sf_time_latest_start = ktime_get_real_seconds();
1031 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
1032 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
1033 rc = scrub_file_store(env, scrub);
1035 spin_lock(&scrub->os_lock);
1036 scrub->os_waiting = 0;
1037 scrub->os_paused = 0;
1038 scrub->os_partial_scan = 0;
1039 scrub->os_in_join = 0;
1040 scrub->os_full_scrub = 0;
1041 spin_unlock(&scrub->os_lock);
1043 up_write(&scrub->os_rwsem);
1045 CDEBUG(D_LFSCK, "%s: joined in the OI scrub with flag %u: rc = %d\n",
1046 osd_scrub2name(scrub), flags, rc);
1051 static int osd_inode_iteration(struct osd_thread_info *info,
1052 struct osd_device *dev, __u32 max, bool preload)
1054 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1055 struct scrub_file *sf = &scrub->os_file;
1056 osd_iit_next_policy next;
1057 osd_iit_exec_policy exec;
1060 struct osd_iit_param *param;
1069 param = &dev->od_scrub.os_iit_param;
1070 memset(param, 0, sizeof(*param));
1071 param->sb = osd_sb(dev);
1073 while (scrub->os_partial_scan && !scrub->os_in_join) {
1074 struct osd_idmap_cache *oic = NULL;
1076 rc = osd_scrub_next(info, dev, param, &oic, noslot);
1078 case SCRUB_NEXT_EXIT:
1080 case SCRUB_NEXT_CRASH:
1081 RETURN(SCRUB_IT_CRASH);
1082 case SCRUB_NEXT_FATAL:
1084 case SCRUB_NEXT_WAIT: {
1085 struct kstatfs *ksfs = &info->oti_ksfs;
1088 if (dev->od_full_scrub_ratio == OFSR_NEVER ||
1089 unlikely(sf->sf_items_updated_prior == 0))
1092 if (dev->od_full_scrub_ratio == OFSR_DIRECTLY ||
1093 scrub->os_full_scrub) {
1094 osd_scrub_join(info->oti_env, dev,
1095 SS_AUTO_FULL | SS_RESET, true);
1099 rc = param->sb->s_op->statfs(param->sb->s_root, ksfs);
1101 __u64 used = ksfs->f_files - ksfs->f_ffree;
1103 used = div64_u64(used, sf->sf_items_updated_prior);
1104 /* If we hit too much inconsistent OI
1105 * mappings during the partial scan,
1106 * then scan the device completely. */
1107 if (used < dev->od_full_scrub_ratio) {
1108 osd_scrub_join(info->oti_env, dev,
1109 SS_AUTO_FULL | SS_RESET, true);
1115 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) &&
1119 saved_flags = sf->sf_flags;
1120 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
1121 SF_UPGRADE | SF_AUTO);
1122 sf->sf_status = SS_COMPLETED;
1125 kthread_should_stop() ||
1126 !scrub->os_partial_scan ||
1127 scrub->os_in_join ||
1128 !list_empty(&scrub->os_inconsistent_items));
1129 sf->sf_flags = saved_flags;
1130 sf->sf_status = SS_SCANNING;
1132 if (kthread_should_stop())
1135 if (!scrub->os_partial_scan || scrub->os_in_join)
1141 LASSERTF(rc == 0, "rc = %d\n", rc);
1143 osd_scrub_exec(info, dev, param, oic, &noslot, rc);
1150 wait_var_event(scrub,
1151 kthread_should_stop() ||
1152 !scrub->os_in_join);
1154 if (kthread_should_stop())
1160 next = osd_scrub_next;
1161 exec = osd_scrub_exec;
1162 pos = &scrub->os_pos_current;
1163 count = &scrub->os_new_checked;
1164 param->start = *pos;
1165 param->bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param->sb);
1167 (*pos - 1) % LDISKFS_INODES_PER_GROUP(param->sb);
1169 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1171 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1173 next = osd_preload_next;
1174 exec = osd_preload_exec;
1175 pos = &ooc->ooc_pos_preload;
1176 count = &ooc->ooc_cached_items;
1177 param = &dev->od_otable_it->ooi_iit_param;
1181 limit = le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count);
1182 while (*pos <= limit && *count < max) {
1183 struct ldiskfs_group_desc *desc;
1184 bool next_group = false;
1186 desc = ldiskfs_get_group_desc(param->sb, param->bg, NULL);
1190 if (desc->bg_flags & cpu_to_le16(LDISKFS_BG_INODE_UNINIT)) {
1195 param->bitmap = ldiskfs_read_inode_bitmap(param->sb, param->bg);
1196 if (IS_ERR_OR_NULL(param->bitmap)) {
1197 if (param->bitmap) {
1198 rc = PTR_ERR(param->bitmap);
1199 param->bitmap = NULL;
1203 CERROR("%s: fail to read bitmap for %u, scrub will stop, urgent mode: rc = %d\n",
1204 osd_scrub2name(scrub), (__u32)param->bg, rc);
1209 struct osd_idmap_cache *oic = NULL;
1212 ldiskfs_itable_unused_count(param->sb, desc) >=
1213 LDISKFS_INODES_PER_GROUP(param->sb)) {
1218 rc = next(info, dev, param, &oic, noslot);
1220 case SCRUB_NEXT_BREAK:
1223 case SCRUB_NEXT_EXIT:
1224 brelse(param->bitmap);
1226 case SCRUB_NEXT_CRASH:
1227 brelse(param->bitmap);
1228 RETURN(SCRUB_IT_CRASH);
1229 case SCRUB_NEXT_FATAL:
1230 brelse(param->bitmap);
1234 rc = exec(info, dev, param, oic, &noslot, rc);
1235 } while (!rc && *pos <= limit && *count < max);
1238 if (param->bitmap) {
1239 brelse(param->bitmap);
1240 param->bitmap = NULL;
1250 param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1251 *pos = param->gbase;
1252 param->start = *pos;
1257 RETURN(SCRUB_IT_ALL);
1263 static int osd_otable_it_preload(const struct lu_env *env,
1264 struct osd_otable_it *it)
1266 struct osd_device *dev = it->ooi_dev;
1267 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1268 struct osd_otable_cache *ooc = &it->ooi_cache;
1272 rc = osd_inode_iteration(osd_oti_get(env), dev,
1273 OSD_OTABLE_IT_CACHE_SIZE, true);
1274 if (rc == SCRUB_IT_ALL)
1275 it->ooi_all_cached = 1;
1277 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1278 spin_lock(&scrub->os_lock);
1279 scrub->os_waiting = 0;
1281 spin_unlock(&scrub->os_lock);
1284 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1287 static int osd_scan_ml_file_main(const struct lu_env *env,
1288 struct osd_device *dev);
1290 static int osd_scrub_main(void *args)
1293 struct osd_device *dev = (struct osd_device *)args;
1294 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1298 rc = lu_env_init(&env, LCT_LOCAL | LCT_DT_THREAD);
1300 CDEBUG(D_LFSCK, "%s: OI scrub fail to init env: rc = %d\n",
1301 osd_scrub2name(scrub), rc);
1305 rc = scrub_thread_prep(&env, scrub, dev->od_uuid,
1306 LDISKFS_FIRST_INO(osd_sb(dev)) + 1);
1308 CDEBUG(D_LFSCK, "%s: OI scrub fail to scrub prep: rc = %d\n",
1309 osd_scrub2name(scrub), rc);
1313 if (!scrub->os_full_speed && !scrub->os_partial_scan) {
1314 struct osd_otable_it *it = dev->od_otable_it;
1315 struct osd_otable_cache *ooc = &it->ooi_cache;
1317 wait_var_event(scrub,
1318 it->ooi_user_ready || kthread_should_stop());
1319 if (kthread_should_stop())
1322 scrub->os_pos_current = ooc->ooc_pos_preload;
1325 CDEBUG(D_LFSCK, "%s: OI scrub start, flags = 0x%x, pos = %llu\n",
1326 osd_scrub2name(scrub), scrub->os_start_flags,
1327 scrub->os_pos_current);
1329 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1330 if (unlikely(rc == SCRUB_IT_CRASH)) {
1331 spin_lock(&scrub->os_lock);
1332 scrub->os_running = 0;
1333 spin_unlock(&scrub->os_lock);
1334 GOTO(out, rc = -EINVAL);
1337 if (scrub->os_has_ml_file) {
1338 ret = osd_scan_ml_file_main(&env, dev);
1347 dev->od_igif_inoi = 1;
1348 dev->od_check_ff = 0;
1350 rc = scrub_thread_post(&env, &dev->od_scrub.os_scrub, rc);
1351 CDEBUG(D_LFSCK, "%s: OI scrub: stop, pos = %llu: rc = %d\n",
1352 osd_scrub2name(scrub), scrub->os_pos_current, rc);
1355 osd_scrub_ois_fini(scrub, &scrub->os_inconsistent_items);
1359 spin_lock(&scrub->os_lock);
1360 scrub->os_running = 0;
1361 spin_unlock(&scrub->os_lock);
1362 if (xchg(&scrub->os_task, NULL) == NULL)
1363 /* scrub_stop() is waiting, we need to synchronize */
1364 wait_var_event(scrub, kthread_should_stop());
1369 /* initial OI scrub */
1371 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1372 struct dentry *, filldir_t filldir);
1374 #ifdef HAVE_FILLDIR_USE_CTX
1376 osd_ios_varfid_fill(struct dir_context *buf, const char *name, int namelen,
1377 loff_t offset, __u64 ino, unsigned int d_type);
1380 osd_ios_lf_fill(struct dir_context *buf, const char *name, int namelen,
1381 loff_t offset, __u64 ino, unsigned int d_type);
1384 osd_ios_dl_fill(struct dir_context *buf, const char *name, int namelen,
1385 loff_t offset, __u64 ino, unsigned int d_type);
1388 osd_ios_uld_fill(struct dir_context *buf, const char *name, int namelen,
1389 loff_t offset, __u64 ino, unsigned int d_type);
1391 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1392 loff_t offset, __u64 ino, unsigned int d_type);
1393 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1394 loff_t offset, __u64 ino, unsigned int d_type);
1395 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1396 loff_t offset, __u64 ino, unsigned int d_type);
1397 static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
1398 loff_t offset, __u64 ino, unsigned int d_type);
1402 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1403 struct dentry *dentry, filldir_t filldir);
1405 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1406 struct dentry *dentry, filldir_t filldir);
1409 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1410 struct dentry *dentry, filldir_t filldir);
1414 struct lu_fid olm_fid;
1417 scandir_t olm_scandir;
1418 filldir_t olm_filldir;
1421 /* Add the new introduced local files in the list in the future. */
1422 static const struct osd_lf_map osd_lf_maps[] = {
1425 .olm_name = CATLIST,
1427 .f_seq = FID_SEQ_LOCAL_FILE,
1428 .f_oid = LLOG_CATALOGS_OID,
1430 .olm_flags = OLF_SHOW_NAME,
1431 .olm_namelen = sizeof(CATLIST) - 1,
1436 .olm_name = MOUNT_CONFIGS_DIR,
1438 .f_seq = FID_SEQ_LOCAL_FILE,
1439 .f_oid = MGS_CONFIGS_OID,
1441 .olm_flags = OLF_SCAN_SUBITEMS,
1442 .olm_namelen = sizeof(MOUNT_CONFIGS_DIR) - 1,
1443 .olm_scandir = osd_ios_general_scan,
1444 .olm_filldir = osd_ios_varfid_fill,
1447 /* NIDTBL_VERSIONS */
1449 .olm_name = MGS_NIDTBL_DIR,
1450 .olm_flags = OLF_SCAN_SUBITEMS,
1451 .olm_namelen = sizeof(MGS_NIDTBL_DIR) - 1,
1452 .olm_scandir = osd_ios_general_scan,
1453 .olm_filldir = osd_ios_varfid_fill,
1458 .olm_name = MDT_ORPHAN_DIR,
1459 .olm_namelen = sizeof(MDT_ORPHAN_DIR) - 1,
1466 .f_seq = FID_SEQ_ROOT,
1467 .f_oid = FID_OID_ROOT,
1469 .olm_flags = OLF_SCAN_SUBITEMS | OLF_HIDE_FID,
1470 .olm_namelen = sizeof("ROOT") - 1,
1471 .olm_scandir = osd_ios_ROOT_scan,
1474 /* changelog_catalog */
1476 .olm_name = CHANGELOG_CATALOG,
1477 .olm_namelen = sizeof(CHANGELOG_CATALOG) - 1,
1480 /* changelog_users */
1482 .olm_name = CHANGELOG_USERS,
1483 .olm_namelen = sizeof(CHANGELOG_USERS) - 1,
1490 .f_seq = FID_SEQ_LOCAL_FILE,
1491 .f_oid = FLD_INDEX_OID,
1493 .olm_flags = OLF_SHOW_NAME,
1494 .olm_namelen = sizeof("fld") - 1,
1499 .olm_name = LAST_RCVD,
1501 .f_seq = FID_SEQ_LOCAL_FILE,
1502 .f_oid = LAST_RECV_OID,
1504 .olm_flags = OLF_SHOW_NAME,
1505 .olm_namelen = sizeof(LAST_RCVD) - 1,
1510 .olm_name = REPLY_DATA,
1512 .f_seq = FID_SEQ_LOCAL_FILE,
1513 .f_oid = REPLY_DATA_OID,
1515 .olm_flags = OLF_SHOW_NAME,
1516 .olm_namelen = sizeof(REPLY_DATA) - 1,
1521 .olm_name = LOV_OBJID,
1523 .f_seq = FID_SEQ_LOCAL_FILE,
1524 .f_oid = MDD_LOV_OBJ_OID,
1526 .olm_flags = OLF_SHOW_NAME,
1527 .olm_namelen = sizeof(LOV_OBJID) - 1,
1532 .olm_name = LOV_OBJSEQ,
1534 .f_seq = FID_SEQ_LOCAL_FILE,
1535 .f_oid = MDD_LOV_OBJ_OSEQ,
1537 .olm_flags = OLF_SHOW_NAME,
1538 .olm_namelen = sizeof(LOV_OBJSEQ) - 1,
1543 .olm_name = QMT_DIR,
1544 .olm_flags = OLF_SCAN_SUBITEMS,
1545 .olm_namelen = sizeof(QMT_DIR) - 1,
1546 .olm_scandir = osd_ios_general_scan,
1547 .olm_filldir = osd_ios_varfid_fill,
1552 .olm_name = QSD_DIR,
1553 .olm_flags = OLF_SCAN_SUBITEMS,
1554 .olm_namelen = sizeof(QSD_DIR) - 1,
1555 .olm_scandir = osd_ios_general_scan,
1556 .olm_filldir = osd_ios_varfid_fill,
1561 .olm_name = "seq_ctl",
1563 .f_seq = FID_SEQ_LOCAL_FILE,
1564 .f_oid = FID_SEQ_CTL_OID,
1566 .olm_flags = OLF_SHOW_NAME,
1567 .olm_namelen = sizeof("seq_ctl") - 1,
1572 .olm_name = "seq_srv",
1574 .f_seq = FID_SEQ_LOCAL_FILE,
1575 .f_oid = FID_SEQ_SRV_OID,
1577 .olm_flags = OLF_SHOW_NAME,
1578 .olm_namelen = sizeof("seq_srv") - 1,
1583 .olm_name = HEALTH_CHECK,
1585 .f_seq = FID_SEQ_LOCAL_FILE,
1586 .f_oid = OFD_HEALTH_CHECK_OID,
1588 .olm_flags = OLF_SHOW_NAME,
1589 .olm_namelen = sizeof(HEALTH_CHECK) - 1,
1594 .olm_name = LFSCK_DIR,
1595 .olm_flags = OLF_SCAN_SUBITEMS,
1596 .olm_namelen = sizeof(LFSCK_DIR) - 1,
1597 .olm_scandir = osd_ios_general_scan,
1598 .olm_filldir = osd_ios_varfid_fill,
1601 /* lfsck_bookmark */
1603 .olm_name = LFSCK_BOOKMARK,
1604 .olm_namelen = sizeof(LFSCK_BOOKMARK) - 1,
1609 .olm_name = LFSCK_LAYOUT,
1610 .olm_namelen = sizeof(LFSCK_LAYOUT) - 1,
1613 /* lfsck_namespace */
1615 .olm_name = LFSCK_NAMESPACE,
1616 .olm_namelen = sizeof(LFSCK_NAMESPACE) - 1,
1619 /* OBJECTS, upgrade from old device */
1621 .olm_name = OBJECTS,
1622 .olm_flags = OLF_SCAN_SUBITEMS,
1623 .olm_namelen = sizeof(OBJECTS) - 1,
1624 .olm_scandir = osd_ios_OBJECTS_scan,
1627 /* lquota_v2.user, upgrade from old device */
1629 .olm_name = "lquota_v2.user",
1630 .olm_namelen = sizeof("lquota_v2.user") - 1,
1633 /* lquota_v2.group, upgrade from old device */
1635 .olm_name = "lquota_v2.group",
1636 .olm_namelen = sizeof("lquota_v2.group") - 1,
1639 /* LAST_GROUP, upgrade from old device */
1641 .olm_name = "LAST_GROUP",
1643 .f_seq = FID_SEQ_LOCAL_FILE,
1644 .f_oid = OFD_LAST_GROUP_OID,
1646 .olm_flags = OLF_SHOW_NAME,
1647 .olm_namelen = sizeof("LAST_GROUP") - 1,
1650 /* committed batchid for cross-MDT operation */
1652 .olm_name = "BATCHID",
1654 .f_seq = FID_SEQ_LOCAL_FILE,
1655 .f_oid = BATCHID_COMMITTED_OID,
1657 .olm_flags = OLF_SHOW_NAME,
1658 .olm_namelen = sizeof("BATCHID") - 1,
1661 /* OSP update logs update_log{_dir} use f_seq = FID_SEQ_UPDATE_LOG{_DIR}
1662 * and f_oid = index for their log files. See lu_update_log{_dir}_fid()
1663 * for more details. */
1667 .olm_name = "update_log",
1669 .f_seq = FID_SEQ_UPDATE_LOG,
1671 .olm_flags = OLF_SHOW_NAME | OLF_IDX_IN_FID,
1672 .olm_namelen = sizeof("update_log") - 1,
1675 /* update_log_dir */
1677 .olm_name = "update_log_dir",
1679 .f_seq = FID_SEQ_UPDATE_LOG_DIR,
1681 .olm_flags = OLF_SHOW_NAME | OLF_SCAN_SUBITEMS |
1683 .olm_namelen = sizeof("update_log_dir") - 1,
1684 .olm_scandir = osd_ios_general_scan,
1685 .olm_filldir = osd_ios_uld_fill,
1690 .olm_name = "lost+found",
1692 .f_seq = FID_SEQ_LOCAL_FILE,
1693 .f_oid = OSD_LPF_OID,
1695 .olm_flags = OLF_SCAN_SUBITEMS,
1696 .olm_namelen = sizeof("lost+found") - 1,
1697 .olm_scandir = osd_ios_general_scan,
1698 .olm_filldir = osd_ios_lf_fill,
1703 .olm_name = HSM_ACTIONS,
1708 .olm_name = LUSTRE_NODEMAP_NAME,
1713 .olm_name = INDEX_BACKUP_DIR,
1715 .f_seq = FID_SEQ_LOCAL_FILE,
1716 .f_oid = INDEX_BACKUP_OID,
1718 .olm_flags = OLF_SCAN_SUBITEMS | OLF_NOT_BACKUP,
1719 .olm_namelen = sizeof(INDEX_BACKUP_DIR) - 1,
1720 .olm_scandir = osd_ios_general_scan,
1721 .olm_filldir = osd_ios_varfid_fill,
1729 /* Add the new introduced files under .lustre/ in the list in the future. */
1730 static const struct osd_lf_map osd_dl_maps[] = {
1735 .f_seq = FID_SEQ_DOT_LUSTRE,
1736 .f_oid = FID_OID_DOT_LUSTRE_OBF,
1738 .olm_namelen = sizeof("fid") - 1,
1741 /* .lustre/lost+found */
1743 .olm_name = "lost+found",
1745 .f_seq = FID_SEQ_DOT_LUSTRE,
1746 .f_oid = FID_OID_DOT_LUSTRE_LPF,
1748 .olm_namelen = sizeof("lost+found") - 1,
1756 struct osd_ios_item {
1757 struct list_head oii_list;
1758 struct dentry *oii_dentry;
1759 scandir_t oii_scandir;
1760 filldir_t oii_filldir;
1763 struct osd_ios_filldir_buf {
1764 /* please keep it as first member */
1765 struct dir_context ctx;
1766 struct osd_thread_info *oifb_info;
1767 struct osd_device *oifb_dev;
1768 struct dentry *oifb_dentry;
1773 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1774 scandir_t scandir, filldir_t filldir)
1776 struct osd_ios_item *item;
1779 OBD_ALLOC_PTR(item);
1783 INIT_LIST_HEAD(&item->oii_list);
1784 item->oii_dentry = dget(dentry);
1785 item->oii_scandir = scandir;
1786 item->oii_filldir = filldir;
1787 list_add_tail(&item->oii_list, &dev->od_ios_list);
1792 static bool osd_index_need_recreate(const struct lu_env *env,
1793 struct osd_device *dev, struct inode *inode)
1795 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1796 struct iam_container *bag = &iam->od_container;
1800 rc = iam_container_init(bag, &iam->od_descr, inode);
1804 rc = iam_container_setup(bag);
1805 iam_container_fini(bag);
1812 static void osd_ios_index_register(const struct lu_env *env,
1813 struct osd_device *osd,
1814 const struct lu_fid *fid,
1815 struct inode *inode)
1817 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1818 struct iam_container *bag = &iam->od_container;
1819 struct super_block *sb = osd_sb(osd);
1820 struct iam_descr *descr;
1826 /* Index must be a regular file. */
1827 if (!S_ISREG(inode->i_mode))
1830 /* Index's size must be block aligned. */
1831 if (inode->i_size < sb->s_blocksize ||
1832 (inode->i_size & (sb->s_blocksize - 1)) != 0)
1835 iam_container_init(bag, &iam->od_descr, inode);
1836 rc = iam_container_setup(bag);
1840 descr = bag->ic_descr;
1841 /* May be regular file with IAM_LFIX_ROOT_MAGIC matched
1842 * coincidentally, or corrupted index object, skip it. */
1843 if (descr->id_ptr_size != 4)
1846 keysize = descr->id_key_size;
1847 recsize = descr->id_rec_size;
1848 rc = osd_index_register(osd, fid, keysize, recsize);
1853 iam_container_fini(bag);
1855 CDEBUG(D_LFSCK, "%s: index object "DFID" (%u/%u) registered\n",
1856 osd_name(osd), PFID(fid), keysize, recsize);
1859 static void osd_index_restore(const struct lu_env *env, struct osd_device *dev,
1860 struct lustre_index_restore_unit *liru,
1861 void *buf, int bufsize)
1863 struct osd_thread_info *info = osd_oti_get(env);
1864 struct osd_inode_id *id = &info->oti_id;
1865 struct lu_fid *tgt_fid = &liru->liru_cfid;
1866 struct inode *bak_inode = NULL;
1867 struct ldiskfs_dir_entry_2 *de = NULL;
1868 struct buffer_head *bh = NULL;
1869 struct dentry *dentry;
1871 struct lu_fid bak_fid;
1875 lustre_fid2lbx(name, tgt_fid, bufsize);
1876 dentry = osd_child_dentry_by_inode(env, dev->od_index_backup_inode,
1877 name, strlen(name));
1878 bh = osd_ldiskfs_find_entry(dev->od_index_backup_inode,
1879 &dentry->d_name, &de, NULL, NULL);
1881 GOTO(log, rc = PTR_ERR(bh));
1883 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
1885 bak_inode = osd_iget_fid(info, dev, id, &bak_fid);
1886 if (IS_ERR(bak_inode))
1887 GOTO(log, rc = PTR_ERR(bak_inode));
1890 /* The OI mapping for index may be invalid, since it will be
1891 * re-created, not update the OI mapping, just cache it in RAM. */
1892 osd_id_gen(id, liru->liru_clid, OSD_OII_NOGEN);
1893 osd_add_oi_cache(info, dev, id, tgt_fid);
1894 rc = lustre_index_restore(env, &dev->od_dt_dev, &liru->liru_pfid,
1895 tgt_fid, &bak_fid, liru->liru_name,
1896 &dev->od_index_backup_list, &dev->od_lock,
1901 CDEBUG(D_WARNING, "%s: restore index '%s' with "DFID": rc = %d\n",
1902 osd_name(dev), liru->liru_name, PFID(tgt_fid), rc);
1906 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1908 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1909 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1910 * reference the inode, or fixed if it is missing or references another inode.
1913 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1914 struct inode *parent, struct inode *inode,
1915 const struct lu_fid *fid, const char *name,
1916 int namelen, int flags)
1918 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1919 struct osd_inode_id *id = &info->oti_id;
1920 struct osd_inode_id *id2 = &info->oti_id2;
1921 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1922 struct scrub_file *sf = &scrub->os_file;
1928 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode: rc = -2\n",
1929 osd_name(dev), namelen, name);
1933 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
1934 &info->oti_ost_attrs);
1935 if (rc != 0 && rc != -ENODATA) {
1936 CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
1937 "rc = %d\n", osd_name(dev), rc);
1942 osd_id_gen(id, inode->i_ino, inode->i_generation);
1943 if (rc == -ENODATA) {
1944 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID) {
1945 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1948 if (flags & OLF_IDX_IN_FID) {
1949 LASSERT(dev->od_index >= 0);
1951 tfid.f_oid = dev->od_index;
1954 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1956 CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
1957 "scrub: rc = %d\n", osd_name(dev), rc);
1962 if (lma->lma_compat & LMAC_NOT_IN_OI)
1965 tfid = lma->lma_self_fid;
1966 if (lma->lma_compat & LMAC_IDX_BACKUP &&
1967 osd_index_need_recreate(info->oti_env, dev, inode)) {
1968 struct lu_fid *pfid = &info->oti_fid3;
1970 if (is_root_inode(parent)) {
1971 lu_local_obj_fid(pfid, OSD_FS_ROOT_OID);
1973 rc = osd_scrub_get_fid(info, dev, parent, pfid,
1979 rc = lustre_liru_new(&dev->od_index_restore_list, pfid,
1980 &tfid, inode->i_ino, name, namelen);
1985 if (!(flags & OLF_NOT_BACKUP))
1986 osd_ios_index_register(info->oti_env, dev, &tfid,
1990 /* Since this called from iterate_dir() the inode lock will be taken */
1991 rc = osd_oi_lookup(info, dev, &tfid, id2, OI_LOCKED);
1996 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1997 DTO_INDEX_INSERT, true, 0, NULL);
2004 if (osd_id_eq_strict(id, id2))
2007 if (!(sf->sf_flags & SF_INCONSISTENT)) {
2008 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
2009 rc = scrub_file_store(info->oti_env, scrub);
2014 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
2015 DTO_INDEX_UPDATE, true, 0, NULL);
2023 * It scans the /lost+found, and for the OST-object (with filter_fid
2024 * or filter_fid_18_23), move them back to its proper /O/<seq>/d<x>.
2026 #ifdef HAVE_FILLDIR_USE_CTX
2027 static FILLDIR_TYPE do_osd_ios_lf_fill(struct dir_context *buf,
2029 static int osd_ios_lf_fill(void *buf,
2031 const char *name, int namelen,
2032 loff_t offset, __u64 ino, unsigned int d_type)
2034 struct osd_ios_filldir_buf *fill_buf =
2035 (struct osd_ios_filldir_buf *)buf;
2036 struct osd_thread_info *info = fill_buf->oifb_info;
2037 struct osd_device *dev = fill_buf->oifb_dev;
2038 struct lu_fid *fid = &info->oti_fid;
2039 struct osd_scrub *scrub = &dev->od_scrub;
2040 struct dentry *parent = fill_buf->oifb_dentry;
2041 struct dentry *child;
2042 struct inode *dir = parent->d_inode;
2043 struct inode *inode;
2047 fill_buf->oifb_items++;
2049 /* skip any '.' started names */
2053 scrub->os_lf_scanned++;
2054 child = osd_lookup_one_len(dev, name, parent, namelen);
2055 if (IS_ERR(child)) {
2056 rc = PTR_ERR(child);
2057 CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
2058 osd_name(dev), namelen, name, rc);
2060 } else if (!child->d_inode) {
2062 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode\n",
2063 osd_name(dev), namelen, name);
2067 inode = child->d_inode;
2068 if (S_ISDIR(inode->i_mode)) {
2069 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2072 CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
2073 "rc = %d\n", osd_name(dev), namelen, name, rc);
2077 if (!S_ISREG(inode->i_mode))
2080 rc = osd_scrub_get_fid(info, dev, inode, fid, true);
2081 if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
2082 rc = osd_obj_map_recover(info, dev, dir, child, fid);
2084 CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
2085 "/lost+found.\n", namelen, name, PFID(fid));
2086 scrub->os_lf_repaired++;
2088 CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
2090 osd_name(dev), namelen, name, PFID(fid), rc);
2094 /* XXX: For MDT-objects, we can move them from /lost+found to namespace
2095 * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
2096 * can process them in furtuer. */
2102 scrub->os_lf_failed++;
2104 /* skip the failure to make the scanning to continue. */
2107 WRAP_FILLDIR_FN(do_, osd_ios_lf_fill)
2109 #ifdef HAVE_FILLDIR_USE_CTX
2110 static FILLDIR_TYPE do_osd_ios_varfid_fill(struct dir_context *buf,
2112 static int osd_ios_varfid_fill(void *buf,
2114 const char *name, int namelen,
2115 loff_t offset, __u64 ino, unsigned int d_type)
2117 struct osd_ios_filldir_buf *fill_buf =
2118 (struct osd_ios_filldir_buf *)buf;
2119 struct osd_device *dev = fill_buf->oifb_dev;
2120 struct dentry *child;
2124 fill_buf->oifb_items++;
2126 /* skip any '.' started names */
2130 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2132 RETURN(PTR_ERR(child));
2134 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2135 fill_buf->oifb_dentry->d_inode, child->d_inode,
2136 NULL, name, namelen, 0);
2137 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
2138 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2139 osd_ios_varfid_fill);
2144 WRAP_FILLDIR_FN(do_, osd_ios_varfid_fill)
2146 #ifdef HAVE_FILLDIR_USE_CTX
2147 static FILLDIR_TYPE do_osd_ios_dl_fill(struct dir_context *buf,
2149 static int osd_ios_dl_fill(void *buf,
2151 const char *name, int namelen,
2152 loff_t offset, __u64 ino, unsigned int d_type)
2154 struct osd_ios_filldir_buf *fill_buf =
2155 (struct osd_ios_filldir_buf *)buf;
2156 struct osd_device *dev = fill_buf->oifb_dev;
2157 const struct osd_lf_map *map;
2158 struct dentry *child;
2162 fill_buf->oifb_items++;
2164 /* skip any '.' started names */
2168 for (map = osd_dl_maps; map->olm_name != NULL; map++) {
2169 if (map->olm_namelen != namelen)
2172 if (strncmp(map->olm_name, name, namelen) == 0)
2176 if (map->olm_name == NULL)
2179 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2181 RETURN(PTR_ERR(child));
2183 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2184 fill_buf->oifb_dentry->d_inode, child->d_inode,
2185 &map->olm_fid, name, namelen, map->olm_flags);
2190 WRAP_FILLDIR_FN(do_, osd_ios_dl_fill)
2192 #ifdef HAVE_FILLDIR_USE_CTX
2193 static FILLDIR_TYPE do_osd_ios_uld_fill(struct dir_context *buf,
2195 static int osd_ios_uld_fill(void *buf,
2197 const char *name, int namelen,
2198 loff_t offset, __u64 ino, unsigned int d_type)
2200 struct osd_ios_filldir_buf *fill_buf =
2201 (struct osd_ios_filldir_buf *)buf;
2202 struct osd_device *dev = fill_buf->oifb_dev;
2203 struct dentry *child;
2208 fill_buf->oifb_items++;
2210 /* skip any non-DFID format name */
2214 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2216 RETURN(PTR_ERR(child));
2218 /* skip the start '[' */
2219 sscanf(&name[1], SFID, RFID(&tfid));
2220 if (fid_is_sane(&tfid))
2221 rc = osd_ios_scan_one(fill_buf->oifb_info, fill_buf->oifb_dev,
2222 fill_buf->oifb_dentry->d_inode,
2223 child->d_inode, &tfid, name, namelen, 0);
2230 WRAP_FILLDIR_FN(do_, osd_ios_uld_fill)
2232 #ifdef HAVE_FILLDIR_USE_CTX
2233 static FILLDIR_TYPE do_osd_ios_root_fill(struct dir_context *buf,
2235 static int osd_ios_root_fill(void *buf,
2237 const char *name, int namelen,
2238 loff_t offset, __u64 ino, unsigned int d_type)
2240 struct osd_ios_filldir_buf *fill_buf =
2241 (struct osd_ios_filldir_buf *)buf;
2242 struct osd_device *dev = fill_buf->oifb_dev;
2243 const struct osd_lf_map *map;
2244 struct dentry *child;
2248 fill_buf->oifb_items++;
2250 /* skip any '.' started names */
2254 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
2255 if (map->olm_namelen != namelen)
2258 if (strncmp(map->olm_name, name, namelen) == 0)
2262 if (map->olm_name == NULL)
2265 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2267 RETURN(PTR_ERR(child));
2268 else if (!child->d_inode)
2269 GOTO(out_put, rc = -ENOENT);
2271 if (!(map->olm_flags & OLF_NO_OI))
2272 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2273 fill_buf->oifb_dentry->d_inode, child->d_inode,
2274 &map->olm_fid, name, namelen, map->olm_flags);
2275 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
2276 rc = osd_ios_new_item(dev, child, map->olm_scandir,
2284 WRAP_FILLDIR_FN(do_, osd_ios_root_fill)
2287 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
2288 struct dentry *dentry, filldir_t filldir)
2290 struct osd_ios_filldir_buf buf = {
2291 .ctx.actor = filldir,
2294 .oifb_dentry = dentry
2302 path.dentry = dget(dentry);
2303 path.mnt = mntget(dev->od_mnt);
2305 filp = dentry_open(&path, O_RDONLY, current_cred());
2308 RETURN(PTR_ERR(filp));
2310 filp->f_mode |= FMODE_64BITHASH | FMODE_NONOTIFY;
2311 filp->f_flags |= O_NOATIME;
2316 rc = iterate_dir(filp, &buf.ctx);
2317 } while (rc >= 0 && buf.oifb_items > 0 &&
2318 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
2325 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
2326 struct dentry *dentry, filldir_t filldir)
2328 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2329 struct scrub_file *sf = &scrub->os_file;
2330 struct dentry *child;
2334 /* It is existing MDT0 device. We only allow the case of object without
2335 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
2336 * can generate IGIF mode FID for the object and related OI mapping. If
2337 * it is on other MDTs, then becuase file-level backup/restore, related
2338 * OI mapping may be invalid already, we do not know which is the right
2339 * FID for the object. We only allow IGIF objects to reside on the MDT0.
2341 * XXX: For the case of object on non-MDT0 device with neither LMA nor
2342 * "fid" xattr, then something crashed. We cannot re-generate the
2343 * FID directly, instead, the OI scrub will scan the OI structure
2344 * and try to re-generate the LMA from the OI mapping. But if the
2345 * OI mapping crashed or lost also, then we have to give up under
2346 * double failure cases.
2348 spin_lock(&scrub->os_lock);
2349 scrub->os_convert_igif = 1;
2350 spin_unlock(&scrub->os_lock);
2351 child = osd_lookup_one_len_unlocked(dev, dot_lustre_name, dentry,
2352 strlen(dot_lustre_name));
2353 if (IS_ERR(child)) {
2354 if (PTR_ERR(child) != -ENOENT)
2355 RETURN(PTR_ERR(child));
2359 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
2360 * so the client will get IGIF for the ".lustre" object when
2363 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
2364 * it does not know whether there are some old clients cached
2365 * the ".lustre" IGIF during the upgrading. Two choices:
2367 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
2368 * It will allow the old connected clients to access the
2369 * ".lustre" with cached IGIF. But it will cause others
2370 * on the MDT failed to check "fid_is_dot_lustre()".
2372 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
2373 * for ".lustre" in spite of whether there are some clients
2374 * cached the ".lustre" IGIF or not. It enables the check
2375 * "fid_is_dot_lustre()" on the MDT, although it will cause
2376 * that the old connected clients cannot access the ".lustre"
2377 * with the cached IGIF.
2379 * Usually, it is rare case for the old connected clients
2380 * to access the ".lustre" with cached IGIF. So we prefer
2381 * to the solution 2).
2383 inode_lock(dentry->d_inode);
2384 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2385 child->d_inode, &LU_DOT_LUSTRE_FID,
2387 strlen(dot_lustre_name), 0);
2388 inode_unlock(dentry->d_inode);
2389 if (rc == -ENOENT) {
2391 /* It is 1.8 MDT device. */
2392 if (!(sf->sf_flags & SF_UPGRADE)) {
2393 scrub_file_reset(scrub, dev->od_uuid,
2395 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2396 rc = scrub_file_store(info->oti_env, scrub);
2400 } else if (rc == 0) {
2401 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2410 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
2411 struct dentry *dentry, filldir_t filldir)
2413 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2414 struct scrub_file *sf = &scrub->os_file;
2415 struct dentry *child;
2419 if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
2420 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2421 rc = scrub_file_store(info->oti_env, scrub);
2426 child = osd_lookup_one_len_unlocked(dev, ADMIN_USR, dentry,
2428 if (IS_ERR(child)) {
2429 rc = PTR_ERR(child);
2431 inode_lock(dentry->d_inode);
2432 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2433 child->d_inode, NULL, ADMIN_USR,
2434 strlen(ADMIN_USR), 0);
2435 inode_unlock(dentry->d_inode);
2439 if (rc != 0 && rc != -ENOENT)
2442 child = osd_lookup_one_len_unlocked(dev, ADMIN_GRP, dentry,
2445 GOTO(out, rc = PTR_ERR(child));
2447 inode_lock(dentry->d_inode);
2448 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2449 child->d_inode, NULL, ADMIN_GRP,
2450 strlen(ADMIN_GRP), 0);
2451 inode_unlock(dentry->d_inode);
2454 RETURN(rc == -ENOENT ? 0 : rc);
2457 static void osd_initial_OI_scrub(struct osd_thread_info *info,
2458 struct osd_device *dev)
2460 struct osd_ios_item *item = NULL;
2461 scandir_t scandir = osd_ios_general_scan;
2462 filldir_t filldir = osd_ios_root_fill;
2463 struct dentry *dentry = osd_sb(dev)->s_root;
2464 const struct osd_lf_map *map = osd_lf_maps;
2467 /* Lookup IGIF in OI by force for initial OI scrub. */
2468 dev->od_igif_inoi = 1;
2471 /* Don't take inode_lock here since scandir() callbacks
2472 * can call VFS functions which may manully take the
2473 * inode lock itself like iterate_dir(). Since this
2474 * is the case it is best to leave the scandir()
2475 * callbacks to managing the inode lock.
2477 scandir(info, dev, dentry, filldir);
2479 dput(item->oii_dentry);
2483 if (list_empty(&dev->od_ios_list))
2486 item = list_first_entry(&dev->od_ios_list,
2487 struct osd_ios_item, oii_list);
2488 list_del_init(&item->oii_list);
2490 LASSERT(item->oii_scandir != NULL);
2491 scandir = item->oii_scandir;
2492 filldir = item->oii_filldir;
2493 dentry = item->oii_dentry;
2496 /* There maybe the case that the object has been removed, but its OI
2497 * mapping is still in the OI file, such as the "CATALOGS" after MDT
2498 * file-level backup/restore. So here cleanup the stale OI mappings. */
2499 while (map->olm_name != NULL) {
2500 struct dentry *child;
2502 if (fid_is_zero(&map->olm_fid)) {
2507 child = osd_lookup_one_len_unlocked(dev, map->olm_name,
2508 osd_sb(dev)->s_root,
2510 if (PTR_ERR(child) == -ENOENT ||
2511 (!IS_ERR(child) && !child->d_inode))
2512 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
2513 NULL, DTO_INDEX_DELETE,
2520 if (!list_empty(&dev->od_index_restore_list)) {
2523 OBD_ALLOC_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2525 CERROR("%s: not enough RAM for rebuild index\n",
2528 while (!list_empty(&dev->od_index_restore_list)) {
2529 struct lustre_index_restore_unit *liru;
2531 liru = list_first_entry(&dev->od_index_restore_list,
2532 struct lustre_index_restore_unit,
2534 list_del(&liru->liru_link);
2536 osd_index_restore(info->oti_env, dev, liru,
2537 buf, INDEX_BACKUP_BUFSIZE);
2538 OBD_FREE(liru, liru->liru_len);
2542 OBD_FREE_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2548 char *osd_lf_fid2name(const struct lu_fid *fid)
2550 const struct osd_lf_map *map = osd_lf_maps;
2552 while (map->olm_name != NULL) {
2553 if (!lu_fid_eq(fid, &map->olm_fid)) {
2558 if (map->olm_flags & OLF_SHOW_NAME)
2559 return map->olm_name;
2567 /* OI scrub start/stop */
2569 int osd_scrub_start(const struct lu_env *env, struct osd_device *dev,
2572 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2576 if (dev->od_dt_dev.dd_rdonly)
2579 /* od_otable_mutex: prevent curcurrent start/stop */
2580 mutex_lock(&dev->od_otable_mutex);
2581 rc = scrub_start(osd_scrub_main, scrub, dev, flags);
2582 if (rc == -EALREADY) {
2584 if ((scrub->os_file.sf_flags & SF_AUTO ||
2585 scrub->os_partial_scan) &&
2586 !(flags & SS_AUTO_PARTIAL))
2587 osd_scrub_join(env, dev, flags, false);
2589 mutex_unlock(&dev->od_otable_mutex);
2594 void osd_scrub_stop(struct osd_device *dev)
2596 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2598 /* od_otable_mutex: prevent curcurrent start/stop */
2599 mutex_lock(&dev->od_otable_mutex);
2600 spin_lock(&scrub->os_lock);
2601 scrub->os_paused = 1;
2602 spin_unlock(&scrub->os_lock);
2604 mutex_unlock(&dev->od_otable_mutex);
2606 osd_scrub_ois_fini(scrub, &scrub->os_inconsistent_items);
2607 osd_scrub_ois_fini(scrub, &scrub->os_stale_items);
2610 /* OI scrub setup/cleanup */
2612 static const char osd_scrub_name[] = "OI_scrub";
2614 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev,
2617 struct osd_thread_info *info = osd_oti_get(env);
2618 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2619 struct lvfs_run_ctxt *ctxt = &dev->od_scrub.os_ctxt;
2620 time64_t interval = scrub->os_auto_scrub_interval;
2621 struct scrub_file *sf = &scrub->os_file;
2622 struct super_block *sb = osd_sb(dev);
2623 struct lvfs_run_ctxt saved;
2625 struct inode *inode;
2626 struct lu_fid *fid = &info->oti_fid;
2627 struct osd_inode_id *id = &info->oti_id;
2628 struct dt_object *obj;
2633 memset(&dev->od_scrub, 0, sizeof(struct osd_scrub));
2634 OBD_SET_CTXT_MAGIC(ctxt);
2635 ctxt->pwdmnt = dev->od_mnt;
2636 ctxt->pwd = dev->od_mnt->mnt_root;
2638 init_rwsem(&scrub->os_rwsem);
2639 spin_lock_init(&scrub->os_lock);
2640 INIT_LIST_HEAD(&scrub->os_inconsistent_items);
2641 INIT_LIST_HEAD(&scrub->os_stale_items);
2642 scrub->os_name = osd_name(dev);
2643 scrub->os_auto_scrub_interval = interval;
2645 push_ctxt(&saved, ctxt);
2646 filp = filp_open(osd_scrub_name,
2647 (dev->od_dt_dev.dd_rdonly ? O_RDONLY :
2651 pop_ctxt(&saved, ctxt);
2652 RETURN(PTR_ERR(filp));
2655 inode = file_inode(filp);
2656 ldiskfs_set_inode_flag(inode, LDISKFS_INODE_JOURNAL_DATA);
2657 if (!dev->od_dt_dev.dd_rdonly) {
2658 /* 'What the @fid is' is not imporatant, because the object
2659 * has no OI mapping, and only is visible inside the OSD.*/
2660 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2661 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
2663 filp_close(filp, NULL);
2664 pop_ctxt(&saved, ctxt);
2669 osd_id_gen(id, inode->i_ino, inode->i_generation);
2670 osd_add_oi_cache(info, dev, id, fid);
2671 filp_close(filp, NULL);
2672 pop_ctxt(&saved, ctxt);
2674 obj = lu2dt(lu_object_find_slice(env, osd2lu_dev(dev), fid, NULL));
2675 if (IS_ERR_OR_NULL(obj))
2676 RETURN(obj ? PTR_ERR(obj) : -ENOENT);
2678 guid_copy(&dev->od_uuid, (guid_t *)&sb->s_uuid);
2679 scrub->os_obj = obj;
2680 rc = scrub_file_load(env, scrub);
2681 if (rc == -ENOENT || rc == -EFAULT) {
2682 scrub_file_init(scrub, dev->od_uuid);
2683 /* If the "/O" dir does not exist when mount (indicated by
2684 * osd_device::od_maybe_new), neither for the "/OI_scrub",
2685 * then it is quite probably that the device is a new one,
2686 * under such case, mark it as SIF_NO_HANDLE_OLD_FID.
2688 * For the rare case that "/O" and "OI_scrub" both lost on
2689 * an old device, it can be found and cleared later.
2691 * For the system with "SIF_NO_HANDLE_OLD_FID", we do not
2692 * need to check "filter_fid_18_23" and to convert it to
2693 * "filter_fid" for each object, and all the IGIF should
2694 * have their FID mapping in OI files already. */
2695 if (dev->od_maybe_new && rc == -ENOENT)
2696 sf->sf_internal_flags = SIF_NO_HANDLE_OLD_FID;
2698 } else if (rc < 0) {
2699 GOTO(cleanup_obj, rc);
2701 if (!guid_equal(&sf->sf_uuid, &dev->od_uuid)) {
2703 "%s: UUID has been changed from %pU to %pU\n",
2704 osd_dev2name(dev), &sf->sf_uuid, &dev->od_uuid);
2705 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
2708 } else if (sf->sf_status == SS_SCANNING) {
2709 sf->sf_status = SS_CRASHED;
2713 if ((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) {
2714 LCONSOLE_WARN("%s: invalid oi count %d, set it to %d\n",
2715 osd_dev2name(dev), sf->sf_oi_count,
2717 sf->sf_oi_count = osd_oi_count;
2722 if (sf->sf_pos_last_checkpoint != 0)
2723 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
2725 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
2728 rc = scrub_file_store(env, scrub);
2730 GOTO(cleanup_obj, rc);
2733 /* Initialize OI files. */
2734 rc = osd_oi_init(info, dev, restored);
2736 GOTO(cleanup_obj, rc);
2738 if (!dev->od_dt_dev.dd_rdonly)
2739 osd_initial_OI_scrub(info, dev);
2741 if (sf->sf_flags & SF_UPGRADE ||
2742 !(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID ||
2743 sf->sf_success_count > 0)) {
2744 dev->od_igif_inoi = 0;
2745 dev->od_check_ff = dev->od_is_ost;
2747 dev->od_igif_inoi = 1;
2748 dev->od_check_ff = 0;
2751 if (sf->sf_flags & SF_INCONSISTENT)
2752 /* The 'od_igif_inoi' will be set under the
2754 * 1) new created system, or
2755 * 2) restored from file-level backup, or
2756 * 3) the upgrading completed.
2758 * The 'od_igif_inoi' may be cleared by OI scrub
2759 * later if found that the system is upgrading. */
2760 dev->od_igif_inoi = 1;
2762 if (!dev->od_dt_dev.dd_rdonly &&
2763 dev->od_scrub.os_scrub.os_auto_scrub_interval != AS_NEVER &&
2764 ((sf->sf_status == SS_PAUSED) ||
2765 (sf->sf_status == SS_CRASHED &&
2766 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2767 SF_UPGRADE | SF_AUTO)) ||
2768 (sf->sf_status == SS_INIT &&
2769 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2771 rc = osd_scrub_start(env, dev, SS_AUTO_FULL);
2774 GOTO(cleanup_oi, rc);
2776 /* it is possible that dcache entries may keep objects after they are
2777 * deleted by OSD. While it looks safe this can cause object data to
2778 * stay until umount causing failures in tests calculating free space,
2779 * e.g. replay-ost-single. Since those dcache entries are not used
2780 * anymore let's just free them after use here */
2781 shrink_dcache_sb(sb);
2785 osd_oi_fini(info, dev);
2787 dt_object_put_nocache(env, scrub->os_obj);
2788 scrub->os_obj = NULL;
2793 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
2795 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2797 LASSERT(dev->od_otable_it == NULL);
2799 if (scrub->os_obj != NULL) {
2800 osd_scrub_stop(dev);
2801 dt_object_put_nocache(env, scrub->os_obj);
2802 scrub->os_obj = NULL;
2806 /* object table based iteration APIs */
2808 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
2809 struct dt_object *dt, __u32 attr)
2811 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
2812 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
2813 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
2814 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2815 struct osd_otable_it *it;
2820 /* od_otable_mutex: prevent curcurrent init/fini */
2821 mutex_lock(&dev->od_otable_mutex);
2822 if (dev->od_otable_it != NULL)
2823 GOTO(out, it = ERR_PTR(-EALREADY));
2827 GOTO(out, it = ERR_PTR(-ENOMEM));
2829 dev->od_otable_it = it;
2831 it->ooi_cache.ooc_consumer_idx = -1;
2832 if (flags & DOIF_OUTUSED)
2833 it->ooi_used_outside = 1;
2835 if (flags & DOIF_RESET)
2838 if (valid & DOIV_ERROR_HANDLE) {
2839 if (flags & DOIF_FAILOUT)
2840 start |= SS_SET_FAILOUT;
2842 start |= SS_CLEAR_FAILOUT;
2845 if (valid & DOIV_DRYRUN) {
2846 if (flags & DOIF_DRYRUN)
2847 start |= SS_SET_DRYRUN;
2849 start |= SS_CLEAR_DRYRUN;
2852 rc = scrub_start(osd_scrub_main, scrub, dev, start & ~SS_AUTO_PARTIAL);
2853 if (rc == -EALREADY) {
2854 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2855 } else if (rc < 0) {
2856 dev->od_otable_it = NULL;
2860 /* We have to start from the begining. */
2861 it->ooi_cache.ooc_pos_preload =
2862 LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2868 mutex_unlock(&dev->od_otable_mutex);
2869 return (struct dt_it *)it;
2872 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2874 struct osd_otable_it *it = (struct osd_otable_it *)di;
2875 struct osd_device *dev = it->ooi_dev;
2877 /* od_otable_mutex: prevent curcurrent init/fini */
2878 mutex_lock(&dev->od_otable_mutex);
2879 scrub_stop(&dev->od_scrub.os_scrub);
2880 LASSERT(dev->od_otable_it == it);
2882 dev->od_otable_it = NULL;
2883 mutex_unlock(&dev->od_otable_mutex);
2887 static int osd_otable_it_get(const struct lu_env *env,
2888 struct dt_it *di, const struct dt_key *key)
2893 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2898 osd_otable_it_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
2900 spin_lock(&scrub->os_lock);
2901 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2902 scrub->os_waiting || !scrub->os_running)
2903 it->ooi_waiting = 0;
2905 it->ooi_waiting = 1;
2906 spin_unlock(&scrub->os_lock);
2908 return !it->ooi_waiting;
2911 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2913 struct osd_otable_it *it = (struct osd_otable_it *)di;
2914 struct osd_device *dev = it->ooi_dev;
2915 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2916 struct osd_otable_cache *ooc = &it->ooi_cache;
2920 LASSERT(it->ooi_user_ready);
2923 if (!scrub->os_running && !it->ooi_used_outside)
2926 if (ooc->ooc_cached_items > 0) {
2927 ooc->ooc_cached_items--;
2928 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2929 ~OSD_OTABLE_IT_CACHE_MASK;
2933 if (it->ooi_all_cached) {
2934 wait_var_event(scrub, !scrub->os_running);
2938 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2939 spin_lock(&scrub->os_lock);
2940 scrub->os_waiting = 0;
2942 spin_unlock(&scrub->os_lock);
2945 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2946 wait_var_event(scrub, osd_otable_it_wakeup(scrub, it));
2948 if (!scrub->os_running && !it->ooi_used_outside)
2951 rc = osd_otable_it_preload(env, it);
2958 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2959 const struct dt_it *di)
2964 static int osd_otable_it_key_size(const struct lu_env *env,
2965 const struct dt_it *di)
2967 return sizeof(__u64);
2970 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2971 struct dt_rec *rec, __u32 attr)
2973 struct osd_otable_it *it = (struct osd_otable_it *)di;
2974 struct osd_otable_cache *ooc = &it->ooi_cache;
2976 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2978 /* Filter out Invald FID already. */
2979 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2980 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2981 PFID((struct lu_fid *)rec),
2982 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2987 static __u64 osd_otable_it_store(const struct lu_env *env,
2988 const struct dt_it *di)
2990 struct osd_otable_it *it = (struct osd_otable_it *)di;
2991 struct osd_otable_cache *ooc = &it->ooi_cache;
2994 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2995 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2997 hash = ooc->ooc_pos_preload;
3002 * Set the OSD layer iteration start position as the specified hash.
3004 static int osd_otable_it_load(const struct lu_env *env,
3005 const struct dt_it *di, __u64 hash)
3007 struct osd_otable_it *it = (struct osd_otable_it *)di;
3008 struct osd_device *dev = it->ooi_dev;
3009 struct osd_otable_cache *ooc = &it->ooi_cache;
3010 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3011 struct osd_iit_param *param = &it->ooi_iit_param;
3015 /* Forbid to set iteration position after iteration started. */
3016 if (it->ooi_user_ready)
3019 LASSERT(!scrub->os_partial_scan);
3021 if (hash > OSD_OTABLE_MAX_HASH)
3022 hash = OSD_OTABLE_MAX_HASH;
3024 /* The hash is the last checkpoint position,
3025 * we will start from the next one. */
3026 ooc->ooc_pos_preload = hash + 1;
3027 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
3028 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
3030 it->ooi_user_ready = 1;
3031 if (!scrub->os_full_speed)
3034 memset(param, 0, sizeof(*param));
3035 param->sb = osd_sb(dev);
3036 param->start = ooc->ooc_pos_preload;
3037 param->bg = (ooc->ooc_pos_preload - 1) /
3038 LDISKFS_INODES_PER_GROUP(param->sb);
3039 param->offset = (ooc->ooc_pos_preload - 1) %
3040 LDISKFS_INODES_PER_GROUP(param->sb);
3041 param->gbase = 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
3043 /* Unplug OSD layer iteration by the first next() call. */
3044 rc = osd_otable_it_next(env, (struct dt_it *)it);
3049 static int osd_otable_it_key_rec(const struct lu_env *env,
3050 const struct dt_it *di, void *key_rec)
3055 const struct dt_index_operations osd_otable_ops = {
3057 .init = osd_otable_it_init,
3058 .fini = osd_otable_it_fini,
3059 .get = osd_otable_it_get,
3060 .put = osd_otable_it_put,
3061 .next = osd_otable_it_next,
3062 .key = osd_otable_it_key,
3063 .key_size = osd_otable_it_key_size,
3064 .rec = osd_otable_it_rec,
3065 .store = osd_otable_it_store,
3066 .load = osd_otable_it_load,
3067 .key_rec = osd_otable_it_key_rec,
3071 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
3073 struct osd_scrub *scrub = &dev->od_scrub;
3075 scrub_dump(m, &scrub->os_scrub);
3076 seq_printf(m, "lf_scanned: %llu\n"
3078 "lf_failed: %llu\n",
3079 scrub->os_lf_scanned,
3080 scrub->os_scrub.os_file.sf_param & SP_DRYRUN ?
3081 "inconsistent" : "repaired",
3082 scrub->os_lf_repaired,
3083 scrub->os_lf_failed);
3086 typedef int (*scan_dir_helper_t)(const struct lu_env *env,
3087 struct osd_device *dev, struct inode *dir,
3088 struct osd_it_ea *oie);
3090 static int osd_scan_dir(const struct lu_env *env, struct osd_device *dev,
3091 struct inode *inode, scan_dir_helper_t cb)
3093 struct osd_it_ea *oie;
3098 oie = osd_it_dir_init(env, dev, inode, LUDA_TYPE);
3100 RETURN(PTR_ERR(oie));
3102 oie->oie_file->f_pos = 0;
3103 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3109 while (oie->oie_it_dirent <= oie->oie_rd_dirent) {
3110 if (!name_is_dot_or_dotdot(oie->oie_dirent->oied_name,
3111 oie->oie_dirent->oied_namelen))
3112 cb(env, dev, inode, oie);
3114 oie->oie_dirent = (void *)oie->oie_dirent +
3115 round_up(sizeof(struct osd_it_ea_dirent) +
3116 oie->oie_dirent->oied_namelen, 8);
3118 oie->oie_it_dirent++;
3119 if (oie->oie_it_dirent <= oie->oie_rd_dirent)
3122 if (oie->oie_file->f_pos ==
3123 ldiskfs_get_htree_eof(oie->oie_file))
3126 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3135 osd_it_dir_fini(env, oie, inode);
3139 static int osd_remove_ml_file(struct osd_thread_info *info,
3140 struct osd_device *dev, struct inode *dir,
3141 struct inode *inode, struct osd_it_ea *oie)
3144 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3145 struct dentry dentry;
3150 if (scrub->os_file.sf_param & SP_DRYRUN)
3153 th = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
3154 osd_dto_credits_noquota[DTO_INDEX_DELETE] +
3155 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
3157 RETURN(PTR_ERR(th));
3159 /* Should be created by the VFS layer */
3160 dentry.d_inode = dir;
3161 dentry.d_sb = dir->i_sb;
3162 rc = osd_obj_del_entry(info, dev, &dentry, oie->oie_dirent->oied_name,
3163 oie->oie_dirent->oied_namelen, th);
3165 mark_inode_dirty(inode);
3166 ldiskfs_journal_stop(th);
3170 static int osd_scan_ml_file(const struct lu_env *env, struct osd_device *dev,
3171 struct inode *dir, struct osd_it_ea *oie)
3173 struct osd_thread_info *info = osd_oti_get(env);
3174 struct osd_inode_id id;
3175 struct inode *inode;
3176 struct osd_obj_seq *oseq;
3177 struct ost_id *ostid = &info->oti_ostid;
3178 struct lu_fid *fid = &oie->oie_dirent->oied_fid;
3184 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3186 if (!fid_is_sane(fid))
3187 inode = osd_iget_fid(info, dev, &id, fid);
3189 inode = osd_iget(info, dev, &id);
3192 RETURN(PTR_ERR(inode));
3194 fid_to_ostid(fid, ostid);
3195 oseq = osd_seq_load(info, dev, ostid_seq(ostid));
3197 RETURN(PTR_ERR(oseq));
3199 dirn = ostid_id(ostid) & (oseq->oos_subdir_count - 1);
3200 LASSERT(oseq->oos_dirs[dirn] != NULL);
3202 osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
3203 if (((strlen(oseq->oos_root->d_name.name) !=
3204 info->oti_seq_dirent->oied_namelen) ||
3205 strncmp(oseq->oos_root->d_name.name,
3206 info->oti_seq_dirent->oied_name,
3207 info->oti_seq_dirent->oied_namelen) != 0) ||
3208 ((strlen(oseq->oos_dirs[dirn]->d_name.name) !=
3209 info->oti_dir_dirent->oied_namelen) ||
3210 strncmp(oseq->oos_dirs[dirn]->d_name.name,
3211 info->oti_dir_dirent->oied_name,
3212 info->oti_dir_dirent->oied_namelen) != 0) ||
3213 ((strlen(name) != oie->oie_dirent->oied_namelen) ||
3214 strncmp(oie->oie_dirent->oied_name, name,
3215 oie->oie_dirent->oied_namelen) != 0)) {
3216 CDEBUG(D_LFSCK, "%s: the file O/%s/%s/%s is corrupted\n",
3217 osd_name(dev), info->oti_seq_dirent->oied_name,
3218 info->oti_dir_dirent->oied_name,
3219 oie->oie_dirent->oied_name);
3221 rc = osd_remove_ml_file(info, dev, dir, inode, oie);
3228 static int osd_scan_ml_file_dir(const struct lu_env *env,
3229 struct osd_device *dev, struct inode *dir,
3230 struct osd_it_ea *oie)
3232 struct osd_thread_info *info = osd_oti_get(env);
3233 struct inode *inode;
3234 struct osd_inode_id id;
3239 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3240 inode = osd_iget(info, dev, &id);
3242 RETURN(PTR_ERR(inode));
3244 if (!S_ISDIR(inode->i_mode))
3247 info->oti_dir_dirent = oie->oie_dirent;
3248 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file);
3249 info->oti_dir_dirent = NULL;
3256 static int osd_scan_ml_file_seq(const struct lu_env *env,
3257 struct osd_device *dev, struct inode *dir,
3258 struct osd_it_ea *oie)
3260 struct osd_thread_info *info = osd_oti_get(env);
3261 struct inode *inode;
3262 struct osd_inode_id id;
3267 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3268 inode = osd_iget(info, dev, &id);
3270 RETURN(PTR_ERR(inode));
3272 if (!S_ISDIR(inode->i_mode))
3275 info->oti_seq_dirent = oie->oie_dirent;
3276 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file_dir);
3277 info->oti_seq_dirent = NULL;
3284 static int osd_scan_ml_file_main(const struct lu_env *env,
3285 struct osd_device *dev)
3287 return osd_scan_dir(env, dev, dev->od_ost_map->om_root->d_inode,
3288 osd_scan_ml_file_seq);