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 static 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);
432 if (inode != NULL && !IS_ERR(inode))
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 /* It is an EA inode, no OI mapping for it, skip it. */
755 if (osd_is_ea_inode(inode))
756 GOTO(put, rc = SCRUB_NEXT_CONTINUE);
759 ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB)) {
760 /* Only skip it for the first OI scrub accessing. */
761 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
762 GOTO(put, rc = SCRUB_NEXT_NOSCRUB);
765 rc = osd_scrub_get_fid(info, dev, inode, fid, scrub);
774 static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
775 struct osd_iit_param *param,
776 struct osd_idmap_cache **oic, const bool noslot)
778 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
780 struct osd_inode_id *lid;
783 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0)
784 wait_var_event_timeout(
786 !list_empty(&scrub->os_inconsistent_items) ||
787 kthread_should_stop(),
788 cfs_time_seconds(cfs_fail_val));
790 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_CRASH)) {
791 spin_lock(&scrub->os_lock);
792 scrub->os_running = 0;
793 spin_unlock(&scrub->os_lock);
794 return SCRUB_NEXT_CRASH;
797 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_FATAL))
798 return SCRUB_NEXT_FATAL;
800 if (kthread_should_stop())
801 return SCRUB_NEXT_EXIT;
803 if (!list_empty(&scrub->os_inconsistent_items)) {
804 spin_lock(&scrub->os_lock);
805 if (likely(!list_empty(&scrub->os_inconsistent_items))) {
806 struct osd_inconsistent_item *oii;
808 oii = list_entry(scrub->os_inconsistent_items.next,
809 struct osd_inconsistent_item, oii_list);
811 *oic = &oii->oii_cache;
812 scrub->os_in_prior = 1;
813 spin_unlock(&scrub->os_lock);
817 spin_unlock(&scrub->os_lock);
821 return SCRUB_NEXT_WAIT;
823 rc = osd_iit_next(param, &scrub->os_pos_current);
827 *oic = &dev->od_scrub.os_oic;
828 fid = &(*oic)->oic_fid;
829 lid = &(*oic)->oic_lid;
830 rc = osd_iit_iget(info, dev, fid, lid,
831 scrub->os_pos_current, param->sb, true);
835 static int osd_preload_next(struct osd_thread_info *info,
836 struct osd_device *dev, struct osd_iit_param *param,
837 struct osd_idmap_cache **oic, const bool noslot)
839 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
840 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
843 if (scrub->os_running &&
844 ooc->ooc_pos_preload >= scrub->os_pos_current)
845 return SCRUB_NEXT_EXIT;
847 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
851 rc = osd_iit_iget(info, dev,
852 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
853 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
854 ooc->ooc_pos_preload, param->sb, false);
859 osd_scrub_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
861 spin_lock(&scrub->os_lock);
862 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
863 !list_empty(&scrub->os_inconsistent_items) ||
864 it->ooi_waiting || kthread_should_stop())
865 scrub->os_waiting = 0;
867 scrub->os_waiting = 1;
868 spin_unlock(&scrub->os_lock);
870 return !scrub->os_waiting;
873 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
874 struct osd_iit_param *param,
875 struct osd_idmap_cache *oic, bool *noslot, int rc)
877 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
878 struct scrub_file *sf = &scrub->os_file;
879 struct osd_otable_it *it = dev->od_otable_it;
880 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
883 case SCRUB_NEXT_NOSCRUB:
884 down_write(&scrub->os_rwsem);
885 scrub->os_new_checked++;
886 sf->sf_items_noscrub++;
887 up_write(&scrub->os_rwsem);
888 case SCRUB_NEXT_CONTINUE:
889 case SCRUB_NEXT_WAIT:
893 rc = osd_scrub_check_update(info, dev, oic, rc);
895 spin_lock(&scrub->os_lock);
896 scrub->os_in_prior = 0;
897 spin_unlock(&scrub->os_lock);
901 rc = scrub_checkpoint(info->oti_env, scrub);
903 CDEBUG(D_LFSCK, "%s: fail to checkpoint, pos = %llu: "
904 "rc = %d\n", osd_scrub2name(scrub),
905 scrub->os_pos_current, rc);
906 /* Continue, as long as the scrub itself can go ahead. */
909 if (scrub->os_in_prior) {
910 spin_lock(&scrub->os_lock);
911 scrub->os_in_prior = 0;
912 spin_unlock(&scrub->os_lock);
917 if (it != NULL && it->ooi_waiting && ooc != NULL &&
918 ooc->ooc_pos_preload < scrub->os_pos_current) {
919 spin_lock(&scrub->os_lock);
922 spin_unlock(&scrub->os_lock);
925 if (rc == SCRUB_NEXT_CONTINUE)
928 if (scrub->os_full_speed || !ooc || osd_scrub_has_window(scrub, ooc)) {
934 wait_var_event(scrub, osd_scrub_wakeup(scrub, it));
936 if (!ooc || osd_scrub_has_window(scrub, ooc))
943 static int osd_preload_exec(struct osd_thread_info *info,
944 struct osd_device *dev, struct osd_iit_param *param,
945 struct osd_idmap_cache *oic, bool *noslot, int rc)
947 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
950 ooc->ooc_cached_items++;
951 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
952 ~OSD_OTABLE_IT_CACHE_MASK;
954 return rc > 0 ? 0 : rc;
957 #define SCRUB_IT_ALL 1
958 #define SCRUB_IT_CRASH 2
960 static void osd_scrub_join(const struct lu_env *env, struct osd_device *dev,
961 __u32 flags, bool inconsistent)
963 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
964 struct scrub_file *sf = &scrub->os_file;
968 LASSERT(!(flags & SS_AUTO_PARTIAL));
970 down_write(&scrub->os_rwsem);
971 spin_lock(&scrub->os_lock);
972 scrub->os_in_join = 1;
973 if (flags & SS_SET_FAILOUT)
974 sf->sf_param |= SP_FAILOUT;
975 else if (flags & SS_CLEAR_FAILOUT)
976 sf->sf_param &= ~SP_FAILOUT;
978 if (flags & SS_SET_DRYRUN)
979 sf->sf_param |= SP_DRYRUN;
980 else if (flags & SS_CLEAR_DRYRUN)
981 sf->sf_param &= ~SP_DRYRUN;
983 if (flags & SS_RESET) {
984 scrub_file_reset(scrub, dev->od_uuid,
985 inconsistent ? SF_INCONSISTENT : 0);
986 sf->sf_status = SS_SCANNING;
989 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
990 scrub->os_full_speed = 1;
992 scrub->os_full_speed = 0;
994 if (flags & SS_AUTO_FULL) {
995 sf->sf_flags |= SF_AUTO;
996 scrub->os_full_speed = 1;
998 spin_unlock(&scrub->os_lock);
1000 scrub->os_new_checked = 0;
1001 if (sf->sf_pos_last_checkpoint != 0)
1002 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
1004 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
1006 scrub->os_pos_current = sf->sf_pos_latest_start;
1007 sf->sf_time_latest_start = ktime_get_real_seconds();
1008 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
1009 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
1010 rc = scrub_file_store(env, scrub);
1012 spin_lock(&scrub->os_lock);
1013 scrub->os_waiting = 0;
1014 scrub->os_paused = 0;
1015 scrub->os_partial_scan = 0;
1016 scrub->os_in_join = 0;
1017 scrub->os_full_scrub = 0;
1018 spin_unlock(&scrub->os_lock);
1020 up_write(&scrub->os_rwsem);
1022 CDEBUG(D_LFSCK, "%s: joined in the OI scrub with flag %u: rc = %d\n",
1023 osd_scrub2name(scrub), flags, rc);
1028 static int osd_inode_iteration(struct osd_thread_info *info,
1029 struct osd_device *dev, __u32 max, bool preload)
1031 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1032 struct scrub_file *sf = &scrub->os_file;
1033 osd_iit_next_policy next;
1034 osd_iit_exec_policy exec;
1037 struct osd_iit_param *param;
1046 param = &dev->od_scrub.os_iit_param;
1047 memset(param, 0, sizeof(*param));
1048 param->sb = osd_sb(dev);
1050 while (scrub->os_partial_scan && !scrub->os_in_join) {
1051 struct osd_idmap_cache *oic = NULL;
1053 rc = osd_scrub_next(info, dev, param, &oic, noslot);
1055 case SCRUB_NEXT_EXIT:
1057 case SCRUB_NEXT_CRASH:
1058 RETURN(SCRUB_IT_CRASH);
1059 case SCRUB_NEXT_FATAL:
1061 case SCRUB_NEXT_WAIT: {
1062 struct kstatfs *ksfs = &info->oti_ksfs;
1065 if (dev->od_full_scrub_ratio == OFSR_NEVER ||
1066 unlikely(sf->sf_items_updated_prior == 0))
1069 if (dev->od_full_scrub_ratio == OFSR_DIRECTLY ||
1070 scrub->os_full_scrub) {
1071 osd_scrub_join(info->oti_env, dev,
1072 SS_AUTO_FULL | SS_RESET, true);
1076 rc = param->sb->s_op->statfs(param->sb->s_root, ksfs);
1078 __u64 used = ksfs->f_files - ksfs->f_ffree;
1080 used = div64_u64(used, sf->sf_items_updated_prior);
1081 /* If we hit too much inconsistent OI
1082 * mappings during the partial scan,
1083 * then scan the device completely. */
1084 if (used < dev->od_full_scrub_ratio) {
1085 osd_scrub_join(info->oti_env, dev,
1086 SS_AUTO_FULL | SS_RESET, true);
1092 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) &&
1096 saved_flags = sf->sf_flags;
1097 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
1098 SF_UPGRADE | SF_AUTO);
1099 sf->sf_status = SS_COMPLETED;
1102 kthread_should_stop() ||
1103 !scrub->os_partial_scan ||
1104 scrub->os_in_join ||
1105 !list_empty(&scrub->os_inconsistent_items));
1106 sf->sf_flags = saved_flags;
1107 sf->sf_status = SS_SCANNING;
1109 if (kthread_should_stop())
1112 if (!scrub->os_partial_scan || scrub->os_in_join)
1118 LASSERTF(rc == 0, "rc = %d\n", rc);
1120 osd_scrub_exec(info, dev, param, oic, &noslot, rc);
1127 wait_var_event(scrub,
1128 kthread_should_stop() ||
1129 !scrub->os_in_join);
1131 if (kthread_should_stop())
1137 next = osd_scrub_next;
1138 exec = osd_scrub_exec;
1139 pos = &scrub->os_pos_current;
1140 count = &scrub->os_new_checked;
1141 param->start = *pos;
1142 param->bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param->sb);
1144 (*pos - 1) % LDISKFS_INODES_PER_GROUP(param->sb);
1146 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1148 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1150 next = osd_preload_next;
1151 exec = osd_preload_exec;
1152 pos = &ooc->ooc_pos_preload;
1153 count = &ooc->ooc_cached_items;
1154 param = &dev->od_otable_it->ooi_iit_param;
1158 limit = le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count);
1159 while (*pos <= limit && *count < max) {
1160 struct ldiskfs_group_desc *desc;
1161 bool next_group = false;
1163 desc = ldiskfs_get_group_desc(param->sb, param->bg, NULL);
1167 if (desc->bg_flags & cpu_to_le16(LDISKFS_BG_INODE_UNINIT)) {
1172 param->bitmap = ldiskfs_read_inode_bitmap(param->sb, param->bg);
1173 if (!param->bitmap) {
1174 CERROR("%s: fail to read bitmap for %u, "
1175 "scrub will stop, urgent mode\n",
1176 osd_scrub2name(scrub), (__u32)param->bg);
1181 struct osd_idmap_cache *oic = NULL;
1184 ldiskfs_itable_unused_count(param->sb, desc) >=
1185 LDISKFS_INODES_PER_GROUP(param->sb)) {
1190 rc = next(info, dev, param, &oic, noslot);
1192 case SCRUB_NEXT_BREAK:
1195 case SCRUB_NEXT_EXIT:
1196 brelse(param->bitmap);
1198 case SCRUB_NEXT_CRASH:
1199 brelse(param->bitmap);
1200 RETURN(SCRUB_IT_CRASH);
1201 case SCRUB_NEXT_FATAL:
1202 brelse(param->bitmap);
1206 rc = exec(info, dev, param, oic, &noslot, rc);
1207 } while (!rc && *pos <= limit && *count < max);
1210 if (param->bitmap) {
1211 brelse(param->bitmap);
1212 param->bitmap = NULL;
1222 param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1223 *pos = param->gbase;
1224 param->start = *pos;
1229 RETURN(SCRUB_IT_ALL);
1235 static int osd_otable_it_preload(const struct lu_env *env,
1236 struct osd_otable_it *it)
1238 struct osd_device *dev = it->ooi_dev;
1239 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1240 struct osd_otable_cache *ooc = &it->ooi_cache;
1244 rc = osd_inode_iteration(osd_oti_get(env), dev,
1245 OSD_OTABLE_IT_CACHE_SIZE, true);
1246 if (rc == SCRUB_IT_ALL)
1247 it->ooi_all_cached = 1;
1249 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1250 spin_lock(&scrub->os_lock);
1251 scrub->os_waiting = 0;
1253 spin_unlock(&scrub->os_lock);
1256 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1259 static int osd_scrub_main(void *args)
1262 struct osd_device *dev = (struct osd_device *)args;
1263 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1267 rc = lu_env_init(&env, LCT_LOCAL | LCT_DT_THREAD);
1269 CDEBUG(D_LFSCK, "%s: OI scrub fail to init env: rc = %d\n",
1270 osd_scrub2name(scrub), rc);
1274 rc = osd_scrub_prep(&env, dev);
1276 CDEBUG(D_LFSCK, "%s: OI scrub fail to scrub prep: rc = %d\n",
1277 osd_scrub2name(scrub), rc);
1281 if (!scrub->os_full_speed && !scrub->os_partial_scan) {
1282 struct osd_otable_it *it = dev->od_otable_it;
1283 struct osd_otable_cache *ooc = &it->ooi_cache;
1285 wait_var_event(scrub,
1286 it->ooi_user_ready || kthread_should_stop());
1287 if (kthread_should_stop())
1290 scrub->os_pos_current = ooc->ooc_pos_preload;
1293 CDEBUG(D_LFSCK, "%s: OI scrub start, flags = 0x%x, pos = %llu\n",
1294 osd_scrub2name(scrub), scrub->os_start_flags,
1295 scrub->os_pos_current);
1297 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1298 if (unlikely(rc == SCRUB_IT_CRASH)) {
1299 spin_lock(&scrub->os_lock);
1300 scrub->os_running = 0;
1301 spin_unlock(&scrub->os_lock);
1302 GOTO(out, rc = -EINVAL);
1308 rc = osd_scrub_post(&env, dev, rc);
1309 CDEBUG(D_LFSCK, "%s: OI scrub: stop, pos = %llu: rc = %d\n",
1310 osd_scrub2name(scrub), scrub->os_pos_current, rc);
1313 while (!list_empty(&scrub->os_inconsistent_items)) {
1314 struct osd_inconsistent_item *oii;
1316 oii = list_entry(scrub->os_inconsistent_items.next,
1317 struct osd_inconsistent_item, oii_list);
1318 list_del_init(&oii->oii_list);
1324 spin_lock(&scrub->os_lock);
1325 scrub->os_running = 0;
1326 spin_unlock(&scrub->os_lock);
1327 if (xchg(&scrub->os_task, NULL) == NULL)
1328 /* scrub_stop() is waiting, we need to synchronize */
1329 wait_var_event(scrub, kthread_should_stop());
1334 /* initial OI scrub */
1336 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1337 struct dentry *, filldir_t filldir);
1339 #ifdef HAVE_FILLDIR_USE_CTX
1340 static int osd_ios_varfid_fill(struct dir_context *buf, const char *name,
1341 int namelen, loff_t offset, __u64 ino,
1343 static int osd_ios_lf_fill(struct dir_context *buf, const char *name,
1344 int namelen, loff_t offset, __u64 ino,
1346 static int osd_ios_dl_fill(struct dir_context *buf, const char *name,
1347 int namelen, loff_t offset, __u64 ino,
1349 static int osd_ios_uld_fill(struct dir_context *buf, const char *name,
1350 int namelen, loff_t offset, __u64 ino,
1353 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1354 loff_t offset, __u64 ino, unsigned d_type);
1355 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1356 loff_t offset, __u64 ino, unsigned d_type);
1357 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1358 loff_t offset, __u64 ino, unsigned d_type);
1359 static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
1360 loff_t offset, __u64 ino, unsigned d_type);
1364 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1365 struct dentry *dentry, filldir_t filldir);
1367 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1368 struct dentry *dentry, filldir_t filldir);
1371 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1372 struct dentry *dentry, filldir_t filldir);
1376 struct lu_fid olm_fid;
1379 scandir_t olm_scandir;
1380 filldir_t olm_filldir;
1383 /* Add the new introduced local files in the list in the future. */
1384 static const struct osd_lf_map osd_lf_maps[] = {
1387 .olm_name = CATLIST,
1389 .f_seq = FID_SEQ_LOCAL_FILE,
1390 .f_oid = LLOG_CATALOGS_OID,
1392 .olm_flags = OLF_SHOW_NAME,
1393 .olm_namelen = sizeof(CATLIST) - 1,
1398 .olm_name = MOUNT_CONFIGS_DIR,
1400 .f_seq = FID_SEQ_LOCAL_FILE,
1401 .f_oid = MGS_CONFIGS_OID,
1403 .olm_flags = OLF_SCAN_SUBITEMS,
1404 .olm_namelen = sizeof(MOUNT_CONFIGS_DIR) - 1,
1405 .olm_scandir = osd_ios_general_scan,
1406 .olm_filldir = osd_ios_varfid_fill,
1409 /* NIDTBL_VERSIONS */
1411 .olm_name = MGS_NIDTBL_DIR,
1412 .olm_flags = OLF_SCAN_SUBITEMS,
1413 .olm_namelen = sizeof(MGS_NIDTBL_DIR) - 1,
1414 .olm_scandir = osd_ios_general_scan,
1415 .olm_filldir = osd_ios_varfid_fill,
1420 .olm_name = MDT_ORPHAN_DIR,
1421 .olm_namelen = sizeof(MDT_ORPHAN_DIR) - 1,
1428 .f_seq = FID_SEQ_ROOT,
1429 .f_oid = FID_OID_ROOT,
1431 .olm_flags = OLF_SCAN_SUBITEMS | OLF_HIDE_FID,
1432 .olm_namelen = sizeof("ROOT") - 1,
1433 .olm_scandir = osd_ios_ROOT_scan,
1436 /* changelog_catalog */
1438 .olm_name = CHANGELOG_CATALOG,
1439 .olm_namelen = sizeof(CHANGELOG_CATALOG) - 1,
1442 /* changelog_users */
1444 .olm_name = CHANGELOG_USERS,
1445 .olm_namelen = sizeof(CHANGELOG_USERS) - 1,
1452 .f_seq = FID_SEQ_LOCAL_FILE,
1453 .f_oid = FLD_INDEX_OID,
1455 .olm_flags = OLF_SHOW_NAME,
1456 .olm_namelen = sizeof("fld") - 1,
1461 .olm_name = LAST_RCVD,
1463 .f_seq = FID_SEQ_LOCAL_FILE,
1464 .f_oid = LAST_RECV_OID,
1466 .olm_flags = OLF_SHOW_NAME,
1467 .olm_namelen = sizeof(LAST_RCVD) - 1,
1472 .olm_name = REPLY_DATA,
1474 .f_seq = FID_SEQ_LOCAL_FILE,
1475 .f_oid = REPLY_DATA_OID,
1477 .olm_flags = OLF_SHOW_NAME,
1478 .olm_namelen = sizeof(REPLY_DATA) - 1,
1483 .olm_name = LOV_OBJID,
1485 .f_seq = FID_SEQ_LOCAL_FILE,
1486 .f_oid = MDD_LOV_OBJ_OID,
1488 .olm_flags = OLF_SHOW_NAME,
1489 .olm_namelen = sizeof(LOV_OBJID) - 1,
1494 .olm_name = LOV_OBJSEQ,
1496 .f_seq = FID_SEQ_LOCAL_FILE,
1497 .f_oid = MDD_LOV_OBJ_OSEQ,
1499 .olm_flags = OLF_SHOW_NAME,
1500 .olm_namelen = sizeof(LOV_OBJSEQ) - 1,
1505 .olm_name = QMT_DIR,
1506 .olm_flags = OLF_SCAN_SUBITEMS,
1507 .olm_namelen = sizeof(QMT_DIR) - 1,
1508 .olm_scandir = osd_ios_general_scan,
1509 .olm_filldir = osd_ios_varfid_fill,
1514 .olm_name = QSD_DIR,
1515 .olm_flags = OLF_SCAN_SUBITEMS,
1516 .olm_namelen = sizeof(QSD_DIR) - 1,
1517 .olm_scandir = osd_ios_general_scan,
1518 .olm_filldir = osd_ios_varfid_fill,
1523 .olm_name = "seq_ctl",
1525 .f_seq = FID_SEQ_LOCAL_FILE,
1526 .f_oid = FID_SEQ_CTL_OID,
1528 .olm_flags = OLF_SHOW_NAME,
1529 .olm_namelen = sizeof("seq_ctl") - 1,
1534 .olm_name = "seq_srv",
1536 .f_seq = FID_SEQ_LOCAL_FILE,
1537 .f_oid = FID_SEQ_SRV_OID,
1539 .olm_flags = OLF_SHOW_NAME,
1540 .olm_namelen = sizeof("seq_srv") - 1,
1545 .olm_name = HEALTH_CHECK,
1547 .f_seq = FID_SEQ_LOCAL_FILE,
1548 .f_oid = OFD_HEALTH_CHECK_OID,
1550 .olm_flags = OLF_SHOW_NAME,
1551 .olm_namelen = sizeof(HEALTH_CHECK) - 1,
1556 .olm_name = LFSCK_DIR,
1557 .olm_flags = OLF_SCAN_SUBITEMS,
1558 .olm_namelen = sizeof(LFSCK_DIR) - 1,
1559 .olm_scandir = osd_ios_general_scan,
1560 .olm_filldir = osd_ios_varfid_fill,
1563 /* lfsck_bookmark */
1565 .olm_name = LFSCK_BOOKMARK,
1566 .olm_namelen = sizeof(LFSCK_BOOKMARK) - 1,
1571 .olm_name = LFSCK_LAYOUT,
1572 .olm_namelen = sizeof(LFSCK_LAYOUT) - 1,
1575 /* lfsck_namespace */
1577 .olm_name = LFSCK_NAMESPACE,
1578 .olm_namelen = sizeof(LFSCK_NAMESPACE) - 1,
1581 /* OBJECTS, upgrade from old device */
1583 .olm_name = OBJECTS,
1584 .olm_flags = OLF_SCAN_SUBITEMS,
1585 .olm_namelen = sizeof(OBJECTS) - 1,
1586 .olm_scandir = osd_ios_OBJECTS_scan,
1589 /* lquota_v2.user, upgrade from old device */
1591 .olm_name = "lquota_v2.user",
1592 .olm_namelen = sizeof("lquota_v2.user") - 1,
1595 /* lquota_v2.group, upgrade from old device */
1597 .olm_name = "lquota_v2.group",
1598 .olm_namelen = sizeof("lquota_v2.group") - 1,
1601 /* LAST_GROUP, upgrade from old device */
1603 .olm_name = "LAST_GROUP",
1605 .f_seq = FID_SEQ_LOCAL_FILE,
1606 .f_oid = OFD_LAST_GROUP_OID,
1608 .olm_flags = OLF_SHOW_NAME,
1609 .olm_namelen = sizeof("LAST_GROUP") - 1,
1612 /* committed batchid for cross-MDT operation */
1614 .olm_name = "BATCHID",
1616 .f_seq = FID_SEQ_LOCAL_FILE,
1617 .f_oid = BATCHID_COMMITTED_OID,
1619 .olm_flags = OLF_SHOW_NAME,
1620 .olm_namelen = sizeof("BATCHID") - 1,
1623 /* OSP update logs update_log{_dir} use f_seq = FID_SEQ_UPDATE_LOG{_DIR}
1624 * and f_oid = index for their log files. See lu_update_log{_dir}_fid()
1625 * for more details. */
1629 .olm_name = "update_log",
1631 .f_seq = FID_SEQ_UPDATE_LOG,
1633 .olm_flags = OLF_SHOW_NAME | OLF_IDX_IN_FID,
1634 .olm_namelen = sizeof("update_log") - 1,
1637 /* update_log_dir */
1639 .olm_name = "update_log_dir",
1641 .f_seq = FID_SEQ_UPDATE_LOG_DIR,
1643 .olm_flags = OLF_SHOW_NAME | OLF_SCAN_SUBITEMS |
1645 .olm_namelen = sizeof("update_log_dir") - 1,
1646 .olm_scandir = osd_ios_general_scan,
1647 .olm_filldir = osd_ios_uld_fill,
1652 .olm_name = "lost+found",
1654 .f_seq = FID_SEQ_LOCAL_FILE,
1655 .f_oid = OSD_LPF_OID,
1657 .olm_flags = OLF_SCAN_SUBITEMS,
1658 .olm_namelen = sizeof("lost+found") - 1,
1659 .olm_scandir = osd_ios_general_scan,
1660 .olm_filldir = osd_ios_lf_fill,
1665 .olm_name = HSM_ACTIONS,
1670 .olm_name = LUSTRE_NODEMAP_NAME,
1675 .olm_name = INDEX_BACKUP_DIR,
1677 .f_seq = FID_SEQ_LOCAL_FILE,
1678 .f_oid = INDEX_BACKUP_OID,
1680 .olm_flags = OLF_SCAN_SUBITEMS | OLF_NOT_BACKUP,
1681 .olm_namelen = sizeof(INDEX_BACKUP_DIR) - 1,
1682 .olm_scandir = osd_ios_general_scan,
1683 .olm_filldir = osd_ios_varfid_fill,
1691 /* Add the new introduced files under .lustre/ in the list in the future. */
1692 static const struct osd_lf_map osd_dl_maps[] = {
1697 .f_seq = FID_SEQ_DOT_LUSTRE,
1698 .f_oid = FID_OID_DOT_LUSTRE_OBF,
1700 .olm_namelen = sizeof("fid") - 1,
1703 /* .lustre/lost+found */
1705 .olm_name = "lost+found",
1707 .f_seq = FID_SEQ_DOT_LUSTRE,
1708 .f_oid = FID_OID_DOT_LUSTRE_LPF,
1710 .olm_namelen = sizeof("lost+found") - 1,
1718 struct osd_ios_item {
1719 struct list_head oii_list;
1720 struct dentry *oii_dentry;
1721 scandir_t oii_scandir;
1722 filldir_t oii_filldir;
1725 struct osd_ios_filldir_buf {
1726 /* please keep it as first member */
1727 struct dir_context ctx;
1728 struct osd_thread_info *oifb_info;
1729 struct osd_device *oifb_dev;
1730 struct dentry *oifb_dentry;
1735 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1736 scandir_t scandir, filldir_t filldir)
1738 struct osd_ios_item *item;
1741 OBD_ALLOC_PTR(item);
1745 INIT_LIST_HEAD(&item->oii_list);
1746 item->oii_dentry = dget(dentry);
1747 item->oii_scandir = scandir;
1748 item->oii_filldir = filldir;
1749 list_add_tail(&item->oii_list, &dev->od_ios_list);
1754 static bool osd_index_need_recreate(const struct lu_env *env,
1755 struct osd_device *dev, struct inode *inode)
1757 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1758 struct iam_container *bag = &iam->od_container;
1762 rc = iam_container_init(bag, &iam->od_descr, inode);
1766 rc = iam_container_setup(bag);
1767 iam_container_fini(bag);
1774 static void osd_ios_index_register(const struct lu_env *env,
1775 struct osd_device *osd,
1776 const struct lu_fid *fid,
1777 struct inode *inode)
1779 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1780 struct iam_container *bag = &iam->od_container;
1781 struct super_block *sb = osd_sb(osd);
1782 struct iam_descr *descr;
1788 /* Index must be a regular file. */
1789 if (!S_ISREG(inode->i_mode))
1792 /* Index's size must be block aligned. */
1793 if (inode->i_size < sb->s_blocksize ||
1794 (inode->i_size & (sb->s_blocksize - 1)) != 0)
1797 iam_container_init(bag, &iam->od_descr, inode);
1798 rc = iam_container_setup(bag);
1802 descr = bag->ic_descr;
1803 /* May be regular file with IAM_LFIX_ROOT_MAGIC matched
1804 * coincidentally, or corrupted index object, skip it. */
1805 if (descr->id_ptr_size != 4)
1808 keysize = descr->id_key_size;
1809 recsize = descr->id_rec_size;
1810 rc = osd_index_register(osd, fid, keysize, recsize);
1815 iam_container_fini(bag);
1817 CDEBUG(D_LFSCK, "%s: index object "DFID" (%u/%u) registered\n",
1818 osd_name(osd), PFID(fid), keysize, recsize);
1821 static void osd_index_restore(const struct lu_env *env, struct osd_device *dev,
1822 struct lustre_index_restore_unit *liru,
1823 void *buf, int bufsize)
1825 struct osd_thread_info *info = osd_oti_get(env);
1826 struct osd_inode_id *id = &info->oti_id;
1827 struct lu_fid *tgt_fid = &liru->liru_cfid;
1828 struct inode *bak_inode = NULL;
1829 struct ldiskfs_dir_entry_2 *de = NULL;
1830 struct buffer_head *bh = NULL;
1831 struct dentry *dentry;
1833 struct lu_fid bak_fid;
1837 lustre_fid2lbx(name, tgt_fid, bufsize);
1838 dentry = osd_child_dentry_by_inode(env, dev->od_index_backup_inode,
1839 name, strlen(name));
1840 bh = osd_ldiskfs_find_entry(dev->od_index_backup_inode,
1841 &dentry->d_name, &de, NULL, NULL);
1843 GOTO(log, rc = PTR_ERR(bh));
1845 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
1847 bak_inode = osd_iget_fid(info, dev, id, &bak_fid);
1848 if (IS_ERR(bak_inode))
1849 GOTO(log, rc = PTR_ERR(bak_inode));
1852 /* The OI mapping for index may be invalid, since it will be
1853 * re-created, not update the OI mapping, just cache it in RAM. */
1854 osd_id_gen(id, liru->liru_clid, OSD_OII_NOGEN);
1855 osd_add_oi_cache(info, dev, id, tgt_fid);
1856 rc = lustre_index_restore(env, &dev->od_dt_dev, &liru->liru_pfid,
1857 tgt_fid, &bak_fid, liru->liru_name,
1858 &dev->od_index_backup_list, &dev->od_lock,
1863 CDEBUG(D_WARNING, "%s: restore index '%s' with "DFID": rc = %d\n",
1864 osd_name(dev), liru->liru_name, PFID(tgt_fid), rc);
1868 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1870 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1871 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1872 * reference the inode, or fixed if it is missing or references another inode.
1875 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1876 struct inode *parent, struct inode *inode,
1877 const struct lu_fid *fid, const char *name,
1878 int namelen, int flags)
1880 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1881 struct osd_inode_id *id = &info->oti_id;
1882 struct osd_inode_id *id2 = &info->oti_id2;
1883 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1884 struct scrub_file *sf = &scrub->os_file;
1890 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode: rc = -2\n",
1891 osd_name(dev), namelen, name);
1895 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
1896 &info->oti_ost_attrs);
1897 if (rc != 0 && rc != -ENODATA) {
1898 CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
1899 "rc = %d\n", osd_name(dev), rc);
1904 osd_id_gen(id, inode->i_ino, inode->i_generation);
1905 if (rc == -ENODATA) {
1906 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID) {
1907 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1910 if (flags & OLF_IDX_IN_FID) {
1911 LASSERT(dev->od_index >= 0);
1913 tfid.f_oid = dev->od_index;
1916 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1918 CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
1919 "scrub: rc = %d\n", osd_name(dev), rc);
1924 if (lma->lma_compat & LMAC_NOT_IN_OI)
1927 tfid = lma->lma_self_fid;
1928 if (lma->lma_compat & LMAC_IDX_BACKUP &&
1929 osd_index_need_recreate(info->oti_env, dev, inode)) {
1930 struct lu_fid *pfid = &info->oti_fid3;
1932 if (is_root_inode(parent)) {
1933 lu_local_obj_fid(pfid, OSD_FS_ROOT_OID);
1935 rc = osd_scrub_get_fid(info, dev, parent, pfid,
1941 rc = lustre_liru_new(&dev->od_index_restore_list, pfid,
1942 &tfid, inode->i_ino, name, namelen);
1947 if (!(flags & OLF_NOT_BACKUP))
1948 osd_ios_index_register(info->oti_env, dev, &tfid,
1952 /* Since this called from iterate_dir() the inode lock will be taken */
1953 rc = osd_oi_lookup(info, dev, &tfid, id2, OI_LOCKED);
1958 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1959 DTO_INDEX_INSERT, true, 0, NULL);
1966 if (osd_id_eq_strict(id, id2))
1969 if (!(sf->sf_flags & SF_INCONSISTENT)) {
1970 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
1971 rc = scrub_file_store(info->oti_env, scrub);
1976 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1977 DTO_INDEX_UPDATE, true, 0, NULL);
1985 * It scans the /lost+found, and for the OST-object (with filter_fid
1986 * or filter_fid_18_23), move them back to its proper /O/<seq>/d<x>.
1988 #ifdef HAVE_FILLDIR_USE_CTX
1989 static int osd_ios_lf_fill(struct dir_context *buf,
1991 static int osd_ios_lf_fill(void *buf,
1993 const char *name, int namelen,
1994 loff_t offset, __u64 ino, unsigned d_type)
1996 struct osd_ios_filldir_buf *fill_buf =
1997 (struct osd_ios_filldir_buf *)buf;
1998 struct osd_thread_info *info = fill_buf->oifb_info;
1999 struct osd_device *dev = fill_buf->oifb_dev;
2000 struct lu_fid *fid = &info->oti_fid;
2001 struct osd_scrub *scrub = &dev->od_scrub;
2002 struct dentry *parent = fill_buf->oifb_dentry;
2003 struct dentry *child;
2004 struct inode *dir = parent->d_inode;
2005 struct inode *inode;
2009 fill_buf->oifb_items++;
2011 /* skip any '.' started names */
2015 scrub->os_lf_scanned++;
2016 child = osd_lookup_one_len(dev, name, parent, namelen);
2017 if (IS_ERR(child)) {
2018 rc = PTR_ERR(child);
2019 CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
2020 osd_name(dev), namelen, name, rc);
2022 } else if (!child->d_inode) {
2024 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode\n",
2025 osd_name(dev), namelen, name);
2029 inode = child->d_inode;
2030 if (S_ISDIR(inode->i_mode)) {
2031 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2034 CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
2035 "rc = %d\n", osd_name(dev), namelen, name, rc);
2039 if (!S_ISREG(inode->i_mode))
2042 rc = osd_scrub_get_fid(info, dev, inode, fid, true);
2043 if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
2044 rc = osd_obj_map_recover(info, dev, dir, child, fid);
2046 CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
2047 "/lost+found.\n", namelen, name, PFID(fid));
2048 scrub->os_lf_repaired++;
2050 CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
2052 osd_name(dev), namelen, name, PFID(fid), rc);
2056 /* XXX: For MDT-objects, we can move them from /lost+found to namespace
2057 * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
2058 * can process them in furtuer. */
2064 scrub->os_lf_failed++;
2066 /* skip the failure to make the scanning to continue. */
2070 #ifdef HAVE_FILLDIR_USE_CTX
2071 static int osd_ios_varfid_fill(struct dir_context *buf,
2073 static int osd_ios_varfid_fill(void *buf,
2075 const char *name, int namelen,
2076 loff_t offset, __u64 ino, unsigned d_type)
2078 struct osd_ios_filldir_buf *fill_buf =
2079 (struct osd_ios_filldir_buf *)buf;
2080 struct osd_device *dev = fill_buf->oifb_dev;
2081 struct dentry *child;
2085 fill_buf->oifb_items++;
2087 /* skip any '.' started names */
2091 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2093 RETURN(PTR_ERR(child));
2095 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2096 fill_buf->oifb_dentry->d_inode, child->d_inode,
2097 NULL, name, namelen, 0);
2098 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
2099 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2100 osd_ios_varfid_fill);
2106 #ifdef HAVE_FILLDIR_USE_CTX
2107 static int osd_ios_dl_fill(struct dir_context *buf,
2109 static int osd_ios_dl_fill(void *buf,
2111 const char *name, int namelen,
2112 loff_t offset, __u64 ino, unsigned d_type)
2114 struct osd_ios_filldir_buf *fill_buf =
2115 (struct osd_ios_filldir_buf *)buf;
2116 struct osd_device *dev = fill_buf->oifb_dev;
2117 const struct osd_lf_map *map;
2118 struct dentry *child;
2122 fill_buf->oifb_items++;
2124 /* skip any '.' started names */
2128 for (map = osd_dl_maps; map->olm_name != NULL; map++) {
2129 if (map->olm_namelen != namelen)
2132 if (strncmp(map->olm_name, name, namelen) == 0)
2136 if (map->olm_name == NULL)
2139 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2141 RETURN(PTR_ERR(child));
2143 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2144 fill_buf->oifb_dentry->d_inode, child->d_inode,
2145 &map->olm_fid, name, namelen, map->olm_flags);
2151 #ifdef HAVE_FILLDIR_USE_CTX
2152 static int osd_ios_uld_fill(struct dir_context *buf,
2154 static int osd_ios_uld_fill(void *buf,
2156 const char *name, int namelen,
2157 loff_t offset, __u64 ino, unsigned d_type)
2159 struct osd_ios_filldir_buf *fill_buf =
2160 (struct osd_ios_filldir_buf *)buf;
2161 struct osd_device *dev = fill_buf->oifb_dev;
2162 struct dentry *child;
2167 fill_buf->oifb_items++;
2169 /* skip any non-DFID format name */
2173 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2175 RETURN(PTR_ERR(child));
2177 /* skip the start '[' */
2178 sscanf(&name[1], SFID, RFID(&tfid));
2179 if (fid_is_sane(&tfid))
2180 rc = osd_ios_scan_one(fill_buf->oifb_info, fill_buf->oifb_dev,
2181 fill_buf->oifb_dentry->d_inode,
2182 child->d_inode, &tfid, name, namelen, 0);
2190 #ifdef HAVE_FILLDIR_USE_CTX
2191 static int osd_ios_root_fill(struct dir_context *buf,
2193 static int osd_ios_root_fill(void *buf,
2195 const char *name, int namelen,
2196 loff_t offset, __u64 ino, unsigned d_type)
2198 struct osd_ios_filldir_buf *fill_buf =
2199 (struct osd_ios_filldir_buf *)buf;
2200 struct osd_device *dev = fill_buf->oifb_dev;
2201 const struct osd_lf_map *map;
2202 struct dentry *child;
2206 fill_buf->oifb_items++;
2208 /* skip any '.' started names */
2212 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
2213 if (map->olm_namelen != namelen)
2216 if (strncmp(map->olm_name, name, namelen) == 0)
2220 if (map->olm_name == NULL)
2223 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2225 RETURN(PTR_ERR(child));
2226 else if (!child->d_inode)
2227 GOTO(out_put, rc = -ENOENT);
2229 if (!(map->olm_flags & OLF_NO_OI))
2230 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2231 fill_buf->oifb_dentry->d_inode, child->d_inode,
2232 &map->olm_fid, name, namelen, map->olm_flags);
2233 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
2234 rc = osd_ios_new_item(dev, child, map->olm_scandir,
2243 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
2244 struct dentry *dentry, filldir_t filldir)
2246 struct osd_ios_filldir_buf buf = {
2247 .ctx.actor = filldir,
2250 .oifb_dentry = dentry
2253 struct inode *inode = dentry->d_inode;
2258 LASSERT(filldir != NULL);
2260 filp = osd_quasi_file_by_dentry(info->oti_env, dentry);
2261 rc = osd_security_file_alloc(filp);
2267 rc = iterate_dir(filp, &buf.ctx);
2268 } while (rc >= 0 && buf.oifb_items > 0 &&
2269 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
2270 inode->i_fop->release(inode, filp);
2276 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
2277 struct dentry *dentry, filldir_t filldir)
2279 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2280 struct scrub_file *sf = &scrub->os_file;
2281 struct dentry *child;
2285 /* It is existing MDT0 device. We only allow the case of object without
2286 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
2287 * can generate IGIF mode FID for the object and related OI mapping. If
2288 * it is on other MDTs, then becuase file-level backup/restore, related
2289 * OI mapping may be invalid already, we do not know which is the right
2290 * FID for the object. We only allow IGIF objects to reside on the MDT0.
2292 * XXX: For the case of object on non-MDT0 device with neither LMA nor
2293 * "fid" xattr, then something crashed. We cannot re-generate the
2294 * FID directly, instead, the OI scrub will scan the OI structure
2295 * and try to re-generate the LMA from the OI mapping. But if the
2296 * OI mapping crashed or lost also, then we have to give up under
2297 * double failure cases.
2299 spin_lock(&scrub->os_lock);
2300 scrub->os_convert_igif = 1;
2301 spin_unlock(&scrub->os_lock);
2302 child = osd_lookup_one_len_unlocked(dev, dot_lustre_name, dentry,
2303 strlen(dot_lustre_name));
2304 if (IS_ERR(child)) {
2305 if (PTR_ERR(child) != -ENOENT)
2306 RETURN(PTR_ERR(child));
2310 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
2311 * so the client will get IGIF for the ".lustre" object when
2314 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
2315 * it does not know whether there are some old clients cached
2316 * the ".lustre" IGIF during the upgrading. Two choices:
2318 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
2319 * It will allow the old connected clients to access the
2320 * ".lustre" with cached IGIF. But it will cause others
2321 * on the MDT failed to check "fid_is_dot_lustre()".
2323 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
2324 * for ".lustre" in spite of whether there are some clients
2325 * cached the ".lustre" IGIF or not. It enables the check
2326 * "fid_is_dot_lustre()" on the MDT, although it will cause
2327 * that the old connected clients cannot access the ".lustre"
2328 * with the cached IGIF.
2330 * Usually, it is rare case for the old connected clients
2331 * to access the ".lustre" with cached IGIF. So we prefer
2332 * to the solution 2).
2334 inode_lock(dentry->d_inode);
2335 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2336 child->d_inode, &LU_DOT_LUSTRE_FID,
2338 strlen(dot_lustre_name), 0);
2339 inode_unlock(dentry->d_inode);
2340 if (rc == -ENOENT) {
2342 /* It is 1.8 MDT device. */
2343 if (!(sf->sf_flags & SF_UPGRADE)) {
2344 scrub_file_reset(scrub, dev->od_uuid,
2346 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2347 rc = scrub_file_store(info->oti_env, scrub);
2351 } else if (rc == 0) {
2352 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2361 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
2362 struct dentry *dentry, filldir_t filldir)
2364 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2365 struct scrub_file *sf = &scrub->os_file;
2366 struct dentry *child;
2370 if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
2371 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2372 rc = scrub_file_store(info->oti_env, scrub);
2377 child = osd_lookup_one_len_unlocked(dev, ADMIN_USR, dentry,
2379 if (IS_ERR(child)) {
2380 rc = PTR_ERR(child);
2382 inode_lock(dentry->d_inode);
2383 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2384 child->d_inode, NULL, ADMIN_USR,
2385 strlen(ADMIN_USR), 0);
2386 inode_unlock(dentry->d_inode);
2390 if (rc != 0 && rc != -ENOENT)
2393 child = osd_lookup_one_len_unlocked(dev, ADMIN_GRP, dentry,
2396 GOTO(out, rc = PTR_ERR(child));
2398 inode_lock(dentry->d_inode);
2399 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2400 child->d_inode, NULL, ADMIN_GRP,
2401 strlen(ADMIN_GRP), 0);
2402 inode_unlock(dentry->d_inode);
2405 RETURN(rc == -ENOENT ? 0 : rc);
2408 static void osd_initial_OI_scrub(struct osd_thread_info *info,
2409 struct osd_device *dev)
2411 struct osd_ios_item *item = NULL;
2412 scandir_t scandir = osd_ios_general_scan;
2413 filldir_t filldir = osd_ios_root_fill;
2414 struct dentry *dentry = osd_sb(dev)->s_root;
2415 const struct osd_lf_map *map = osd_lf_maps;
2418 /* Lookup IGIF in OI by force for initial OI scrub. */
2419 dev->od_igif_inoi = 1;
2422 /* Don't take inode_lock here since scandir() callbacks
2423 * can call VFS functions which may manully take the
2424 * inode lock itself like iterate_dir(). Since this
2425 * is the case it is best to leave the scandir()
2426 * callbacks to managing the inode lock.
2428 scandir(info, dev, dentry, filldir);
2430 dput(item->oii_dentry);
2434 if (list_empty(&dev->od_ios_list))
2437 item = list_entry(dev->od_ios_list.next,
2438 struct osd_ios_item, oii_list);
2439 list_del_init(&item->oii_list);
2441 LASSERT(item->oii_scandir != NULL);
2442 scandir = item->oii_scandir;
2443 filldir = item->oii_filldir;
2444 dentry = item->oii_dentry;
2447 /* There maybe the case that the object has been removed, but its OI
2448 * mapping is still in the OI file, such as the "CATALOGS" after MDT
2449 * file-level backup/restore. So here cleanup the stale OI mappings. */
2450 while (map->olm_name != NULL) {
2451 struct dentry *child;
2453 if (fid_is_zero(&map->olm_fid)) {
2458 child = osd_lookup_one_len_unlocked(dev, map->olm_name,
2459 osd_sb(dev)->s_root,
2461 if (PTR_ERR(child) == -ENOENT ||
2462 (!IS_ERR(child) && !child->d_inode))
2463 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
2464 NULL, DTO_INDEX_DELETE,
2471 if (!list_empty(&dev->od_index_restore_list)) {
2474 OBD_ALLOC_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2476 CERROR("%s: not enough RAM for rebuild index\n",
2479 while (!list_empty(&dev->od_index_restore_list)) {
2480 struct lustre_index_restore_unit *liru;
2482 liru = list_entry(dev->od_index_restore_list.next,
2483 struct lustre_index_restore_unit,
2485 list_del(&liru->liru_link);
2487 osd_index_restore(info->oti_env, dev, liru,
2488 buf, INDEX_BACKUP_BUFSIZE);
2489 OBD_FREE(liru, liru->liru_len);
2493 OBD_FREE_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2499 char *osd_lf_fid2name(const struct lu_fid *fid)
2501 const struct osd_lf_map *map = osd_lf_maps;
2503 while (map->olm_name != NULL) {
2504 if (!lu_fid_eq(fid, &map->olm_fid)) {
2509 if (map->olm_flags & OLF_SHOW_NAME)
2510 return map->olm_name;
2518 /* OI scrub start/stop */
2520 int osd_scrub_start(const struct lu_env *env, struct osd_device *dev,
2523 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2527 if (dev->od_dt_dev.dd_rdonly)
2530 /* od_otable_mutex: prevent curcurrent start/stop */
2531 mutex_lock(&dev->od_otable_mutex);
2532 rc = scrub_start(osd_scrub_main, scrub, dev, flags);
2533 if (rc == -EALREADY) {
2535 if ((scrub->os_file.sf_flags & SF_AUTO ||
2536 scrub->os_partial_scan) &&
2537 !(flags & SS_AUTO_PARTIAL))
2538 osd_scrub_join(env, dev, flags, false);
2540 mutex_unlock(&dev->od_otable_mutex);
2545 void osd_scrub_stop(struct osd_device *dev)
2547 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2549 /* od_otable_mutex: prevent curcurrent start/stop */
2550 mutex_lock(&dev->od_otable_mutex);
2551 spin_lock(&scrub->os_lock);
2552 scrub->os_paused = 1;
2553 spin_unlock(&scrub->os_lock);
2555 mutex_unlock(&dev->od_otable_mutex);
2558 /* OI scrub setup/cleanup */
2560 static const char osd_scrub_name[] = "OI_scrub";
2562 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
2564 struct osd_thread_info *info = osd_oti_get(env);
2565 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2566 struct lvfs_run_ctxt *ctxt = &dev->od_scrub.os_ctxt;
2567 struct scrub_file *sf = &scrub->os_file;
2568 struct super_block *sb = osd_sb(dev);
2569 struct lvfs_run_ctxt saved;
2571 struct inode *inode;
2572 struct lu_fid *fid = &info->oti_fid;
2573 struct osd_inode_id *id = &info->oti_id;
2574 struct dt_object *obj;
2576 bool restored = false;
2580 memset(&dev->od_scrub, 0, sizeof(struct osd_scrub));
2581 OBD_SET_CTXT_MAGIC(ctxt);
2582 ctxt->pwdmnt = dev->od_mnt;
2583 ctxt->pwd = dev->od_mnt->mnt_root;
2585 init_rwsem(&scrub->os_rwsem);
2586 spin_lock_init(&scrub->os_lock);
2587 INIT_LIST_HEAD(&scrub->os_inconsistent_items);
2588 scrub->os_name = osd_name(dev);
2590 push_ctxt(&saved, ctxt);
2591 filp = filp_open(osd_scrub_name, O_RDWR |
2592 (dev->od_dt_dev.dd_rdonly ? 0 : O_CREAT), 0644);
2594 pop_ctxt(&saved, ctxt);
2595 RETURN(PTR_ERR(filp));
2598 inode = file_inode(filp);
2599 ldiskfs_set_inode_flag(inode, LDISKFS_INODE_JOURNAL_DATA);
2600 if (!dev->od_dt_dev.dd_rdonly) {
2601 /* 'What the @fid is' is not imporatant, because the object
2602 * has no OI mapping, and only is visible inside the OSD.*/
2603 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2604 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
2606 filp_close(filp, NULL);
2607 pop_ctxt(&saved, ctxt);
2612 osd_id_gen(id, inode->i_ino, inode->i_generation);
2613 osd_add_oi_cache(info, dev, id, fid);
2614 filp_close(filp, NULL);
2615 pop_ctxt(&saved, ctxt);
2617 obj = lu2dt(lu_object_find_slice(env, osd2lu_dev(dev), fid, NULL));
2618 if (IS_ERR_OR_NULL(obj))
2619 RETURN(obj ? PTR_ERR(obj) : -ENOENT);
2621 #ifndef HAVE_S_UUID_AS_UUID_T
2622 memcpy(dev->od_uuid.b, sb->s_uuid, sizeof(dev->od_uuid));
2624 uuid_copy(&dev->od_uuid, &sb->s_uuid);
2626 scrub->os_obj = obj;
2627 rc = scrub_file_load(env, scrub);
2628 if (rc == -ENOENT || rc == -EFAULT) {
2629 scrub_file_init(scrub, dev->od_uuid);
2630 /* If the "/O" dir does not exist when mount (indicated by
2631 * osd_device::od_maybe_new), neither for the "/OI_scrub",
2632 * then it is quite probably that the device is a new one,
2633 * under such case, mark it as SIF_NO_HANDLE_OLD_FID.
2635 * For the rare case that "/O" and "OI_scrub" both lost on
2636 * an old device, it can be found and cleared later.
2638 * For the system with "SIF_NO_HANDLE_OLD_FID", we do not
2639 * need to check "filter_fid_18_23" and to convert it to
2640 * "filter_fid" for each object, and all the IGIF should
2641 * have their FID mapping in OI files already. */
2642 if (dev->od_maybe_new && rc == -ENOENT)
2643 sf->sf_internal_flags = SIF_NO_HANDLE_OLD_FID;
2645 } else if (rc < 0) {
2646 GOTO(cleanup_obj, rc);
2648 if (!uuid_equal(&sf->sf_uuid, &dev->od_uuid)) {
2650 "%s: UUID has been changed from %pU to %pU\n",
2651 osd_dev2name(dev), &sf->sf_uuid, &dev->od_uuid);
2652 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
2655 } else if (sf->sf_status == SS_SCANNING) {
2656 sf->sf_status = SS_CRASHED;
2660 if ((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) {
2661 LCONSOLE_WARN("%s: invalid oi count %d, set it to %d\n",
2662 osd_dev2name(dev), sf->sf_oi_count,
2664 sf->sf_oi_count = osd_oi_count;
2669 if (sf->sf_pos_last_checkpoint != 0)
2670 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
2672 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
2675 rc = scrub_file_store(env, scrub);
2677 GOTO(cleanup_obj, rc);
2680 /* Initialize OI files. */
2681 rc = osd_oi_init(info, dev, restored);
2683 GOTO(cleanup_obj, rc);
2685 if (!dev->od_dt_dev.dd_rdonly)
2686 osd_initial_OI_scrub(info, dev);
2688 if (sf->sf_flags & SF_UPGRADE ||
2689 !(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID ||
2690 sf->sf_success_count > 0)) {
2691 dev->od_igif_inoi = 0;
2692 dev->od_check_ff = dev->od_is_ost;
2694 dev->od_igif_inoi = 1;
2695 dev->od_check_ff = 0;
2698 if (sf->sf_flags & SF_INCONSISTENT)
2699 /* The 'od_igif_inoi' will be set under the
2701 * 1) new created system, or
2702 * 2) restored from file-level backup, or
2703 * 3) the upgrading completed.
2705 * The 'od_igif_inoi' may be cleared by OI scrub
2706 * later if found that the system is upgrading. */
2707 dev->od_igif_inoi = 1;
2709 if (!dev->od_dt_dev.dd_rdonly &&
2710 dev->od_auto_scrub_interval != AS_NEVER &&
2711 ((sf->sf_status == SS_PAUSED) ||
2712 (sf->sf_status == SS_CRASHED &&
2713 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2714 SF_UPGRADE | SF_AUTO)) ||
2715 (sf->sf_status == SS_INIT &&
2716 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2718 rc = osd_scrub_start(env, dev, SS_AUTO_FULL);
2721 GOTO(cleanup_oi, rc);
2723 /* it is possible that dcache entries may keep objects after they are
2724 * deleted by OSD. While it looks safe this can cause object data to
2725 * stay until umount causing failures in tests calculating free space,
2726 * e.g. replay-ost-single. Since those dcache entries are not used
2727 * anymore let's just free them after use here */
2728 shrink_dcache_sb(sb);
2732 osd_oi_fini(info, dev);
2734 dt_object_put_nocache(env, scrub->os_obj);
2735 scrub->os_obj = NULL;
2740 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
2742 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2744 LASSERT(dev->od_otable_it == NULL);
2746 if (scrub->os_obj != NULL) {
2747 osd_scrub_stop(dev);
2748 dt_object_put_nocache(env, scrub->os_obj);
2749 scrub->os_obj = NULL;
2753 /* object table based iteration APIs */
2755 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
2756 struct dt_object *dt, __u32 attr)
2758 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
2759 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
2760 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
2761 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2762 struct osd_otable_it *it;
2767 /* od_otable_mutex: prevent curcurrent init/fini */
2768 mutex_lock(&dev->od_otable_mutex);
2769 if (dev->od_otable_it != NULL)
2770 GOTO(out, it = ERR_PTR(-EALREADY));
2774 GOTO(out, it = ERR_PTR(-ENOMEM));
2776 dev->od_otable_it = it;
2778 it->ooi_cache.ooc_consumer_idx = -1;
2779 if (flags & DOIF_OUTUSED)
2780 it->ooi_used_outside = 1;
2782 if (flags & DOIF_RESET)
2785 if (valid & DOIV_ERROR_HANDLE) {
2786 if (flags & DOIF_FAILOUT)
2787 start |= SS_SET_FAILOUT;
2789 start |= SS_CLEAR_FAILOUT;
2792 if (valid & DOIV_DRYRUN) {
2793 if (flags & DOIF_DRYRUN)
2794 start |= SS_SET_DRYRUN;
2796 start |= SS_CLEAR_DRYRUN;
2799 rc = scrub_start(osd_scrub_main, scrub, dev, start & ~SS_AUTO_PARTIAL);
2800 if (rc == -EALREADY) {
2801 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2802 } else if (rc < 0) {
2803 dev->od_otable_it = NULL;
2807 /* We have to start from the begining. */
2808 it->ooi_cache.ooc_pos_preload =
2809 LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2815 mutex_unlock(&dev->od_otable_mutex);
2816 return (struct dt_it *)it;
2819 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2821 struct osd_otable_it *it = (struct osd_otable_it *)di;
2822 struct osd_device *dev = it->ooi_dev;
2824 /* od_otable_mutex: prevent curcurrent init/fini */
2825 mutex_lock(&dev->od_otable_mutex);
2826 scrub_stop(&dev->od_scrub.os_scrub);
2827 LASSERT(dev->od_otable_it == it);
2829 dev->od_otable_it = NULL;
2830 mutex_unlock(&dev->od_otable_mutex);
2834 static int osd_otable_it_get(const struct lu_env *env,
2835 struct dt_it *di, const struct dt_key *key)
2840 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2845 osd_otable_it_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
2847 spin_lock(&scrub->os_lock);
2848 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2849 scrub->os_waiting || !scrub->os_running)
2850 it->ooi_waiting = 0;
2852 it->ooi_waiting = 1;
2853 spin_unlock(&scrub->os_lock);
2855 return !it->ooi_waiting;
2858 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2860 struct osd_otable_it *it = (struct osd_otable_it *)di;
2861 struct osd_device *dev = it->ooi_dev;
2862 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2863 struct osd_otable_cache *ooc = &it->ooi_cache;
2867 LASSERT(it->ooi_user_ready);
2870 if (!scrub->os_running && !it->ooi_used_outside)
2873 if (ooc->ooc_cached_items > 0) {
2874 ooc->ooc_cached_items--;
2875 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2876 ~OSD_OTABLE_IT_CACHE_MASK;
2880 if (it->ooi_all_cached) {
2881 wait_var_event(scrub, !scrub->os_running);
2885 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2886 spin_lock(&scrub->os_lock);
2887 scrub->os_waiting = 0;
2889 spin_unlock(&scrub->os_lock);
2892 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2893 wait_var_event(scrub, osd_otable_it_wakeup(scrub, it));
2895 if (!scrub->os_running && !it->ooi_used_outside)
2898 rc = osd_otable_it_preload(env, it);
2905 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2906 const struct dt_it *di)
2911 static int osd_otable_it_key_size(const struct lu_env *env,
2912 const struct dt_it *di)
2914 return sizeof(__u64);
2917 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2918 struct dt_rec *rec, __u32 attr)
2920 struct osd_otable_it *it = (struct osd_otable_it *)di;
2921 struct osd_otable_cache *ooc = &it->ooi_cache;
2923 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2925 /* Filter out Invald FID already. */
2926 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2927 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2928 PFID((struct lu_fid *)rec),
2929 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2934 static __u64 osd_otable_it_store(const struct lu_env *env,
2935 const struct dt_it *di)
2937 struct osd_otable_it *it = (struct osd_otable_it *)di;
2938 struct osd_otable_cache *ooc = &it->ooi_cache;
2941 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2942 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2944 hash = ooc->ooc_pos_preload;
2949 * Set the OSD layer iteration start position as the specified hash.
2951 static int osd_otable_it_load(const struct lu_env *env,
2952 const struct dt_it *di, __u64 hash)
2954 struct osd_otable_it *it = (struct osd_otable_it *)di;
2955 struct osd_device *dev = it->ooi_dev;
2956 struct osd_otable_cache *ooc = &it->ooi_cache;
2957 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2958 struct osd_iit_param *param = &it->ooi_iit_param;
2962 /* Forbid to set iteration position after iteration started. */
2963 if (it->ooi_user_ready)
2966 LASSERT(!scrub->os_partial_scan);
2968 if (hash > OSD_OTABLE_MAX_HASH)
2969 hash = OSD_OTABLE_MAX_HASH;
2971 /* The hash is the last checkpoint position,
2972 * we will start from the next one. */
2973 ooc->ooc_pos_preload = hash + 1;
2974 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
2975 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2977 it->ooi_user_ready = 1;
2978 if (!scrub->os_full_speed)
2981 memset(param, 0, sizeof(*param));
2982 param->sb = osd_sb(dev);
2983 param->start = ooc->ooc_pos_preload;
2984 param->bg = (ooc->ooc_pos_preload - 1) /
2985 LDISKFS_INODES_PER_GROUP(param->sb);
2986 param->offset = (ooc->ooc_pos_preload - 1) %
2987 LDISKFS_INODES_PER_GROUP(param->sb);
2988 param->gbase = 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
2990 /* Unplug OSD layer iteration by the first next() call. */
2991 rc = osd_otable_it_next(env, (struct dt_it *)it);
2996 static int osd_otable_it_key_rec(const struct lu_env *env,
2997 const struct dt_it *di, void *key_rec)
3002 const struct dt_index_operations osd_otable_ops = {
3004 .init = osd_otable_it_init,
3005 .fini = osd_otable_it_fini,
3006 .get = osd_otable_it_get,
3007 .put = osd_otable_it_put,
3008 .next = osd_otable_it_next,
3009 .key = osd_otable_it_key,
3010 .key_size = osd_otable_it_key_size,
3011 .rec = osd_otable_it_rec,
3012 .store = osd_otable_it_store,
3013 .load = osd_otable_it_load,
3014 .key_rec = osd_otable_it_key_rec,
3018 /* high priority inconsistent items list APIs */
3020 #define SCRUB_BAD_OIMAP_DECAY_INTERVAL 60
3022 int osd_oii_insert(struct osd_device *dev, struct osd_idmap_cache *oic,
3025 struct osd_inconsistent_item *oii;
3026 struct osd_scrub *oscrub = &dev->od_scrub;
3027 struct lustre_scrub *lscrub = &oscrub->os_scrub;
3032 if (unlikely(oii == NULL))
3035 INIT_LIST_HEAD(&oii->oii_list);
3036 oii->oii_cache = *oic;
3037 oii->oii_insert = insert;
3039 spin_lock(&lscrub->os_lock);
3040 if (lscrub->os_partial_scan) {
3041 __u64 now = ktime_get_real_seconds();
3043 /* If there haven't been errors in a long time,
3044 * decay old count until either the errors are
3045 * gone or we reach the current interval. */
3046 while (unlikely(oscrub->os_bad_oimap_count > 0 &&
3047 oscrub->os_bad_oimap_time +
3048 SCRUB_BAD_OIMAP_DECAY_INTERVAL < now)) {
3049 oscrub->os_bad_oimap_count >>= 1;
3050 oscrub->os_bad_oimap_time +=
3051 SCRUB_BAD_OIMAP_DECAY_INTERVAL;
3054 oscrub->os_bad_oimap_time = now;
3055 if (++oscrub->os_bad_oimap_count >
3056 dev->od_full_scrub_threshold_rate)
3057 lscrub->os_full_scrub = 1;
3060 if (!lscrub->os_running) {
3061 spin_unlock(&lscrub->os_lock);
3066 if (list_empty(&lscrub->os_inconsistent_items))
3068 list_add_tail(&oii->oii_list, &lscrub->os_inconsistent_items);
3069 spin_unlock(&lscrub->os_lock);
3072 wake_up_var(lscrub);
3077 int osd_oii_lookup(struct osd_device *dev, const struct lu_fid *fid,
3078 struct osd_inode_id *id)
3080 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3081 struct osd_inconsistent_item *oii;
3084 spin_lock(&scrub->os_lock);
3085 list_for_each_entry(oii, &scrub->os_inconsistent_items, oii_list) {
3086 if (lu_fid_eq(fid, &oii->oii_cache.oic_fid)) {
3087 *id = oii->oii_cache.oic_lid;
3088 spin_unlock(&scrub->os_lock);
3092 spin_unlock(&scrub->os_lock);
3097 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
3099 struct osd_scrub *scrub = &dev->od_scrub;
3101 scrub_dump(m, &scrub->os_scrub);
3102 seq_printf(m, "lf_scanned: %llu\n"
3104 "lf_failed: %llu\n",
3105 scrub->os_lf_scanned,
3106 scrub->os_scrub.os_file.sf_param & SP_DRYRUN ?
3107 "inconsistent" : "repaired",
3108 scrub->os_lf_repaired,
3109 scrub->os_lf_failed);