4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2012, 2017, Intel Corporation.
26 * lustre/osd-ldiskfs/osd_scrub.c
28 * Top-level entry points into osd module
30 * The OI scrub is used for rebuilding Object Index files when restores MDT from
33 * The otable based iterator scans ldiskfs inode table to feed up layer LFSCK.
35 * Author: Fan Yong <yong.fan@whamcloud.com>
38 #define DEBUG_SUBSYSTEM S_LFSCK
40 #include <linux/kthread.h>
41 #include <uapi/linux/lustre/lustre_idl.h>
42 #include <lustre_disk.h>
43 #include <dt_object.h>
44 #include <linux/xattr.h>
45 #include <lustre_scrub.h>
46 #include <lustre_nodemap.h>
48 #include "osd_internal.h"
50 #include "osd_scrub.h"
52 #define OSD_OTABLE_MAX_HASH 0x00000000ffffffffULL
54 static inline int osd_scrub_has_window(struct lustre_scrub *scrub,
55 struct osd_otable_cache *ooc)
57 return scrub->os_pos_current < ooc->ooc_pos_preload + SCRUB_WINDOW_SIZE;
61 * update/insert/delete the specified OI mapping (@fid @id) according to the ops
63 * \retval 1, changed nothing
64 * \retval 0, changed successfully
65 * \retval -ve, on error
67 int osd_scrub_refresh_mapping(struct osd_thread_info *info,
68 struct osd_device *dev,
69 const struct lu_fid *fid,
70 const struct osd_inode_id *id,
72 enum oi_check_flags flags, bool *exist)
78 if (dev->od_scrub.os_scrub.os_file.sf_param & SP_DRYRUN && !force)
81 /* DTO_INDEX_INSERT is enough for other two ops:
82 * delete/update, but save stack. */
83 th = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
84 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
87 CDEBUG(D_LFSCK, "%s: fail to start trans for scrub op %d "
88 DFID" => %u/%u: rc = %d\n", osd_name(dev), ops,
89 PFID(fid), id ? id->oii_ino : -1, id ? id->oii_gen : -1,
95 case DTO_INDEX_UPDATE:
96 rc = osd_oi_update(info, dev, fid, id, th, flags);
97 if (unlikely(rc == -ENOENT)) {
98 /* Some unlink thread may removed the OI mapping. */
102 case DTO_INDEX_INSERT:
103 rc = osd_oi_insert(info, dev, fid, id, th, flags, exist);
104 if (unlikely(rc == -EEXIST)) {
106 /* XXX: There are trouble things when adding OI
107 * mapping for IGIF object, which may cause
108 * multiple objects to be mapped to the same
109 * IGIF formatted FID. Consider the following
112 * 1) The MDT is upgrading from 1.8 device.
113 * The OI scrub generates IGIF FID1 for the
114 * OBJ1 and adds the OI mapping.
116 * 2) For some reason, the OI scrub does not
117 * process all the IGIF objects completely.
119 * 3) The MDT is backuped and restored against
122 * 4) When the MDT mounts up, the OI scrub will
123 * try to rebuild the OI files. For some IGIF
124 * object, OBJ2, which was not processed by the
125 * OI scrub before the backup/restore, and the
126 * new generated IGIF formatted FID may be just
127 * the FID1, the same as OBJ1.
129 * Under such case, the OI scrub cannot know how
130 * to generate new FID for the OBJ2.
132 * Currently, we do nothing for that. One possible
133 * solution is to generate new normal FID for the
136 * Anyway, it is rare, only exists in theory. */
139 case DTO_INDEX_DELETE:
140 rc = osd_oi_delete(info, dev, fid, th, flags);
142 /* It is normal that the unlink thread has removed the
143 * OI mapping already. */
148 LASSERTF(0, "Unexpected ops %d\n", ops);
152 ldiskfs_journal_stop(th);
154 CDEBUG(D_LFSCK, "%s: fail to refresh OI map for scrub op %d "
155 DFID" => %u/%u: rc = %d\n", osd_name(dev), ops,
156 PFID(fid), id ? id->oii_ino : -1, id ? id->oii_gen : -1,
163 osd_scrub_convert_ff(struct osd_thread_info *info, struct osd_device *dev,
164 struct inode *inode, const struct lu_fid *fid)
166 struct filter_fid_18_23 *ff = &info->oti_ff_old;
167 struct dentry *dentry = &info->oti_obj_dentry;
168 struct lu_fid *tfid = &info->oti_fid;
169 bool fid_18_23 = false;
175 if (dev->od_scrub.os_scrub.os_file.sf_param & SP_DRYRUN)
178 if (fid_is_idif(fid) && dev->od_index_in_idif == 0) {
179 struct ost_id *oi = &info->oti_ostid;
181 fid_to_ostid(fid, oi);
182 ostid_to_fid(tfid, oi, 0);
187 /* We want the LMA to fit into the 256-byte OST inode, so operate
189 * 1) read old XATTR_NAME_FID and save the parent FID;
190 * 2) delete the old XATTR_NAME_FID;
191 * 3) make new LMA and add it;
192 * 4) generate new XATTR_NAME_FID with the saved parent FID and add it.
194 * Making the LMA to fit into the 256-byte OST inode can save time for
195 * normal osd_check_lma() and for other OI scrub scanning in future.
196 * So it is worth to make some slow conversion here. */
197 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
198 osd_dto_credits_noquota[DTO_XATTR_SET] * 3);
201 CDEBUG(D_LFSCK, "%s: fail to start trans for convert ff "
202 DFID": rc = %d\n", osd_name(dev), PFID(tfid), rc);
206 /* 1) read old XATTR_NAME_FID and save the parent FID */
207 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_FID, ff, sizeof(*ff));
208 if (rc == sizeof(*ff)) {
209 /* 2) delete the old XATTR_NAME_FID */
210 dquot_initialize(inode);
211 rc = ll_vfs_removexattr(dentry, inode, XATTR_NAME_FID);
216 } else if (rc != -ENODATA && rc < (int)sizeof(struct filter_fid_24_29)) {
217 GOTO(stop, rc = -EINVAL);
220 /* 3) make new LMA and add it */
221 rc = osd_ea_fid_set(info, inode, tfid, LMAC_FID_ON_OST, 0);
224 /* If failed, we should try to add the old back. */
227 /* The new PFID EA will only contains ::ff_parent */
228 size = sizeof(ff->ff_parent);
231 /* 4) generate new XATTR_NAME_FID with the saved parent FID and add it*/
235 rc1 = __osd_xattr_set(info, inode, XATTR_NAME_FID, ff, size,
237 if (rc1 != 0 && rc == 0)
244 ldiskfs_journal_stop(jh);
246 CDEBUG(D_LFSCK, "%s: fail to convert ff "DFID": rc = %d\n",
247 osd_name(dev), PFID(tfid), rc);
252 osd_scrub_check_update(struct osd_thread_info *info, struct osd_device *dev,
253 struct osd_idmap_cache *oic, int val)
255 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
256 struct scrub_file *sf = &scrub->os_file;
257 struct lu_fid *fid = &oic->oic_fid;
258 struct osd_inode_id *lid = &oic->oic_lid;
259 struct osd_inode_id *lid2 = &info->oti_id;
260 struct osd_inconsistent_item *oii = NULL;
261 struct inode *inode = NULL;
262 int ops = DTO_INDEX_UPDATE;
264 bool converted = false;
268 down_write(&scrub->os_rwsem);
269 scrub->os_new_checked++;
273 if (scrub->os_in_prior)
274 oii = list_entry(oic, struct osd_inconsistent_item,
277 if (lid->oii_ino < sf->sf_pos_latest_start && oii == NULL)
280 if (fid_is_igif(fid))
283 if (val == SCRUB_NEXT_OSTOBJ_OLD) {
284 inode = osd_iget(info, dev, lid);
287 /* Someone removed the inode. */
288 if (rc == -ENOENT || rc == -ESTALE)
293 /* The inode has been reused as EA inode, ignore it. */
294 if (unlikely(osd_is_ea_inode(inode)))
297 sf->sf_flags |= SF_UPGRADE;
298 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
299 dev->od_check_ff = 1;
300 rc = osd_scrub_convert_ff(info, dev, inode, fid);
307 if ((val == SCRUB_NEXT_NOLMA) &&
308 (!scrub->os_convert_igif || OBD_FAIL_CHECK(OBD_FAIL_FID_NOLMA)))
311 if ((oii != NULL && oii->oii_insert) || (val == SCRUB_NEXT_NOLMA)) {
312 ops = DTO_INDEX_INSERT;
317 rc = osd_oi_lookup(info, dev, fid, lid2,
318 (val == SCRUB_NEXT_OSTOBJ ||
319 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0);
322 ops = DTO_INDEX_INSERT;
323 else if (rc != -ESTALE)
328 inode = osd_iget(info, dev, lid);
331 /* Someone removed the inode. */
332 if (rc == -ENOENT || rc == -ESTALE)
337 /* The inode has been reused as EA inode, ignore it. */
338 if (unlikely(osd_is_ea_inode(inode)))
343 case SCRUB_NEXT_NOLMA:
344 sf->sf_flags |= SF_UPGRADE;
345 if (!(sf->sf_param & SP_DRYRUN)) {
346 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
351 if (!(sf->sf_flags & SF_INCONSISTENT))
352 dev->od_igif_inoi = 0;
354 case SCRUB_NEXT_OSTOBJ:
355 sf->sf_flags |= SF_INCONSISTENT;
356 case SCRUB_NEXT_OSTOBJ_OLD:
361 } else if (osd_id_eq(lid, lid2)) {
363 sf->sf_items_updated++;
367 if (!scrub->os_partial_scan) {
368 spin_lock(&scrub->os_lock);
369 scrub->os_full_speed = 1;
370 spin_unlock(&scrub->os_lock);
372 sf->sf_flags |= SF_INCONSISTENT;
374 /* XXX: If the device is restored from file-level backup, then
375 * some IGIFs may have been already in OI files, and some
376 * may be not yet. Means upgrading from 1.8 may be partly
377 * processed, but some clients may hold some immobilized
378 * IGIFs, and use them to access related objects. Under
379 * such case, OSD does not know whether an given IGIF has
380 * been processed or to be processed, and it also cannot
381 * generate local ino#/gen# directly from the immobilized
382 * IGIF because of the backup/restore. Then force OSD to
383 * lookup the given IGIF in OI files, and if no entry,
384 * then ask the client to retry after upgrading completed.
385 * No better choice. */
386 dev->od_igif_inoi = 1;
389 rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops, false,
390 (val == SCRUB_NEXT_OSTOBJ ||
391 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0,
394 if (scrub->os_in_prior)
395 sf->sf_items_updated_prior++;
397 sf->sf_items_updated++;
399 if (ops == DTO_INDEX_INSERT && val == 0 && !exist) {
400 int idx = osd_oi_fid2idx(dev, fid);
402 sf->sf_flags |= SF_RECREATED;
403 if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
404 ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
412 sf->sf_items_failed++;
413 if (sf->sf_pos_first_inconsistent == 0 ||
414 sf->sf_pos_first_inconsistent > lid->oii_ino)
415 sf->sf_pos_first_inconsistent = lid->oii_ino;
420 /* There may be conflict unlink during the OI scrub,
421 * if happend, then remove the new added OI mapping. */
422 if (ops == DTO_INDEX_INSERT && inode != NULL && !IS_ERR(inode) &&
423 unlikely(ldiskfs_test_inode_state(inode,
424 LDISKFS_STATE_LUSTRE_DESTROY)))
425 osd_scrub_refresh_mapping(info, dev, fid, lid,
426 DTO_INDEX_DELETE, false,
427 (val == SCRUB_NEXT_OSTOBJ ||
428 val == SCRUB_NEXT_OSTOBJ_OLD) ?
429 OI_KNOWN_ON_OST : 0, NULL);
430 up_write(&scrub->os_rwsem);
436 spin_lock(&scrub->os_lock);
437 if (likely(!list_empty(&oii->oii_list)))
438 list_del(&oii->oii_list);
439 spin_unlock(&scrub->os_lock);
444 RETURN(sf->sf_param & SP_FAILOUT ? rc : 0);
447 static int osd_scrub_prep(const struct lu_env *env, struct osd_device *dev)
449 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
450 struct scrub_file *sf = &scrub->os_file;
451 __u32 flags = scrub->os_start_flags;
453 bool drop_dryrun = false;
456 CDEBUG(D_LFSCK, "%s: OI scrub prep, flags = 0x%x\n",
457 osd_scrub2name(scrub), flags);
459 down_write(&scrub->os_rwsem);
460 if (flags & SS_SET_FAILOUT)
461 sf->sf_param |= SP_FAILOUT;
462 else if (flags & SS_CLEAR_FAILOUT)
463 sf->sf_param &= ~SP_FAILOUT;
465 if (flags & SS_SET_DRYRUN) {
466 sf->sf_param |= SP_DRYRUN;
467 } else if (flags & SS_CLEAR_DRYRUN && sf->sf_param & SP_DRYRUN) {
468 sf->sf_param &= ~SP_DRYRUN;
472 if (flags & SS_RESET)
473 scrub_file_reset(scrub, dev->od_uuid, 0);
475 spin_lock(&scrub->os_lock);
476 if (flags & SS_AUTO_FULL) {
477 scrub->os_full_speed = 1;
478 scrub->os_partial_scan = 0;
479 sf->sf_flags |= SF_AUTO;
480 } else if (flags & SS_AUTO_PARTIAL) {
481 scrub->os_full_speed = 0;
482 scrub->os_partial_scan = 1;
483 sf->sf_flags |= SF_AUTO;
484 } else if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
486 scrub->os_full_speed = 1;
487 scrub->os_partial_scan = 0;
489 scrub->os_full_speed = 0;
490 scrub->os_partial_scan = 0;
493 scrub->os_in_prior = 0;
494 scrub->os_waiting = 0;
495 scrub->os_paused = 0;
496 scrub->os_in_join = 0;
497 scrub->os_full_scrub = 0;
498 spin_unlock(&scrub->os_lock);
499 scrub->os_new_checked = 0;
500 if (drop_dryrun && sf->sf_pos_first_inconsistent != 0)
501 sf->sf_pos_latest_start = sf->sf_pos_first_inconsistent;
502 else if (sf->sf_pos_last_checkpoint != 0)
503 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
505 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
507 scrub->os_pos_current = sf->sf_pos_latest_start;
508 sf->sf_status = SS_SCANNING;
509 sf->sf_time_latest_start = ktime_get_real_seconds();
510 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
511 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
512 rc = scrub_file_store(env, scrub);
514 spin_lock(&scrub->os_lock);
515 scrub->os_running = 1;
516 spin_unlock(&scrub->os_lock);
519 up_write(&scrub->os_rwsem);
524 static int osd_scrub_post(const struct lu_env *env, struct osd_device *dev,
527 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
528 struct scrub_file *sf = &scrub->os_file;
532 CDEBUG(D_LFSCK, "%s: OI scrub post with result = %d\n",
533 osd_scrub2name(scrub), result);
535 down_write(&scrub->os_rwsem);
536 spin_lock(&scrub->os_lock);
537 scrub->os_running = 0;
538 spin_unlock(&scrub->os_lock);
539 if (scrub->os_new_checked > 0) {
540 sf->sf_items_checked += scrub->os_new_checked;
541 scrub->os_new_checked = 0;
542 sf->sf_pos_last_checkpoint = scrub->os_pos_current;
544 sf->sf_time_last_checkpoint = ktime_get_real_seconds();
546 dev->od_igif_inoi = 1;
547 dev->od_check_ff = 0;
548 sf->sf_status = SS_COMPLETED;
549 if (!(sf->sf_param & SP_DRYRUN)) {
550 memset(sf->sf_oi_bitmap, 0, SCRUB_OI_BITMAP_SIZE);
551 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
552 SF_UPGRADE | SF_AUTO);
554 sf->sf_time_last_complete = sf->sf_time_last_checkpoint;
555 sf->sf_success_count++;
556 } else if (result == 0) {
557 if (scrub->os_paused)
558 sf->sf_status = SS_PAUSED;
560 sf->sf_status = SS_STOPPED;
562 sf->sf_status = SS_FAILED;
564 sf->sf_run_time += ktime_get_seconds() -
565 scrub->os_time_last_checkpoint;
567 rc = scrub_file_store(env, scrub);
568 up_write(&scrub->os_rwsem);
570 RETURN(rc < 0 ? rc : result);
573 /* iteration engine */
575 typedef int (*osd_iit_next_policy)(struct osd_thread_info *info,
576 struct osd_device *dev,
577 struct osd_iit_param *param,
578 struct osd_idmap_cache **oic,
581 typedef int (*osd_iit_exec_policy)(struct osd_thread_info *info,
582 struct osd_device *dev,
583 struct osd_iit_param *param,
584 struct osd_idmap_cache *oic,
585 bool *noslot, int rc);
587 static int osd_iit_next(struct osd_iit_param *param, __u64 *pos)
592 param->offset = ldiskfs_find_next_bit(param->bitmap->b_data,
593 LDISKFS_INODES_PER_GROUP(param->sb), param->offset);
594 if (param->offset >= LDISKFS_INODES_PER_GROUP(param->sb)) {
595 *pos = 1 + (param->bg+1) * LDISKFS_INODES_PER_GROUP(param->sb);
596 return SCRUB_NEXT_BREAK;
599 offset = param->offset++;
600 if (unlikely(*pos == param->gbase + offset && *pos != param->start)) {
601 /* We should NOT find the same object more than once. */
602 CERROR("%s: scan the same object multiple times at the pos: "
603 "group = %u, base = %u, offset = %u, start = %u\n",
604 osd_sb2name(param->sb), (__u32)param->bg, param->gbase,
605 offset, param->start);
609 *pos = param->gbase + offset;
614 * \retval SCRUB_NEXT_OSTOBJ_OLD: FID-on-OST
615 * \retval 0: FID-on-MDT
617 static int osd_scrub_check_local_fldb(struct osd_thread_info *info,
618 struct osd_device *dev,
621 /* XXX: The initial OI scrub will scan the top level /O to generate
622 * a small local FLDB according to the <seq>. If the given FID
623 * is in the local FLDB, then it is FID-on-OST; otherwise it's
624 * quite possible for FID-on-MDT. */
626 return SCRUB_NEXT_OSTOBJ_OLD;
631 static int osd_scrub_get_fid(struct osd_thread_info *info,
632 struct osd_device *dev, struct inode *inode,
633 struct lu_fid *fid, bool scrub)
635 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
636 bool has_lma = false;
639 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
640 &info->oti_ost_attrs);
643 if (lma->lma_compat & LMAC_NOT_IN_OI ||
644 lma->lma_incompat & LMAI_AGENT)
645 return SCRUB_NEXT_CONTINUE;
647 *fid = lma->lma_self_fid;
651 if (lma->lma_compat & LMAC_FID_ON_OST)
652 return SCRUB_NEXT_OSTOBJ;
654 if (fid_is_idif(fid))
655 return SCRUB_NEXT_OSTOBJ_OLD;
657 /* For local object. */
658 if (fid_is_internal(fid))
661 /* For external visible MDT-object with non-normal FID. */
662 if (fid_is_namespace_visible(fid) && !fid_is_norm(fid))
665 /* For the object with normal FID, it may be MDT-object,
666 * or may be 2.4 OST-object, need further distinguish.
667 * Fall through to next section. */
670 if (rc == -ENODATA || rc == 0) {
671 rc = osd_get_idif(info, inode, &info->oti_obj_dentry, fid);
674 /* It is 2.3 or older OST-object. */
675 rc = SCRUB_NEXT_OSTOBJ_OLD;
681 /* It is FID-on-OST, but we do not know how
682 * to generate its FID, ignore it directly. */
683 rc = SCRUB_NEXT_CONTINUE;
685 /* It is 2.4 or newer OST-object. */
686 rc = SCRUB_NEXT_OSTOBJ_OLD;
694 if (dev->od_scrub.os_scrub.os_convert_igif) {
695 lu_igif_build(fid, inode->i_ino,
696 inode->i_generation);
698 rc = SCRUB_NEXT_NOLMA;
702 /* It may be FID-on-OST, or may be FID for
703 * non-MDT0, anyway, we do not know how to
704 * generate its FID, ignore it directly. */
705 rc = SCRUB_NEXT_CONTINUE;
710 /* For OI scrub case only: the object has LMA but has no ff
711 * (or ff crashed). It may be MDT-object, may be OST-object
712 * with crashed ff. The last check is local FLDB. */
713 rc = osd_scrub_check_local_fldb(info, dev, fid);
719 static int osd_iit_iget(struct osd_thread_info *info, struct osd_device *dev,
720 struct lu_fid *fid, struct osd_inode_id *lid, __u32 pos,
721 struct super_block *sb, bool scrub)
727 /* Not handle the backend root object and agent parent object.
728 * They are neither visible to namespace nor have OI mappings. */
729 if (unlikely(pos == osd_sb(dev)->s_root->d_inode->i_ino ||
730 is_remote_parent_ino(dev, pos)))
731 RETURN(SCRUB_NEXT_CONTINUE);
733 /* Skip project quota inode since it is greater than s_first_ino. */
734 #ifdef HAVE_PROJECT_QUOTA
735 if (ldiskfs_has_feature_project(sb) &&
736 pos == le32_to_cpu(LDISKFS_SB(sb)->s_es->s_prj_quota_inum))
737 RETURN(SCRUB_NEXT_CONTINUE);
740 osd_id_gen(lid, pos, OSD_OII_NOGEN);
741 inode = osd_iget(info, dev, lid);
744 /* The inode may be removed after bitmap searching, or the
745 * file is new created without inode initialized yet. */
746 if (rc == -ENOENT || rc == -ESTALE)
747 RETURN(SCRUB_NEXT_CONTINUE);
749 CDEBUG(D_LFSCK, "%s: fail to read inode, ino# = %u: "
750 "rc = %d\n", osd_dev2name(dev), pos, rc);
754 if (dev->od_is_ost && S_ISREG(inode->i_mode) && inode->i_nlink > 1)
755 dev->od_scrub.os_scrub.os_has_ml_file = 1;
757 /* It is an EA inode, no OI mapping for it, skip it. */
758 if (osd_is_ea_inode(inode))
759 GOTO(put, rc = SCRUB_NEXT_CONTINUE);
762 ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB)) {
763 /* Only skip it for the first OI scrub accessing. */
764 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
765 GOTO(put, rc = SCRUB_NEXT_NOSCRUB);
768 rc = osd_scrub_get_fid(info, dev, inode, fid, scrub);
777 static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
778 struct osd_iit_param *param,
779 struct osd_idmap_cache **oic, const bool noslot)
781 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
783 struct osd_inode_id *lid;
786 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0)
787 wait_var_event_timeout(
789 !list_empty(&scrub->os_inconsistent_items) ||
790 kthread_should_stop(),
791 cfs_time_seconds(cfs_fail_val));
793 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_CRASH)) {
794 spin_lock(&scrub->os_lock);
795 scrub->os_running = 0;
796 spin_unlock(&scrub->os_lock);
797 return SCRUB_NEXT_CRASH;
800 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_FATAL))
801 return SCRUB_NEXT_FATAL;
803 if (kthread_should_stop())
804 return SCRUB_NEXT_EXIT;
806 if (!list_empty(&scrub->os_inconsistent_items)) {
807 spin_lock(&scrub->os_lock);
808 if (likely(!list_empty(&scrub->os_inconsistent_items))) {
809 struct osd_inconsistent_item *oii;
811 oii = list_entry(scrub->os_inconsistent_items.next,
812 struct osd_inconsistent_item, oii_list);
814 *oic = &oii->oii_cache;
815 scrub->os_in_prior = 1;
816 spin_unlock(&scrub->os_lock);
820 spin_unlock(&scrub->os_lock);
824 return SCRUB_NEXT_WAIT;
826 rc = osd_iit_next(param, &scrub->os_pos_current);
830 *oic = &dev->od_scrub.os_oic;
831 fid = &(*oic)->oic_fid;
832 lid = &(*oic)->oic_lid;
833 rc = osd_iit_iget(info, dev, fid, lid,
834 scrub->os_pos_current, param->sb, true);
838 static int osd_preload_next(struct osd_thread_info *info,
839 struct osd_device *dev, struct osd_iit_param *param,
840 struct osd_idmap_cache **oic, const bool noslot)
842 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
843 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
846 if (scrub->os_running &&
847 ooc->ooc_pos_preload >= scrub->os_pos_current)
848 return SCRUB_NEXT_EXIT;
850 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
854 rc = osd_iit_iget(info, dev,
855 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
856 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
857 ooc->ooc_pos_preload, param->sb, false);
862 osd_scrub_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
864 spin_lock(&scrub->os_lock);
865 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
866 !list_empty(&scrub->os_inconsistent_items) ||
867 it->ooi_waiting || kthread_should_stop())
868 scrub->os_waiting = 0;
870 scrub->os_waiting = 1;
871 spin_unlock(&scrub->os_lock);
873 return !scrub->os_waiting;
876 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
877 struct osd_iit_param *param,
878 struct osd_idmap_cache *oic, bool *noslot, int rc)
880 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
881 struct scrub_file *sf = &scrub->os_file;
882 struct osd_otable_it *it = dev->od_otable_it;
883 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
886 case SCRUB_NEXT_NOSCRUB:
887 down_write(&scrub->os_rwsem);
888 scrub->os_new_checked++;
889 sf->sf_items_noscrub++;
890 up_write(&scrub->os_rwsem);
891 case SCRUB_NEXT_CONTINUE:
892 case SCRUB_NEXT_WAIT:
896 rc = osd_scrub_check_update(info, dev, oic, rc);
898 spin_lock(&scrub->os_lock);
899 scrub->os_in_prior = 0;
900 spin_unlock(&scrub->os_lock);
904 rc = scrub_checkpoint(info->oti_env, scrub);
906 CDEBUG(D_LFSCK, "%s: fail to checkpoint, pos = %llu: "
907 "rc = %d\n", osd_scrub2name(scrub),
908 scrub->os_pos_current, rc);
909 /* Continue, as long as the scrub itself can go ahead. */
912 if (scrub->os_in_prior) {
913 spin_lock(&scrub->os_lock);
914 scrub->os_in_prior = 0;
915 spin_unlock(&scrub->os_lock);
920 if (it != NULL && it->ooi_waiting && ooc != NULL &&
921 ooc->ooc_pos_preload < scrub->os_pos_current) {
922 spin_lock(&scrub->os_lock);
925 spin_unlock(&scrub->os_lock);
928 if (rc == SCRUB_NEXT_CONTINUE)
931 if (scrub->os_full_speed || !ooc || osd_scrub_has_window(scrub, ooc)) {
937 wait_var_event(scrub, osd_scrub_wakeup(scrub, it));
939 if (!ooc || osd_scrub_has_window(scrub, ooc))
946 static int osd_preload_exec(struct osd_thread_info *info,
947 struct osd_device *dev, struct osd_iit_param *param,
948 struct osd_idmap_cache *oic, bool *noslot, int rc)
950 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
953 ooc->ooc_cached_items++;
954 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
955 ~OSD_OTABLE_IT_CACHE_MASK;
957 return rc > 0 ? 0 : rc;
960 #define SCRUB_IT_ALL 1
961 #define SCRUB_IT_CRASH 2
963 static void osd_scrub_join(const struct lu_env *env, struct osd_device *dev,
964 __u32 flags, bool inconsistent)
966 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
967 struct scrub_file *sf = &scrub->os_file;
971 LASSERT(!(flags & SS_AUTO_PARTIAL));
973 down_write(&scrub->os_rwsem);
974 spin_lock(&scrub->os_lock);
975 scrub->os_in_join = 1;
976 if (flags & SS_SET_FAILOUT)
977 sf->sf_param |= SP_FAILOUT;
978 else if (flags & SS_CLEAR_FAILOUT)
979 sf->sf_param &= ~SP_FAILOUT;
981 if (flags & SS_SET_DRYRUN)
982 sf->sf_param |= SP_DRYRUN;
983 else if (flags & SS_CLEAR_DRYRUN)
984 sf->sf_param &= ~SP_DRYRUN;
986 if (flags & SS_RESET) {
987 scrub_file_reset(scrub, dev->od_uuid,
988 inconsistent ? SF_INCONSISTENT : 0);
989 sf->sf_status = SS_SCANNING;
992 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
993 scrub->os_full_speed = 1;
995 scrub->os_full_speed = 0;
997 if (flags & SS_AUTO_FULL) {
998 sf->sf_flags |= SF_AUTO;
999 scrub->os_full_speed = 1;
1001 spin_unlock(&scrub->os_lock);
1003 scrub->os_new_checked = 0;
1004 if (sf->sf_pos_last_checkpoint != 0)
1005 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
1007 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
1009 scrub->os_pos_current = sf->sf_pos_latest_start;
1010 sf->sf_time_latest_start = ktime_get_real_seconds();
1011 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
1012 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
1013 rc = scrub_file_store(env, scrub);
1015 spin_lock(&scrub->os_lock);
1016 scrub->os_waiting = 0;
1017 scrub->os_paused = 0;
1018 scrub->os_partial_scan = 0;
1019 scrub->os_in_join = 0;
1020 scrub->os_full_scrub = 0;
1021 spin_unlock(&scrub->os_lock);
1023 up_write(&scrub->os_rwsem);
1025 CDEBUG(D_LFSCK, "%s: joined in the OI scrub with flag %u: rc = %d\n",
1026 osd_scrub2name(scrub), flags, rc);
1031 static int osd_inode_iteration(struct osd_thread_info *info,
1032 struct osd_device *dev, __u32 max, bool preload)
1034 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1035 struct scrub_file *sf = &scrub->os_file;
1036 osd_iit_next_policy next;
1037 osd_iit_exec_policy exec;
1040 struct osd_iit_param *param;
1049 param = &dev->od_scrub.os_iit_param;
1050 memset(param, 0, sizeof(*param));
1051 param->sb = osd_sb(dev);
1053 while (scrub->os_partial_scan && !scrub->os_in_join) {
1054 struct osd_idmap_cache *oic = NULL;
1056 rc = osd_scrub_next(info, dev, param, &oic, noslot);
1058 case SCRUB_NEXT_EXIT:
1060 case SCRUB_NEXT_CRASH:
1061 RETURN(SCRUB_IT_CRASH);
1062 case SCRUB_NEXT_FATAL:
1064 case SCRUB_NEXT_WAIT: {
1065 struct kstatfs *ksfs = &info->oti_ksfs;
1068 if (dev->od_full_scrub_ratio == OFSR_NEVER ||
1069 unlikely(sf->sf_items_updated_prior == 0))
1072 if (dev->od_full_scrub_ratio == OFSR_DIRECTLY ||
1073 scrub->os_full_scrub) {
1074 osd_scrub_join(info->oti_env, dev,
1075 SS_AUTO_FULL | SS_RESET, true);
1079 rc = param->sb->s_op->statfs(param->sb->s_root, ksfs);
1081 __u64 used = ksfs->f_files - ksfs->f_ffree;
1083 used = div64_u64(used, sf->sf_items_updated_prior);
1084 /* If we hit too much inconsistent OI
1085 * mappings during the partial scan,
1086 * then scan the device completely. */
1087 if (used < dev->od_full_scrub_ratio) {
1088 osd_scrub_join(info->oti_env, dev,
1089 SS_AUTO_FULL | SS_RESET, true);
1095 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) &&
1099 saved_flags = sf->sf_flags;
1100 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
1101 SF_UPGRADE | SF_AUTO);
1102 sf->sf_status = SS_COMPLETED;
1105 kthread_should_stop() ||
1106 !scrub->os_partial_scan ||
1107 scrub->os_in_join ||
1108 !list_empty(&scrub->os_inconsistent_items));
1109 sf->sf_flags = saved_flags;
1110 sf->sf_status = SS_SCANNING;
1112 if (kthread_should_stop())
1115 if (!scrub->os_partial_scan || scrub->os_in_join)
1121 LASSERTF(rc == 0, "rc = %d\n", rc);
1123 osd_scrub_exec(info, dev, param, oic, &noslot, rc);
1130 wait_var_event(scrub,
1131 kthread_should_stop() ||
1132 !scrub->os_in_join);
1134 if (kthread_should_stop())
1140 next = osd_scrub_next;
1141 exec = osd_scrub_exec;
1142 pos = &scrub->os_pos_current;
1143 count = &scrub->os_new_checked;
1144 param->start = *pos;
1145 param->bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param->sb);
1147 (*pos - 1) % LDISKFS_INODES_PER_GROUP(param->sb);
1149 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1151 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1153 next = osd_preload_next;
1154 exec = osd_preload_exec;
1155 pos = &ooc->ooc_pos_preload;
1156 count = &ooc->ooc_cached_items;
1157 param = &dev->od_otable_it->ooi_iit_param;
1161 limit = le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count);
1162 while (*pos <= limit && *count < max) {
1163 struct ldiskfs_group_desc *desc;
1164 bool next_group = false;
1166 desc = ldiskfs_get_group_desc(param->sb, param->bg, NULL);
1170 if (desc->bg_flags & cpu_to_le16(LDISKFS_BG_INODE_UNINIT)) {
1175 param->bitmap = ldiskfs_read_inode_bitmap(param->sb, param->bg);
1176 if (!param->bitmap) {
1177 CERROR("%s: fail to read bitmap for %u, "
1178 "scrub will stop, urgent mode\n",
1179 osd_scrub2name(scrub), (__u32)param->bg);
1184 struct osd_idmap_cache *oic = NULL;
1187 ldiskfs_itable_unused_count(param->sb, desc) >=
1188 LDISKFS_INODES_PER_GROUP(param->sb)) {
1193 rc = next(info, dev, param, &oic, noslot);
1195 case SCRUB_NEXT_BREAK:
1198 case SCRUB_NEXT_EXIT:
1199 brelse(param->bitmap);
1201 case SCRUB_NEXT_CRASH:
1202 brelse(param->bitmap);
1203 RETURN(SCRUB_IT_CRASH);
1204 case SCRUB_NEXT_FATAL:
1205 brelse(param->bitmap);
1209 rc = exec(info, dev, param, oic, &noslot, rc);
1210 } while (!rc && *pos <= limit && *count < max);
1213 if (param->bitmap) {
1214 brelse(param->bitmap);
1215 param->bitmap = NULL;
1225 param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1226 *pos = param->gbase;
1227 param->start = *pos;
1232 RETURN(SCRUB_IT_ALL);
1238 static int osd_otable_it_preload(const struct lu_env *env,
1239 struct osd_otable_it *it)
1241 struct osd_device *dev = it->ooi_dev;
1242 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1243 struct osd_otable_cache *ooc = &it->ooi_cache;
1247 rc = osd_inode_iteration(osd_oti_get(env), dev,
1248 OSD_OTABLE_IT_CACHE_SIZE, true);
1249 if (rc == SCRUB_IT_ALL)
1250 it->ooi_all_cached = 1;
1252 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1253 spin_lock(&scrub->os_lock);
1254 scrub->os_waiting = 0;
1256 spin_unlock(&scrub->os_lock);
1259 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1262 static int osd_scan_ml_file_main(const struct lu_env *env,
1263 struct osd_device *dev);
1265 static int osd_scrub_main(void *args)
1268 struct osd_device *dev = (struct osd_device *)args;
1269 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1273 rc = lu_env_init(&env, LCT_LOCAL | LCT_DT_THREAD);
1275 CDEBUG(D_LFSCK, "%s: OI scrub fail to init env: rc = %d\n",
1276 osd_scrub2name(scrub), rc);
1280 rc = osd_scrub_prep(&env, dev);
1282 CDEBUG(D_LFSCK, "%s: OI scrub fail to scrub prep: rc = %d\n",
1283 osd_scrub2name(scrub), rc);
1287 if (!scrub->os_full_speed && !scrub->os_partial_scan) {
1288 struct osd_otable_it *it = dev->od_otable_it;
1289 struct osd_otable_cache *ooc = &it->ooi_cache;
1291 wait_var_event(scrub,
1292 it->ooi_user_ready || kthread_should_stop());
1293 if (kthread_should_stop())
1296 scrub->os_pos_current = ooc->ooc_pos_preload;
1299 CDEBUG(D_LFSCK, "%s: OI scrub start, flags = 0x%x, pos = %llu\n",
1300 osd_scrub2name(scrub), scrub->os_start_flags,
1301 scrub->os_pos_current);
1303 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1304 if (unlikely(rc == SCRUB_IT_CRASH)) {
1305 spin_lock(&scrub->os_lock);
1306 scrub->os_running = 0;
1307 spin_unlock(&scrub->os_lock);
1308 GOTO(out, rc = -EINVAL);
1311 if (scrub->os_has_ml_file) {
1312 ret = osd_scan_ml_file_main(&env, dev);
1320 rc = osd_scrub_post(&env, dev, rc);
1321 CDEBUG(D_LFSCK, "%s: OI scrub: stop, pos = %llu: rc = %d\n",
1322 osd_scrub2name(scrub), scrub->os_pos_current, rc);
1325 while (!list_empty(&scrub->os_inconsistent_items)) {
1326 struct osd_inconsistent_item *oii;
1328 oii = list_entry(scrub->os_inconsistent_items.next,
1329 struct osd_inconsistent_item, oii_list);
1330 list_del_init(&oii->oii_list);
1337 spin_lock(&scrub->os_lock);
1338 scrub->os_running = 0;
1339 spin_unlock(&scrub->os_lock);
1340 if (xchg(&scrub->os_task, NULL) == NULL)
1341 /* scrub_stop() is waiting, we need to synchronize */
1342 wait_var_event(scrub, kthread_should_stop());
1347 /* initial OI scrub */
1349 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1350 struct dentry *, filldir_t filldir);
1352 #ifdef HAVE_FILLDIR_USE_CTX
1353 static int osd_ios_varfid_fill(struct dir_context *buf, const char *name,
1354 int namelen, loff_t offset, __u64 ino,
1356 static int osd_ios_lf_fill(struct dir_context *buf, const char *name,
1357 int namelen, loff_t offset, __u64 ino,
1359 static int osd_ios_dl_fill(struct dir_context *buf, const char *name,
1360 int namelen, loff_t offset, __u64 ino,
1362 static int osd_ios_uld_fill(struct dir_context *buf, const char *name,
1363 int namelen, loff_t offset, __u64 ino,
1366 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1367 loff_t offset, __u64 ino, unsigned d_type);
1368 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1369 loff_t offset, __u64 ino, unsigned d_type);
1370 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1371 loff_t offset, __u64 ino, unsigned d_type);
1372 static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
1373 loff_t offset, __u64 ino, unsigned d_type);
1377 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1378 struct dentry *dentry, filldir_t filldir);
1380 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1381 struct dentry *dentry, filldir_t filldir);
1384 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1385 struct dentry *dentry, filldir_t filldir);
1389 struct lu_fid olm_fid;
1392 scandir_t olm_scandir;
1393 filldir_t olm_filldir;
1396 /* Add the new introduced local files in the list in the future. */
1397 static const struct osd_lf_map osd_lf_maps[] = {
1400 .olm_name = CATLIST,
1402 .f_seq = FID_SEQ_LOCAL_FILE,
1403 .f_oid = LLOG_CATALOGS_OID,
1405 .olm_flags = OLF_SHOW_NAME,
1406 .olm_namelen = sizeof(CATLIST) - 1,
1411 .olm_name = MOUNT_CONFIGS_DIR,
1413 .f_seq = FID_SEQ_LOCAL_FILE,
1414 .f_oid = MGS_CONFIGS_OID,
1416 .olm_flags = OLF_SCAN_SUBITEMS,
1417 .olm_namelen = sizeof(MOUNT_CONFIGS_DIR) - 1,
1418 .olm_scandir = osd_ios_general_scan,
1419 .olm_filldir = osd_ios_varfid_fill,
1422 /* NIDTBL_VERSIONS */
1424 .olm_name = MGS_NIDTBL_DIR,
1425 .olm_flags = OLF_SCAN_SUBITEMS,
1426 .olm_namelen = sizeof(MGS_NIDTBL_DIR) - 1,
1427 .olm_scandir = osd_ios_general_scan,
1428 .olm_filldir = osd_ios_varfid_fill,
1433 .olm_name = MDT_ORPHAN_DIR,
1434 .olm_namelen = sizeof(MDT_ORPHAN_DIR) - 1,
1441 .f_seq = FID_SEQ_ROOT,
1442 .f_oid = FID_OID_ROOT,
1444 .olm_flags = OLF_SCAN_SUBITEMS | OLF_HIDE_FID,
1445 .olm_namelen = sizeof("ROOT") - 1,
1446 .olm_scandir = osd_ios_ROOT_scan,
1449 /* changelog_catalog */
1451 .olm_name = CHANGELOG_CATALOG,
1452 .olm_namelen = sizeof(CHANGELOG_CATALOG) - 1,
1455 /* changelog_users */
1457 .olm_name = CHANGELOG_USERS,
1458 .olm_namelen = sizeof(CHANGELOG_USERS) - 1,
1465 .f_seq = FID_SEQ_LOCAL_FILE,
1466 .f_oid = FLD_INDEX_OID,
1468 .olm_flags = OLF_SHOW_NAME,
1469 .olm_namelen = sizeof("fld") - 1,
1474 .olm_name = LAST_RCVD,
1476 .f_seq = FID_SEQ_LOCAL_FILE,
1477 .f_oid = LAST_RECV_OID,
1479 .olm_flags = OLF_SHOW_NAME,
1480 .olm_namelen = sizeof(LAST_RCVD) - 1,
1485 .olm_name = REPLY_DATA,
1487 .f_seq = FID_SEQ_LOCAL_FILE,
1488 .f_oid = REPLY_DATA_OID,
1490 .olm_flags = OLF_SHOW_NAME,
1491 .olm_namelen = sizeof(REPLY_DATA) - 1,
1496 .olm_name = LOV_OBJID,
1498 .f_seq = FID_SEQ_LOCAL_FILE,
1499 .f_oid = MDD_LOV_OBJ_OID,
1501 .olm_flags = OLF_SHOW_NAME,
1502 .olm_namelen = sizeof(LOV_OBJID) - 1,
1507 .olm_name = LOV_OBJSEQ,
1509 .f_seq = FID_SEQ_LOCAL_FILE,
1510 .f_oid = MDD_LOV_OBJ_OSEQ,
1512 .olm_flags = OLF_SHOW_NAME,
1513 .olm_namelen = sizeof(LOV_OBJSEQ) - 1,
1518 .olm_name = QMT_DIR,
1519 .olm_flags = OLF_SCAN_SUBITEMS,
1520 .olm_namelen = sizeof(QMT_DIR) - 1,
1521 .olm_scandir = osd_ios_general_scan,
1522 .olm_filldir = osd_ios_varfid_fill,
1527 .olm_name = QSD_DIR,
1528 .olm_flags = OLF_SCAN_SUBITEMS,
1529 .olm_namelen = sizeof(QSD_DIR) - 1,
1530 .olm_scandir = osd_ios_general_scan,
1531 .olm_filldir = osd_ios_varfid_fill,
1536 .olm_name = "seq_ctl",
1538 .f_seq = FID_SEQ_LOCAL_FILE,
1539 .f_oid = FID_SEQ_CTL_OID,
1541 .olm_flags = OLF_SHOW_NAME,
1542 .olm_namelen = sizeof("seq_ctl") - 1,
1547 .olm_name = "seq_srv",
1549 .f_seq = FID_SEQ_LOCAL_FILE,
1550 .f_oid = FID_SEQ_SRV_OID,
1552 .olm_flags = OLF_SHOW_NAME,
1553 .olm_namelen = sizeof("seq_srv") - 1,
1558 .olm_name = HEALTH_CHECK,
1560 .f_seq = FID_SEQ_LOCAL_FILE,
1561 .f_oid = OFD_HEALTH_CHECK_OID,
1563 .olm_flags = OLF_SHOW_NAME,
1564 .olm_namelen = sizeof(HEALTH_CHECK) - 1,
1569 .olm_name = LFSCK_DIR,
1570 .olm_flags = OLF_SCAN_SUBITEMS,
1571 .olm_namelen = sizeof(LFSCK_DIR) - 1,
1572 .olm_scandir = osd_ios_general_scan,
1573 .olm_filldir = osd_ios_varfid_fill,
1576 /* lfsck_bookmark */
1578 .olm_name = LFSCK_BOOKMARK,
1579 .olm_namelen = sizeof(LFSCK_BOOKMARK) - 1,
1584 .olm_name = LFSCK_LAYOUT,
1585 .olm_namelen = sizeof(LFSCK_LAYOUT) - 1,
1588 /* lfsck_namespace */
1590 .olm_name = LFSCK_NAMESPACE,
1591 .olm_namelen = sizeof(LFSCK_NAMESPACE) - 1,
1594 /* OBJECTS, upgrade from old device */
1596 .olm_name = OBJECTS,
1597 .olm_flags = OLF_SCAN_SUBITEMS,
1598 .olm_namelen = sizeof(OBJECTS) - 1,
1599 .olm_scandir = osd_ios_OBJECTS_scan,
1602 /* lquota_v2.user, upgrade from old device */
1604 .olm_name = "lquota_v2.user",
1605 .olm_namelen = sizeof("lquota_v2.user") - 1,
1608 /* lquota_v2.group, upgrade from old device */
1610 .olm_name = "lquota_v2.group",
1611 .olm_namelen = sizeof("lquota_v2.group") - 1,
1614 /* LAST_GROUP, upgrade from old device */
1616 .olm_name = "LAST_GROUP",
1618 .f_seq = FID_SEQ_LOCAL_FILE,
1619 .f_oid = OFD_LAST_GROUP_OID,
1621 .olm_flags = OLF_SHOW_NAME,
1622 .olm_namelen = sizeof("LAST_GROUP") - 1,
1625 /* committed batchid for cross-MDT operation */
1627 .olm_name = "BATCHID",
1629 .f_seq = FID_SEQ_LOCAL_FILE,
1630 .f_oid = BATCHID_COMMITTED_OID,
1632 .olm_flags = OLF_SHOW_NAME,
1633 .olm_namelen = sizeof("BATCHID") - 1,
1636 /* OSP update logs update_log{_dir} use f_seq = FID_SEQ_UPDATE_LOG{_DIR}
1637 * and f_oid = index for their log files. See lu_update_log{_dir}_fid()
1638 * for more details. */
1642 .olm_name = "update_log",
1644 .f_seq = FID_SEQ_UPDATE_LOG,
1646 .olm_flags = OLF_SHOW_NAME | OLF_IDX_IN_FID,
1647 .olm_namelen = sizeof("update_log") - 1,
1650 /* update_log_dir */
1652 .olm_name = "update_log_dir",
1654 .f_seq = FID_SEQ_UPDATE_LOG_DIR,
1656 .olm_flags = OLF_SHOW_NAME | OLF_SCAN_SUBITEMS |
1658 .olm_namelen = sizeof("update_log_dir") - 1,
1659 .olm_scandir = osd_ios_general_scan,
1660 .olm_filldir = osd_ios_uld_fill,
1665 .olm_name = "lost+found",
1667 .f_seq = FID_SEQ_LOCAL_FILE,
1668 .f_oid = OSD_LPF_OID,
1670 .olm_flags = OLF_SCAN_SUBITEMS,
1671 .olm_namelen = sizeof("lost+found") - 1,
1672 .olm_scandir = osd_ios_general_scan,
1673 .olm_filldir = osd_ios_lf_fill,
1678 .olm_name = HSM_ACTIONS,
1683 .olm_name = LUSTRE_NODEMAP_NAME,
1688 .olm_name = INDEX_BACKUP_DIR,
1690 .f_seq = FID_SEQ_LOCAL_FILE,
1691 .f_oid = INDEX_BACKUP_OID,
1693 .olm_flags = OLF_SCAN_SUBITEMS | OLF_NOT_BACKUP,
1694 .olm_namelen = sizeof(INDEX_BACKUP_DIR) - 1,
1695 .olm_scandir = osd_ios_general_scan,
1696 .olm_filldir = osd_ios_varfid_fill,
1704 /* Add the new introduced files under .lustre/ in the list in the future. */
1705 static const struct osd_lf_map osd_dl_maps[] = {
1710 .f_seq = FID_SEQ_DOT_LUSTRE,
1711 .f_oid = FID_OID_DOT_LUSTRE_OBF,
1713 .olm_namelen = sizeof("fid") - 1,
1716 /* .lustre/lost+found */
1718 .olm_name = "lost+found",
1720 .f_seq = FID_SEQ_DOT_LUSTRE,
1721 .f_oid = FID_OID_DOT_LUSTRE_LPF,
1723 .olm_namelen = sizeof("lost+found") - 1,
1731 struct osd_ios_item {
1732 struct list_head oii_list;
1733 struct dentry *oii_dentry;
1734 scandir_t oii_scandir;
1735 filldir_t oii_filldir;
1738 struct osd_ios_filldir_buf {
1739 /* please keep it as first member */
1740 struct dir_context ctx;
1741 struct osd_thread_info *oifb_info;
1742 struct osd_device *oifb_dev;
1743 struct dentry *oifb_dentry;
1748 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1749 scandir_t scandir, filldir_t filldir)
1751 struct osd_ios_item *item;
1754 OBD_ALLOC_PTR(item);
1758 INIT_LIST_HEAD(&item->oii_list);
1759 item->oii_dentry = dget(dentry);
1760 item->oii_scandir = scandir;
1761 item->oii_filldir = filldir;
1762 list_add_tail(&item->oii_list, &dev->od_ios_list);
1767 static bool osd_index_need_recreate(const struct lu_env *env,
1768 struct osd_device *dev, struct inode *inode)
1770 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1771 struct iam_container *bag = &iam->od_container;
1775 rc = iam_container_init(bag, &iam->od_descr, inode);
1779 rc = iam_container_setup(bag);
1780 iam_container_fini(bag);
1787 static void osd_ios_index_register(const struct lu_env *env,
1788 struct osd_device *osd,
1789 const struct lu_fid *fid,
1790 struct inode *inode)
1792 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1793 struct iam_container *bag = &iam->od_container;
1794 struct super_block *sb = osd_sb(osd);
1795 struct iam_descr *descr;
1801 /* Index must be a regular file. */
1802 if (!S_ISREG(inode->i_mode))
1805 /* Index's size must be block aligned. */
1806 if (inode->i_size < sb->s_blocksize ||
1807 (inode->i_size & (sb->s_blocksize - 1)) != 0)
1810 iam_container_init(bag, &iam->od_descr, inode);
1811 rc = iam_container_setup(bag);
1815 descr = bag->ic_descr;
1816 /* May be regular file with IAM_LFIX_ROOT_MAGIC matched
1817 * coincidentally, or corrupted index object, skip it. */
1818 if (descr->id_ptr_size != 4)
1821 keysize = descr->id_key_size;
1822 recsize = descr->id_rec_size;
1823 rc = osd_index_register(osd, fid, keysize, recsize);
1828 iam_container_fini(bag);
1830 CDEBUG(D_LFSCK, "%s: index object "DFID" (%u/%u) registered\n",
1831 osd_name(osd), PFID(fid), keysize, recsize);
1834 static void osd_index_restore(const struct lu_env *env, struct osd_device *dev,
1835 struct lustre_index_restore_unit *liru,
1836 void *buf, int bufsize)
1838 struct osd_thread_info *info = osd_oti_get(env);
1839 struct osd_inode_id *id = &info->oti_id;
1840 struct lu_fid *tgt_fid = &liru->liru_cfid;
1841 struct inode *bak_inode = NULL;
1842 struct ldiskfs_dir_entry_2 *de = NULL;
1843 struct buffer_head *bh = NULL;
1844 struct dentry *dentry;
1846 struct lu_fid bak_fid;
1850 lustre_fid2lbx(name, tgt_fid, bufsize);
1851 dentry = osd_child_dentry_by_inode(env, dev->od_index_backup_inode,
1852 name, strlen(name));
1853 bh = osd_ldiskfs_find_entry(dev->od_index_backup_inode,
1854 &dentry->d_name, &de, NULL, NULL);
1856 GOTO(log, rc = PTR_ERR(bh));
1858 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
1860 bak_inode = osd_iget_fid(info, dev, id, &bak_fid);
1861 if (IS_ERR(bak_inode))
1862 GOTO(log, rc = PTR_ERR(bak_inode));
1865 /* The OI mapping for index may be invalid, since it will be
1866 * re-created, not update the OI mapping, just cache it in RAM. */
1867 osd_id_gen(id, liru->liru_clid, OSD_OII_NOGEN);
1868 osd_add_oi_cache(info, dev, id, tgt_fid);
1869 rc = lustre_index_restore(env, &dev->od_dt_dev, &liru->liru_pfid,
1870 tgt_fid, &bak_fid, liru->liru_name,
1871 &dev->od_index_backup_list, &dev->od_lock,
1876 CDEBUG(D_WARNING, "%s: restore index '%s' with "DFID": rc = %d\n",
1877 osd_name(dev), liru->liru_name, PFID(tgt_fid), rc);
1881 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1883 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1884 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1885 * reference the inode, or fixed if it is missing or references another inode.
1888 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1889 struct inode *parent, struct inode *inode,
1890 const struct lu_fid *fid, const char *name,
1891 int namelen, int flags)
1893 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1894 struct osd_inode_id *id = &info->oti_id;
1895 struct osd_inode_id *id2 = &info->oti_id2;
1896 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1897 struct scrub_file *sf = &scrub->os_file;
1903 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode: rc = -2\n",
1904 osd_name(dev), namelen, name);
1908 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
1909 &info->oti_ost_attrs);
1910 if (rc != 0 && rc != -ENODATA) {
1911 CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
1912 "rc = %d\n", osd_name(dev), rc);
1917 osd_id_gen(id, inode->i_ino, inode->i_generation);
1918 if (rc == -ENODATA) {
1919 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID) {
1920 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1923 if (flags & OLF_IDX_IN_FID) {
1924 LASSERT(dev->od_index >= 0);
1926 tfid.f_oid = dev->od_index;
1929 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1931 CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
1932 "scrub: rc = %d\n", osd_name(dev), rc);
1937 if (lma->lma_compat & LMAC_NOT_IN_OI)
1940 tfid = lma->lma_self_fid;
1941 if (lma->lma_compat & LMAC_IDX_BACKUP &&
1942 osd_index_need_recreate(info->oti_env, dev, inode)) {
1943 struct lu_fid *pfid = &info->oti_fid3;
1945 if (is_root_inode(parent)) {
1946 lu_local_obj_fid(pfid, OSD_FS_ROOT_OID);
1948 rc = osd_scrub_get_fid(info, dev, parent, pfid,
1954 rc = lustre_liru_new(&dev->od_index_restore_list, pfid,
1955 &tfid, inode->i_ino, name, namelen);
1960 if (!(flags & OLF_NOT_BACKUP))
1961 osd_ios_index_register(info->oti_env, dev, &tfid,
1965 /* Since this called from iterate_dir() the inode lock will be taken */
1966 rc = osd_oi_lookup(info, dev, &tfid, id2, OI_LOCKED);
1971 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1972 DTO_INDEX_INSERT, true, 0, NULL);
1979 if (osd_id_eq_strict(id, id2))
1982 if (!(sf->sf_flags & SF_INCONSISTENT)) {
1983 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
1984 rc = scrub_file_store(info->oti_env, scrub);
1989 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1990 DTO_INDEX_UPDATE, true, 0, NULL);
1998 * It scans the /lost+found, and for the OST-object (with filter_fid
1999 * or filter_fid_18_23), move them back to its proper /O/<seq>/d<x>.
2001 #ifdef HAVE_FILLDIR_USE_CTX
2002 static int osd_ios_lf_fill(struct dir_context *buf,
2004 static int osd_ios_lf_fill(void *buf,
2006 const char *name, int namelen,
2007 loff_t offset, __u64 ino, unsigned d_type)
2009 struct osd_ios_filldir_buf *fill_buf =
2010 (struct osd_ios_filldir_buf *)buf;
2011 struct osd_thread_info *info = fill_buf->oifb_info;
2012 struct osd_device *dev = fill_buf->oifb_dev;
2013 struct lu_fid *fid = &info->oti_fid;
2014 struct osd_scrub *scrub = &dev->od_scrub;
2015 struct dentry *parent = fill_buf->oifb_dentry;
2016 struct dentry *child;
2017 struct inode *dir = parent->d_inode;
2018 struct inode *inode;
2022 fill_buf->oifb_items++;
2024 /* skip any '.' started names */
2028 scrub->os_lf_scanned++;
2029 child = osd_lookup_one_len(dev, name, parent, namelen);
2030 if (IS_ERR(child)) {
2031 rc = PTR_ERR(child);
2032 CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
2033 osd_name(dev), namelen, name, rc);
2035 } else if (!child->d_inode) {
2037 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode\n",
2038 osd_name(dev), namelen, name);
2042 inode = child->d_inode;
2043 if (S_ISDIR(inode->i_mode)) {
2044 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2047 CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
2048 "rc = %d\n", osd_name(dev), namelen, name, rc);
2052 if (!S_ISREG(inode->i_mode))
2055 rc = osd_scrub_get_fid(info, dev, inode, fid, true);
2056 if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
2057 rc = osd_obj_map_recover(info, dev, dir, child, fid);
2059 CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
2060 "/lost+found.\n", namelen, name, PFID(fid));
2061 scrub->os_lf_repaired++;
2063 CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
2065 osd_name(dev), namelen, name, PFID(fid), rc);
2069 /* XXX: For MDT-objects, we can move them from /lost+found to namespace
2070 * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
2071 * can process them in furtuer. */
2077 scrub->os_lf_failed++;
2079 /* skip the failure to make the scanning to continue. */
2083 #ifdef HAVE_FILLDIR_USE_CTX
2084 static int osd_ios_varfid_fill(struct dir_context *buf,
2086 static int osd_ios_varfid_fill(void *buf,
2088 const char *name, int namelen,
2089 loff_t offset, __u64 ino, unsigned d_type)
2091 struct osd_ios_filldir_buf *fill_buf =
2092 (struct osd_ios_filldir_buf *)buf;
2093 struct osd_device *dev = fill_buf->oifb_dev;
2094 struct dentry *child;
2098 fill_buf->oifb_items++;
2100 /* skip any '.' started names */
2104 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2106 RETURN(PTR_ERR(child));
2108 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2109 fill_buf->oifb_dentry->d_inode, child->d_inode,
2110 NULL, name, namelen, 0);
2111 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
2112 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2113 osd_ios_varfid_fill);
2119 #ifdef HAVE_FILLDIR_USE_CTX
2120 static int osd_ios_dl_fill(struct dir_context *buf,
2122 static int osd_ios_dl_fill(void *buf,
2124 const char *name, int namelen,
2125 loff_t offset, __u64 ino, unsigned d_type)
2127 struct osd_ios_filldir_buf *fill_buf =
2128 (struct osd_ios_filldir_buf *)buf;
2129 struct osd_device *dev = fill_buf->oifb_dev;
2130 const struct osd_lf_map *map;
2131 struct dentry *child;
2135 fill_buf->oifb_items++;
2137 /* skip any '.' started names */
2141 for (map = osd_dl_maps; map->olm_name != NULL; map++) {
2142 if (map->olm_namelen != namelen)
2145 if (strncmp(map->olm_name, name, namelen) == 0)
2149 if (map->olm_name == NULL)
2152 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2154 RETURN(PTR_ERR(child));
2156 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2157 fill_buf->oifb_dentry->d_inode, child->d_inode,
2158 &map->olm_fid, name, namelen, map->olm_flags);
2164 #ifdef HAVE_FILLDIR_USE_CTX
2165 static int osd_ios_uld_fill(struct dir_context *buf,
2167 static int osd_ios_uld_fill(void *buf,
2169 const char *name, int namelen,
2170 loff_t offset, __u64 ino, unsigned d_type)
2172 struct osd_ios_filldir_buf *fill_buf =
2173 (struct osd_ios_filldir_buf *)buf;
2174 struct osd_device *dev = fill_buf->oifb_dev;
2175 struct dentry *child;
2180 fill_buf->oifb_items++;
2182 /* skip any non-DFID format name */
2186 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2188 RETURN(PTR_ERR(child));
2190 /* skip the start '[' */
2191 sscanf(&name[1], SFID, RFID(&tfid));
2192 if (fid_is_sane(&tfid))
2193 rc = osd_ios_scan_one(fill_buf->oifb_info, fill_buf->oifb_dev,
2194 fill_buf->oifb_dentry->d_inode,
2195 child->d_inode, &tfid, name, namelen, 0);
2203 #ifdef HAVE_FILLDIR_USE_CTX
2204 static int osd_ios_root_fill(struct dir_context *buf,
2206 static int osd_ios_root_fill(void *buf,
2208 const char *name, int namelen,
2209 loff_t offset, __u64 ino, unsigned d_type)
2211 struct osd_ios_filldir_buf *fill_buf =
2212 (struct osd_ios_filldir_buf *)buf;
2213 struct osd_device *dev = fill_buf->oifb_dev;
2214 const struct osd_lf_map *map;
2215 struct dentry *child;
2219 fill_buf->oifb_items++;
2221 /* skip any '.' started names */
2225 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
2226 if (map->olm_namelen != namelen)
2229 if (strncmp(map->olm_name, name, namelen) == 0)
2233 if (map->olm_name == NULL)
2236 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2238 RETURN(PTR_ERR(child));
2239 else if (!child->d_inode)
2240 GOTO(out_put, rc = -ENOENT);
2242 if (!(map->olm_flags & OLF_NO_OI))
2243 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2244 fill_buf->oifb_dentry->d_inode, child->d_inode,
2245 &map->olm_fid, name, namelen, map->olm_flags);
2246 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
2247 rc = osd_ios_new_item(dev, child, map->olm_scandir,
2256 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
2257 struct dentry *dentry, filldir_t filldir)
2259 struct osd_ios_filldir_buf buf = {
2260 .ctx.actor = filldir,
2263 .oifb_dentry = dentry
2266 struct inode *inode = dentry->d_inode;
2271 LASSERT(filldir != NULL);
2273 filp = osd_quasi_file_by_dentry(info->oti_env, dentry);
2274 rc = osd_security_file_alloc(filp);
2280 rc = iterate_dir(filp, &buf.ctx);
2281 } while (rc >= 0 && buf.oifb_items > 0 &&
2282 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
2283 inode->i_fop->release(inode, filp);
2289 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
2290 struct dentry *dentry, filldir_t filldir)
2292 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2293 struct scrub_file *sf = &scrub->os_file;
2294 struct dentry *child;
2298 /* It is existing MDT0 device. We only allow the case of object without
2299 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
2300 * can generate IGIF mode FID for the object and related OI mapping. If
2301 * it is on other MDTs, then becuase file-level backup/restore, related
2302 * OI mapping may be invalid already, we do not know which is the right
2303 * FID for the object. We only allow IGIF objects to reside on the MDT0.
2305 * XXX: For the case of object on non-MDT0 device with neither LMA nor
2306 * "fid" xattr, then something crashed. We cannot re-generate the
2307 * FID directly, instead, the OI scrub will scan the OI structure
2308 * and try to re-generate the LMA from the OI mapping. But if the
2309 * OI mapping crashed or lost also, then we have to give up under
2310 * double failure cases.
2312 spin_lock(&scrub->os_lock);
2313 scrub->os_convert_igif = 1;
2314 spin_unlock(&scrub->os_lock);
2315 child = osd_lookup_one_len_unlocked(dev, dot_lustre_name, dentry,
2316 strlen(dot_lustre_name));
2317 if (IS_ERR(child)) {
2318 if (PTR_ERR(child) != -ENOENT)
2319 RETURN(PTR_ERR(child));
2323 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
2324 * so the client will get IGIF for the ".lustre" object when
2327 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
2328 * it does not know whether there are some old clients cached
2329 * the ".lustre" IGIF during the upgrading. Two choices:
2331 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
2332 * It will allow the old connected clients to access the
2333 * ".lustre" with cached IGIF. But it will cause others
2334 * on the MDT failed to check "fid_is_dot_lustre()".
2336 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
2337 * for ".lustre" in spite of whether there are some clients
2338 * cached the ".lustre" IGIF or not. It enables the check
2339 * "fid_is_dot_lustre()" on the MDT, although it will cause
2340 * that the old connected clients cannot access the ".lustre"
2341 * with the cached IGIF.
2343 * Usually, it is rare case for the old connected clients
2344 * to access the ".lustre" with cached IGIF. So we prefer
2345 * to the solution 2).
2347 inode_lock(dentry->d_inode);
2348 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2349 child->d_inode, &LU_DOT_LUSTRE_FID,
2351 strlen(dot_lustre_name), 0);
2352 inode_unlock(dentry->d_inode);
2353 if (rc == -ENOENT) {
2355 /* It is 1.8 MDT device. */
2356 if (!(sf->sf_flags & SF_UPGRADE)) {
2357 scrub_file_reset(scrub, dev->od_uuid,
2359 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2360 rc = scrub_file_store(info->oti_env, scrub);
2364 } else if (rc == 0) {
2365 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2374 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
2375 struct dentry *dentry, filldir_t filldir)
2377 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2378 struct scrub_file *sf = &scrub->os_file;
2379 struct dentry *child;
2383 if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
2384 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2385 rc = scrub_file_store(info->oti_env, scrub);
2390 child = osd_lookup_one_len_unlocked(dev, ADMIN_USR, dentry,
2392 if (IS_ERR(child)) {
2393 rc = PTR_ERR(child);
2395 inode_lock(dentry->d_inode);
2396 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2397 child->d_inode, NULL, ADMIN_USR,
2398 strlen(ADMIN_USR), 0);
2399 inode_unlock(dentry->d_inode);
2403 if (rc != 0 && rc != -ENOENT)
2406 child = osd_lookup_one_len_unlocked(dev, ADMIN_GRP, dentry,
2409 GOTO(out, rc = PTR_ERR(child));
2411 inode_lock(dentry->d_inode);
2412 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2413 child->d_inode, NULL, ADMIN_GRP,
2414 strlen(ADMIN_GRP), 0);
2415 inode_unlock(dentry->d_inode);
2418 RETURN(rc == -ENOENT ? 0 : rc);
2421 static void osd_initial_OI_scrub(struct osd_thread_info *info,
2422 struct osd_device *dev)
2424 struct osd_ios_item *item = NULL;
2425 scandir_t scandir = osd_ios_general_scan;
2426 filldir_t filldir = osd_ios_root_fill;
2427 struct dentry *dentry = osd_sb(dev)->s_root;
2428 const struct osd_lf_map *map = osd_lf_maps;
2431 /* Lookup IGIF in OI by force for initial OI scrub. */
2432 dev->od_igif_inoi = 1;
2435 /* Don't take inode_lock here since scandir() callbacks
2436 * can call VFS functions which may manully take the
2437 * inode lock itself like iterate_dir(). Since this
2438 * is the case it is best to leave the scandir()
2439 * callbacks to managing the inode lock.
2441 scandir(info, dev, dentry, filldir);
2443 dput(item->oii_dentry);
2447 if (list_empty(&dev->od_ios_list))
2450 item = list_entry(dev->od_ios_list.next,
2451 struct osd_ios_item, oii_list);
2452 list_del_init(&item->oii_list);
2454 LASSERT(item->oii_scandir != NULL);
2455 scandir = item->oii_scandir;
2456 filldir = item->oii_filldir;
2457 dentry = item->oii_dentry;
2460 /* There maybe the case that the object has been removed, but its OI
2461 * mapping is still in the OI file, such as the "CATALOGS" after MDT
2462 * file-level backup/restore. So here cleanup the stale OI mappings. */
2463 while (map->olm_name != NULL) {
2464 struct dentry *child;
2466 if (fid_is_zero(&map->olm_fid)) {
2471 child = osd_lookup_one_len_unlocked(dev, map->olm_name,
2472 osd_sb(dev)->s_root,
2474 if (PTR_ERR(child) == -ENOENT ||
2475 (!IS_ERR(child) && !child->d_inode))
2476 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
2477 NULL, DTO_INDEX_DELETE,
2484 if (!list_empty(&dev->od_index_restore_list)) {
2487 OBD_ALLOC_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2489 CERROR("%s: not enough RAM for rebuild index\n",
2492 while (!list_empty(&dev->od_index_restore_list)) {
2493 struct lustre_index_restore_unit *liru;
2495 liru = list_entry(dev->od_index_restore_list.next,
2496 struct lustre_index_restore_unit,
2498 list_del(&liru->liru_link);
2500 osd_index_restore(info->oti_env, dev, liru,
2501 buf, INDEX_BACKUP_BUFSIZE);
2502 OBD_FREE(liru, liru->liru_len);
2506 OBD_FREE_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2512 char *osd_lf_fid2name(const struct lu_fid *fid)
2514 const struct osd_lf_map *map = osd_lf_maps;
2516 while (map->olm_name != NULL) {
2517 if (!lu_fid_eq(fid, &map->olm_fid)) {
2522 if (map->olm_flags & OLF_SHOW_NAME)
2523 return map->olm_name;
2531 /* OI scrub start/stop */
2533 int osd_scrub_start(const struct lu_env *env, struct osd_device *dev,
2536 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2540 if (dev->od_dt_dev.dd_rdonly)
2543 /* od_otable_mutex: prevent curcurrent start/stop */
2544 mutex_lock(&dev->od_otable_mutex);
2545 rc = scrub_start(osd_scrub_main, scrub, dev, flags);
2546 if (rc == -EALREADY) {
2548 if ((scrub->os_file.sf_flags & SF_AUTO ||
2549 scrub->os_partial_scan) &&
2550 !(flags & SS_AUTO_PARTIAL))
2551 osd_scrub_join(env, dev, flags, false);
2553 mutex_unlock(&dev->od_otable_mutex);
2558 void osd_scrub_stop(struct osd_device *dev)
2560 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2562 /* od_otable_mutex: prevent curcurrent start/stop */
2563 mutex_lock(&dev->od_otable_mutex);
2564 spin_lock(&scrub->os_lock);
2565 scrub->os_paused = 1;
2566 spin_unlock(&scrub->os_lock);
2568 mutex_unlock(&dev->od_otable_mutex);
2571 /* OI scrub setup/cleanup */
2573 static const char osd_scrub_name[] = "OI_scrub";
2575 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev,
2578 struct osd_thread_info *info = osd_oti_get(env);
2579 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2580 struct lvfs_run_ctxt *ctxt = &dev->od_scrub.os_ctxt;
2581 struct scrub_file *sf = &scrub->os_file;
2582 struct super_block *sb = osd_sb(dev);
2583 struct lvfs_run_ctxt saved;
2585 struct inode *inode;
2586 struct lu_fid *fid = &info->oti_fid;
2587 struct osd_inode_id *id = &info->oti_id;
2588 struct dt_object *obj;
2593 memset(&dev->od_scrub, 0, sizeof(struct osd_scrub));
2594 OBD_SET_CTXT_MAGIC(ctxt);
2595 ctxt->pwdmnt = dev->od_mnt;
2596 ctxt->pwd = dev->od_mnt->mnt_root;
2598 init_rwsem(&scrub->os_rwsem);
2599 spin_lock_init(&scrub->os_lock);
2600 INIT_LIST_HEAD(&scrub->os_inconsistent_items);
2601 scrub->os_name = osd_name(dev);
2603 push_ctxt(&saved, ctxt);
2604 filp = filp_open(osd_scrub_name, O_RDWR |
2605 (dev->od_dt_dev.dd_rdonly ? 0 : O_CREAT), 0644);
2607 pop_ctxt(&saved, ctxt);
2608 RETURN(PTR_ERR(filp));
2611 inode = file_inode(filp);
2612 ldiskfs_set_inode_flag(inode, LDISKFS_INODE_JOURNAL_DATA);
2613 if (!dev->od_dt_dev.dd_rdonly) {
2614 /* 'What the @fid is' is not imporatant, because the object
2615 * has no OI mapping, and only is visible inside the OSD.*/
2616 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2617 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
2619 filp_close(filp, NULL);
2620 pop_ctxt(&saved, ctxt);
2625 osd_id_gen(id, inode->i_ino, inode->i_generation);
2626 osd_add_oi_cache(info, dev, id, fid);
2627 filp_close(filp, NULL);
2628 pop_ctxt(&saved, ctxt);
2630 obj = lu2dt(lu_object_find_slice(env, osd2lu_dev(dev), fid, NULL));
2631 if (IS_ERR_OR_NULL(obj))
2632 RETURN(obj ? PTR_ERR(obj) : -ENOENT);
2634 #ifndef HAVE_S_UUID_AS_UUID_T
2635 memcpy(dev->od_uuid.b, sb->s_uuid, sizeof(dev->od_uuid));
2637 uuid_copy(&dev->od_uuid, &sb->s_uuid);
2639 scrub->os_obj = obj;
2640 rc = scrub_file_load(env, scrub);
2641 if (rc == -ENOENT || rc == -EFAULT) {
2642 scrub_file_init(scrub, dev->od_uuid);
2643 /* If the "/O" dir does not exist when mount (indicated by
2644 * osd_device::od_maybe_new), neither for the "/OI_scrub",
2645 * then it is quite probably that the device is a new one,
2646 * under such case, mark it as SIF_NO_HANDLE_OLD_FID.
2648 * For the rare case that "/O" and "OI_scrub" both lost on
2649 * an old device, it can be found and cleared later.
2651 * For the system with "SIF_NO_HANDLE_OLD_FID", we do not
2652 * need to check "filter_fid_18_23" and to convert it to
2653 * "filter_fid" for each object, and all the IGIF should
2654 * have their FID mapping in OI files already. */
2655 if (dev->od_maybe_new && rc == -ENOENT)
2656 sf->sf_internal_flags = SIF_NO_HANDLE_OLD_FID;
2658 } else if (rc < 0) {
2659 GOTO(cleanup_obj, rc);
2661 if (!uuid_equal(&sf->sf_uuid, &dev->od_uuid)) {
2663 "%s: UUID has been changed from %pU to %pU\n",
2664 osd_dev2name(dev), &sf->sf_uuid, &dev->od_uuid);
2665 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
2668 } else if (sf->sf_status == SS_SCANNING) {
2669 sf->sf_status = SS_CRASHED;
2673 if ((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) {
2674 LCONSOLE_WARN("%s: invalid oi count %d, set it to %d\n",
2675 osd_dev2name(dev), sf->sf_oi_count,
2677 sf->sf_oi_count = osd_oi_count;
2682 if (sf->sf_pos_last_checkpoint != 0)
2683 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
2685 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
2688 rc = scrub_file_store(env, scrub);
2690 GOTO(cleanup_obj, rc);
2693 /* Initialize OI files. */
2694 rc = osd_oi_init(info, dev, restored);
2696 GOTO(cleanup_obj, rc);
2698 if (!dev->od_dt_dev.dd_rdonly)
2699 osd_initial_OI_scrub(info, dev);
2701 if (sf->sf_flags & SF_UPGRADE ||
2702 !(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID ||
2703 sf->sf_success_count > 0)) {
2704 dev->od_igif_inoi = 0;
2705 dev->od_check_ff = dev->od_is_ost;
2707 dev->od_igif_inoi = 1;
2708 dev->od_check_ff = 0;
2711 if (sf->sf_flags & SF_INCONSISTENT)
2712 /* The 'od_igif_inoi' will be set under the
2714 * 1) new created system, or
2715 * 2) restored from file-level backup, or
2716 * 3) the upgrading completed.
2718 * The 'od_igif_inoi' may be cleared by OI scrub
2719 * later if found that the system is upgrading. */
2720 dev->od_igif_inoi = 1;
2722 if (!dev->od_dt_dev.dd_rdonly &&
2723 dev->od_auto_scrub_interval != AS_NEVER &&
2724 ((sf->sf_status == SS_PAUSED) ||
2725 (sf->sf_status == SS_CRASHED &&
2726 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2727 SF_UPGRADE | SF_AUTO)) ||
2728 (sf->sf_status == SS_INIT &&
2729 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2731 rc = osd_scrub_start(env, dev, SS_AUTO_FULL);
2734 GOTO(cleanup_oi, rc);
2736 /* it is possible that dcache entries may keep objects after they are
2737 * deleted by OSD. While it looks safe this can cause object data to
2738 * stay until umount causing failures in tests calculating free space,
2739 * e.g. replay-ost-single. Since those dcache entries are not used
2740 * anymore let's just free them after use here */
2741 shrink_dcache_sb(sb);
2745 osd_oi_fini(info, dev);
2747 dt_object_put_nocache(env, scrub->os_obj);
2748 scrub->os_obj = NULL;
2753 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
2755 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2757 LASSERT(dev->od_otable_it == NULL);
2759 if (scrub->os_obj != NULL) {
2760 osd_scrub_stop(dev);
2761 dt_object_put_nocache(env, scrub->os_obj);
2762 scrub->os_obj = NULL;
2766 /* object table based iteration APIs */
2768 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
2769 struct dt_object *dt, __u32 attr)
2771 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
2772 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
2773 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
2774 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2775 struct osd_otable_it *it;
2780 /* od_otable_mutex: prevent curcurrent init/fini */
2781 mutex_lock(&dev->od_otable_mutex);
2782 if (dev->od_otable_it != NULL)
2783 GOTO(out, it = ERR_PTR(-EALREADY));
2787 GOTO(out, it = ERR_PTR(-ENOMEM));
2789 dev->od_otable_it = it;
2791 it->ooi_cache.ooc_consumer_idx = -1;
2792 if (flags & DOIF_OUTUSED)
2793 it->ooi_used_outside = 1;
2795 if (flags & DOIF_RESET)
2798 if (valid & DOIV_ERROR_HANDLE) {
2799 if (flags & DOIF_FAILOUT)
2800 start |= SS_SET_FAILOUT;
2802 start |= SS_CLEAR_FAILOUT;
2805 if (valid & DOIV_DRYRUN) {
2806 if (flags & DOIF_DRYRUN)
2807 start |= SS_SET_DRYRUN;
2809 start |= SS_CLEAR_DRYRUN;
2812 rc = scrub_start(osd_scrub_main, scrub, dev, start & ~SS_AUTO_PARTIAL);
2813 if (rc == -EALREADY) {
2814 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2815 } else if (rc < 0) {
2816 dev->od_otable_it = NULL;
2820 /* We have to start from the begining. */
2821 it->ooi_cache.ooc_pos_preload =
2822 LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2828 mutex_unlock(&dev->od_otable_mutex);
2829 return (struct dt_it *)it;
2832 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2834 struct osd_otable_it *it = (struct osd_otable_it *)di;
2835 struct osd_device *dev = it->ooi_dev;
2837 /* od_otable_mutex: prevent curcurrent init/fini */
2838 mutex_lock(&dev->od_otable_mutex);
2839 scrub_stop(&dev->od_scrub.os_scrub);
2840 LASSERT(dev->od_otable_it == it);
2842 dev->od_otable_it = NULL;
2843 mutex_unlock(&dev->od_otable_mutex);
2847 static int osd_otable_it_get(const struct lu_env *env,
2848 struct dt_it *di, const struct dt_key *key)
2853 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2858 osd_otable_it_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
2860 spin_lock(&scrub->os_lock);
2861 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2862 scrub->os_waiting || !scrub->os_running)
2863 it->ooi_waiting = 0;
2865 it->ooi_waiting = 1;
2866 spin_unlock(&scrub->os_lock);
2868 return !it->ooi_waiting;
2871 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2873 struct osd_otable_it *it = (struct osd_otable_it *)di;
2874 struct osd_device *dev = it->ooi_dev;
2875 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2876 struct osd_otable_cache *ooc = &it->ooi_cache;
2880 LASSERT(it->ooi_user_ready);
2883 if (!scrub->os_running && !it->ooi_used_outside)
2886 if (ooc->ooc_cached_items > 0) {
2887 ooc->ooc_cached_items--;
2888 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2889 ~OSD_OTABLE_IT_CACHE_MASK;
2893 if (it->ooi_all_cached) {
2894 wait_var_event(scrub, !scrub->os_running);
2898 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2899 spin_lock(&scrub->os_lock);
2900 scrub->os_waiting = 0;
2902 spin_unlock(&scrub->os_lock);
2905 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2906 wait_var_event(scrub, osd_otable_it_wakeup(scrub, it));
2908 if (!scrub->os_running && !it->ooi_used_outside)
2911 rc = osd_otable_it_preload(env, it);
2918 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2919 const struct dt_it *di)
2924 static int osd_otable_it_key_size(const struct lu_env *env,
2925 const struct dt_it *di)
2927 return sizeof(__u64);
2930 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2931 struct dt_rec *rec, __u32 attr)
2933 struct osd_otable_it *it = (struct osd_otable_it *)di;
2934 struct osd_otable_cache *ooc = &it->ooi_cache;
2936 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2938 /* Filter out Invald FID already. */
2939 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2940 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2941 PFID((struct lu_fid *)rec),
2942 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2947 static __u64 osd_otable_it_store(const struct lu_env *env,
2948 const struct dt_it *di)
2950 struct osd_otable_it *it = (struct osd_otable_it *)di;
2951 struct osd_otable_cache *ooc = &it->ooi_cache;
2954 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2955 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2957 hash = ooc->ooc_pos_preload;
2962 * Set the OSD layer iteration start position as the specified hash.
2964 static int osd_otable_it_load(const struct lu_env *env,
2965 const struct dt_it *di, __u64 hash)
2967 struct osd_otable_it *it = (struct osd_otable_it *)di;
2968 struct osd_device *dev = it->ooi_dev;
2969 struct osd_otable_cache *ooc = &it->ooi_cache;
2970 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2971 struct osd_iit_param *param = &it->ooi_iit_param;
2975 /* Forbid to set iteration position after iteration started. */
2976 if (it->ooi_user_ready)
2979 LASSERT(!scrub->os_partial_scan);
2981 if (hash > OSD_OTABLE_MAX_HASH)
2982 hash = OSD_OTABLE_MAX_HASH;
2984 /* The hash is the last checkpoint position,
2985 * we will start from the next one. */
2986 ooc->ooc_pos_preload = hash + 1;
2987 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
2988 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2990 it->ooi_user_ready = 1;
2991 if (!scrub->os_full_speed)
2994 memset(param, 0, sizeof(*param));
2995 param->sb = osd_sb(dev);
2996 param->start = ooc->ooc_pos_preload;
2997 param->bg = (ooc->ooc_pos_preload - 1) /
2998 LDISKFS_INODES_PER_GROUP(param->sb);
2999 param->offset = (ooc->ooc_pos_preload - 1) %
3000 LDISKFS_INODES_PER_GROUP(param->sb);
3001 param->gbase = 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
3003 /* Unplug OSD layer iteration by the first next() call. */
3004 rc = osd_otable_it_next(env, (struct dt_it *)it);
3009 static int osd_otable_it_key_rec(const struct lu_env *env,
3010 const struct dt_it *di, void *key_rec)
3015 const struct dt_index_operations osd_otable_ops = {
3017 .init = osd_otable_it_init,
3018 .fini = osd_otable_it_fini,
3019 .get = osd_otable_it_get,
3020 .put = osd_otable_it_put,
3021 .next = osd_otable_it_next,
3022 .key = osd_otable_it_key,
3023 .key_size = osd_otable_it_key_size,
3024 .rec = osd_otable_it_rec,
3025 .store = osd_otable_it_store,
3026 .load = osd_otable_it_load,
3027 .key_rec = osd_otable_it_key_rec,
3031 /* high priority inconsistent items list APIs */
3033 #define SCRUB_BAD_OIMAP_DECAY_INTERVAL 60
3035 int osd_oii_insert(struct osd_device *dev, const struct lu_fid *fid,
3036 struct osd_inode_id *id, int insert)
3038 struct osd_inconsistent_item *oii;
3039 struct osd_scrub *oscrub = &dev->od_scrub;
3040 struct lustre_scrub *lscrub = &oscrub->os_scrub;
3045 if (unlikely(oii == NULL))
3048 INIT_LIST_HEAD(&oii->oii_list);
3049 oii->oii_cache.oic_fid = *fid;
3050 oii->oii_cache.oic_lid = *id;
3051 oii->oii_cache.oic_dev = dev;
3052 oii->oii_insert = insert;
3054 spin_lock(&lscrub->os_lock);
3055 if (lscrub->os_partial_scan) {
3056 __u64 now = ktime_get_real_seconds();
3058 /* If there haven't been errors in a long time,
3059 * decay old count until either the errors are
3060 * gone or we reach the current interval. */
3061 while (unlikely(oscrub->os_bad_oimap_count > 0 &&
3062 oscrub->os_bad_oimap_time +
3063 SCRUB_BAD_OIMAP_DECAY_INTERVAL < now)) {
3064 oscrub->os_bad_oimap_count >>= 1;
3065 oscrub->os_bad_oimap_time +=
3066 SCRUB_BAD_OIMAP_DECAY_INTERVAL;
3069 oscrub->os_bad_oimap_time = now;
3070 if (++oscrub->os_bad_oimap_count >
3071 dev->od_full_scrub_threshold_rate)
3072 lscrub->os_full_scrub = 1;
3075 if (!lscrub->os_running) {
3076 spin_unlock(&lscrub->os_lock);
3081 if (list_empty(&lscrub->os_inconsistent_items))
3083 list_add_tail(&oii->oii_list, &lscrub->os_inconsistent_items);
3084 spin_unlock(&lscrub->os_lock);
3087 wake_up_var(lscrub);
3092 int osd_oii_lookup(struct osd_device *dev, const struct lu_fid *fid,
3093 struct osd_inode_id *id)
3095 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3096 struct osd_inconsistent_item *oii;
3099 spin_lock(&scrub->os_lock);
3100 list_for_each_entry(oii, &scrub->os_inconsistent_items, oii_list) {
3101 if (lu_fid_eq(fid, &oii->oii_cache.oic_fid)) {
3102 *id = oii->oii_cache.oic_lid;
3103 spin_unlock(&scrub->os_lock);
3107 spin_unlock(&scrub->os_lock);
3112 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
3114 struct osd_scrub *scrub = &dev->od_scrub;
3116 scrub_dump(m, &scrub->os_scrub);
3117 seq_printf(m, "lf_scanned: %llu\n"
3119 "lf_failed: %llu\n",
3120 scrub->os_lf_scanned,
3121 scrub->os_scrub.os_file.sf_param & SP_DRYRUN ?
3122 "inconsistent" : "repaired",
3123 scrub->os_lf_repaired,
3124 scrub->os_lf_failed);
3127 typedef int (*scan_dir_helper_t)(const struct lu_env *env,
3128 struct osd_device *dev, struct inode *dir,
3129 struct osd_it_ea *oie);
3131 static int osd_scan_dir(const struct lu_env *env, struct osd_device *dev,
3132 struct inode *inode, scan_dir_helper_t cb)
3134 struct osd_it_ea *oie;
3139 oie = osd_it_dir_init(env, inode, LUDA_TYPE);
3141 RETURN(PTR_ERR(oie));
3143 oie->oie_file.f_pos = 0;
3144 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3150 while (oie->oie_it_dirent <= oie->oie_rd_dirent) {
3151 if (!name_is_dot_or_dotdot(oie->oie_dirent->oied_name,
3152 oie->oie_dirent->oied_namelen))
3153 cb(env, dev, inode, oie);
3155 oie->oie_dirent = (void *)oie->oie_dirent +
3156 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
3157 oie->oie_dirent->oied_namelen);
3159 oie->oie_it_dirent++;
3160 if (oie->oie_it_dirent <= oie->oie_rd_dirent)
3163 if (oie->oie_file.f_pos ==
3164 ldiskfs_get_htree_eof(&oie->oie_file))
3167 rc = osd_ldiskfs_it_fill(env, (struct dt_it *)oie);
3176 osd_it_dir_fini(env, oie, inode);
3180 static int osd_remove_ml_file(struct osd_thread_info *info,
3181 struct osd_device *dev, struct inode *dir,
3182 struct inode *inode, struct osd_it_ea *oie)
3185 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3186 struct dentry *dentry;
3191 if (scrub->os_file.sf_param & SP_DRYRUN)
3194 th = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
3195 osd_dto_credits_noquota[DTO_INDEX_DELETE] +
3196 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
3198 RETURN(PTR_ERR(th));
3200 dentry = &oie->oie_dentry;
3201 dentry->d_inode = dir;
3202 dentry->d_sb = dir->i_sb;
3203 rc = osd_obj_del_entry(info, dev, dentry, oie->oie_dirent->oied_name,
3204 oie->oie_dirent->oied_namelen, th);
3206 mark_inode_dirty(inode);
3207 ldiskfs_journal_stop(th);
3211 static int osd_scan_ml_file(const struct lu_env *env, struct osd_device *dev,
3212 struct inode *dir, struct osd_it_ea *oie)
3214 struct osd_thread_info *info = osd_oti_get(env);
3215 struct osd_inode_id id;
3216 struct inode *inode;
3217 struct osd_obj_seq *oseq;
3218 struct ost_id *ostid = &info->oti_ostid;
3219 struct lu_fid *fid = &oie->oie_dirent->oied_fid;
3225 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3227 if (!fid_is_sane(fid))
3228 inode = osd_iget_fid(info, dev, &id, fid);
3230 inode = osd_iget(info, dev, &id);
3233 RETURN(PTR_ERR(inode));
3235 fid_to_ostid(fid, ostid);
3236 oseq = osd_seq_load(info, dev, ostid_seq(ostid));
3238 RETURN(PTR_ERR(oseq));
3240 dirn = ostid_id(ostid) & (oseq->oos_subdir_count - 1);
3241 LASSERT(oseq->oos_dirs[dirn] != NULL);
3243 osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
3244 if (((strlen(oseq->oos_root->d_name.name) !=
3245 info->oti_seq_dirent->oied_namelen) ||
3246 strncmp(oseq->oos_root->d_name.name,
3247 info->oti_seq_dirent->oied_name,
3248 info->oti_seq_dirent->oied_namelen) != 0) ||
3249 ((strlen(oseq->oos_dirs[dirn]->d_name.name) !=
3250 info->oti_dir_dirent->oied_namelen) ||
3251 strncmp(oseq->oos_dirs[dirn]->d_name.name,
3252 info->oti_dir_dirent->oied_name,
3253 info->oti_dir_dirent->oied_namelen) != 0) ||
3254 ((strlen(name) != oie->oie_dirent->oied_namelen) ||
3255 strncmp(oie->oie_dirent->oied_name, name,
3256 oie->oie_dirent->oied_namelen) != 0)) {
3257 CDEBUG(D_LFSCK, "%s: the file O/%s/%s/%s is corrupted\n",
3258 osd_name(dev), info->oti_seq_dirent->oied_name,
3259 info->oti_dir_dirent->oied_name,
3260 oie->oie_dirent->oied_name);
3262 rc = osd_remove_ml_file(info, dev, dir, inode, oie);
3269 static int osd_scan_ml_file_dir(const struct lu_env *env,
3270 struct osd_device *dev, struct inode *dir,
3271 struct osd_it_ea *oie)
3273 struct osd_thread_info *info = osd_oti_get(env);
3274 struct inode *inode;
3275 struct osd_inode_id id;
3280 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3281 inode = osd_iget(info, dev, &id);
3283 RETURN(PTR_ERR(inode));
3285 if (!S_ISDIR(inode->i_mode))
3288 info->oti_dir_dirent = oie->oie_dirent;
3289 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file);
3290 info->oti_dir_dirent = NULL;
3297 static int osd_scan_ml_file_seq(const struct lu_env *env,
3298 struct osd_device *dev, struct inode *dir,
3299 struct osd_it_ea *oie)
3301 struct osd_thread_info *info = osd_oti_get(env);
3302 struct inode *inode;
3303 struct osd_inode_id id;
3308 osd_id_gen(&id, oie->oie_dirent->oied_ino, OSD_OII_NOGEN);
3309 inode = osd_iget(info, dev, &id);
3311 RETURN(PTR_ERR(inode));
3313 if (!S_ISDIR(inode->i_mode))
3316 info->oti_seq_dirent = oie->oie_dirent;
3317 rc = osd_scan_dir(env, dev, inode, osd_scan_ml_file_dir);
3318 info->oti_seq_dirent = NULL;
3325 static int osd_scan_ml_file_main(const struct lu_env *env,
3326 struct osd_device *dev)
3328 return osd_scan_dir(env, dev, dev->od_ost_map->om_root->d_inode,
3329 osd_scan_ml_file_seq);