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 ll_vfs_dq_init(inode);
211 rc = osd_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)))
342 if (!scrub->os_partial_scan)
343 scrub->os_full_speed = 1;
346 case SCRUB_NEXT_NOLMA:
347 sf->sf_flags |= SF_UPGRADE;
348 if (!(sf->sf_param & SP_DRYRUN)) {
349 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
354 if (!(sf->sf_flags & SF_INCONSISTENT))
355 dev->od_igif_inoi = 0;
357 case SCRUB_NEXT_OSTOBJ:
358 sf->sf_flags |= SF_INCONSISTENT;
359 case SCRUB_NEXT_OSTOBJ_OLD:
364 } else if (osd_id_eq(lid, lid2)) {
366 sf->sf_items_updated++;
370 if (!scrub->os_partial_scan)
371 scrub->os_full_speed = 1;
373 sf->sf_flags |= SF_INCONSISTENT;
375 /* XXX: If the device is restored from file-level backup, then
376 * some IGIFs may have been already in OI files, and some
377 * may be not yet. Means upgrading from 1.8 may be partly
378 * processed, but some clients may hold some immobilized
379 * IGIFs, and use them to access related objects. Under
380 * such case, OSD does not know whether an given IGIF has
381 * been processed or to be processed, and it also cannot
382 * generate local ino#/gen# directly from the immobilized
383 * IGIF because of the backup/restore. Then force OSD to
384 * lookup the given IGIF in OI files, and if no entry,
385 * then ask the client to retry after upgrading completed.
386 * No better choice. */
387 dev->od_igif_inoi = 1;
390 rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops, false,
391 (val == SCRUB_NEXT_OSTOBJ ||
392 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0,
395 if (scrub->os_in_prior)
396 sf->sf_items_updated_prior++;
398 sf->sf_items_updated++;
400 if (ops == DTO_INDEX_INSERT && val == 0 && !exist) {
401 int idx = osd_oi_fid2idx(dev, fid);
403 sf->sf_flags |= SF_RECREATED;
404 if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
405 ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
413 sf->sf_items_failed++;
414 if (sf->sf_pos_first_inconsistent == 0 ||
415 sf->sf_pos_first_inconsistent > lid->oii_ino)
416 sf->sf_pos_first_inconsistent = lid->oii_ino;
421 /* There may be conflict unlink during the OI scrub,
422 * if happend, then remove the new added OI mapping. */
423 if (ops == DTO_INDEX_INSERT && inode != NULL && !IS_ERR(inode) &&
424 unlikely(ldiskfs_test_inode_state(inode,
425 LDISKFS_STATE_LUSTRE_DESTROY)))
426 osd_scrub_refresh_mapping(info, dev, fid, lid,
427 DTO_INDEX_DELETE, false,
428 (val == SCRUB_NEXT_OSTOBJ ||
429 val == SCRUB_NEXT_OSTOBJ_OLD) ?
430 OI_KNOWN_ON_OST : 0, NULL);
431 up_write(&scrub->os_rwsem);
433 if (inode != NULL && !IS_ERR(inode))
437 spin_lock(&scrub->os_lock);
438 if (likely(!list_empty(&oii->oii_list)))
439 list_del(&oii->oii_list);
440 spin_unlock(&scrub->os_lock);
445 RETURN(sf->sf_param & SP_FAILOUT ? rc : 0);
448 static int osd_scrub_prep(const struct lu_env *env, struct osd_device *dev)
450 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
451 struct ptlrpc_thread *thread = &scrub->os_thread;
452 struct scrub_file *sf = &scrub->os_file;
453 __u32 flags = scrub->os_start_flags;
455 bool drop_dryrun = false;
458 CDEBUG(D_LFSCK, "%s: OI scrub prep, flags = 0x%x\n",
459 osd_scrub2name(scrub), flags);
461 down_write(&scrub->os_rwsem);
462 if (flags & SS_SET_FAILOUT)
463 sf->sf_param |= SP_FAILOUT;
464 else if (flags & SS_CLEAR_FAILOUT)
465 sf->sf_param &= ~SP_FAILOUT;
467 if (flags & SS_SET_DRYRUN) {
468 sf->sf_param |= SP_DRYRUN;
469 } else if (flags & SS_CLEAR_DRYRUN && sf->sf_param & SP_DRYRUN) {
470 sf->sf_param &= ~SP_DRYRUN;
474 if (flags & SS_RESET)
475 scrub_file_reset(scrub,
476 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid, 0);
478 if (flags & SS_AUTO_FULL) {
479 scrub->os_full_speed = 1;
480 scrub->os_partial_scan = 0;
481 sf->sf_flags |= SF_AUTO;
482 } else if (flags & SS_AUTO_PARTIAL) {
483 scrub->os_full_speed = 0;
484 scrub->os_partial_scan = 1;
485 sf->sf_flags |= SF_AUTO;
486 } else if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
488 scrub->os_full_speed = 1;
489 scrub->os_partial_scan = 0;
491 scrub->os_full_speed = 0;
492 scrub->os_partial_scan = 0;
495 spin_lock(&scrub->os_lock);
496 scrub->os_in_prior = 0;
497 scrub->os_waiting = 0;
498 scrub->os_paused = 0;
499 scrub->os_in_join = 0;
500 scrub->os_full_scrub = 0;
501 spin_unlock(&scrub->os_lock);
502 scrub->os_new_checked = 0;
503 if (drop_dryrun && sf->sf_pos_first_inconsistent != 0)
504 sf->sf_pos_latest_start = sf->sf_pos_first_inconsistent;
505 else if (sf->sf_pos_last_checkpoint != 0)
506 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
508 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
510 scrub->os_pos_current = sf->sf_pos_latest_start;
511 sf->sf_status = SS_SCANNING;
512 sf->sf_time_latest_start = ktime_get_real_seconds();
513 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
514 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
515 rc = scrub_file_store(env, scrub);
517 spin_lock(&scrub->os_lock);
518 thread_set_flags(thread, SVC_RUNNING);
519 spin_unlock(&scrub->os_lock);
520 wake_up_all(&thread->t_ctl_waitq);
522 up_write(&scrub->os_rwsem);
527 static int osd_scrub_post(const struct lu_env *env, struct osd_device *dev,
530 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
531 struct scrub_file *sf = &scrub->os_file;
535 CDEBUG(D_LFSCK, "%s: OI scrub post with result = %d\n",
536 osd_scrub2name(scrub), result);
538 down_write(&scrub->os_rwsem);
539 spin_lock(&scrub->os_lock);
540 thread_set_flags(&scrub->os_thread, SVC_STOPPING);
541 spin_unlock(&scrub->os_lock);
542 if (scrub->os_new_checked > 0) {
543 sf->sf_items_checked += scrub->os_new_checked;
544 scrub->os_new_checked = 0;
545 sf->sf_pos_last_checkpoint = scrub->os_pos_current;
547 sf->sf_time_last_checkpoint = ktime_get_real_seconds();
549 dev->od_igif_inoi = 1;
550 dev->od_check_ff = 0;
551 sf->sf_status = SS_COMPLETED;
552 if (!(sf->sf_param & SP_DRYRUN)) {
553 memset(sf->sf_oi_bitmap, 0, SCRUB_OI_BITMAP_SIZE);
554 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
555 SF_UPGRADE | SF_AUTO);
557 sf->sf_time_last_complete = sf->sf_time_last_checkpoint;
558 sf->sf_success_count++;
559 } else if (result == 0) {
560 if (scrub->os_paused)
561 sf->sf_status = SS_PAUSED;
563 sf->sf_status = SS_STOPPED;
565 sf->sf_status = SS_FAILED;
567 sf->sf_run_time += ktime_get_seconds() -
568 scrub->os_time_last_checkpoint;
570 rc = scrub_file_store(env, scrub);
571 up_write(&scrub->os_rwsem);
573 RETURN(rc < 0 ? rc : result);
576 /* iteration engine */
578 typedef int (*osd_iit_next_policy)(struct osd_thread_info *info,
579 struct osd_device *dev,
580 struct osd_iit_param *param,
581 struct osd_idmap_cache **oic,
584 typedef int (*osd_iit_exec_policy)(struct osd_thread_info *info,
585 struct osd_device *dev,
586 struct osd_iit_param *param,
587 struct osd_idmap_cache *oic,
588 bool *noslot, int rc);
590 static int osd_iit_next(struct osd_iit_param *param, __u64 *pos)
595 param->offset = ldiskfs_find_next_bit(param->bitmap->b_data,
596 LDISKFS_INODES_PER_GROUP(param->sb), param->offset);
597 if (param->offset >= LDISKFS_INODES_PER_GROUP(param->sb)) {
598 *pos = 1 + (param->bg+1) * LDISKFS_INODES_PER_GROUP(param->sb);
599 return SCRUB_NEXT_BREAK;
602 offset = param->offset++;
603 if (unlikely(*pos == param->gbase + offset && *pos != param->start)) {
604 /* We should NOT find the same object more than once. */
605 CERROR("%s: scan the same object multiple times at the pos: "
606 "group = %u, base = %u, offset = %u, start = %u\n",
607 param->sb->s_id, (__u32)param->bg, param->gbase,
608 offset, param->start);
612 *pos = param->gbase + offset;
617 * \retval SCRUB_NEXT_OSTOBJ_OLD: FID-on-OST
618 * \retval 0: FID-on-MDT
620 static int osd_scrub_check_local_fldb(struct osd_thread_info *info,
621 struct osd_device *dev,
624 /* XXX: The initial OI scrub will scan the top level /O to generate
625 * a small local FLDB according to the <seq>. If the given FID
626 * is in the local FLDB, then it is FID-on-OST; otherwise it's
627 * quite possible for FID-on-MDT. */
629 return SCRUB_NEXT_OSTOBJ_OLD;
634 static int osd_scrub_get_fid(struct osd_thread_info *info,
635 struct osd_device *dev, struct inode *inode,
636 struct lu_fid *fid, bool scrub)
638 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
639 bool has_lma = false;
642 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
643 &info->oti_ost_attrs);
646 if (lma->lma_compat & LMAC_NOT_IN_OI ||
647 lma->lma_incompat & LMAI_AGENT)
648 return SCRUB_NEXT_CONTINUE;
650 *fid = lma->lma_self_fid;
654 if (lma->lma_compat & LMAC_FID_ON_OST)
655 return SCRUB_NEXT_OSTOBJ;
657 if (fid_is_idif(fid))
658 return SCRUB_NEXT_OSTOBJ_OLD;
660 /* For local object. */
661 if (fid_is_internal(fid))
664 /* For external visible MDT-object with non-normal FID. */
665 if (fid_is_namespace_visible(fid) && !fid_is_norm(fid))
668 /* For the object with normal FID, it may be MDT-object,
669 * or may be 2.4 OST-object, need further distinguish.
670 * Fall through to next section. */
673 if (rc == -ENODATA || rc == 0) {
674 rc = osd_get_idif(info, inode, &info->oti_obj_dentry, fid);
677 /* It is 2.3 or older OST-object. */
678 rc = SCRUB_NEXT_OSTOBJ_OLD;
684 /* It is FID-on-OST, but we do not know how
685 * to generate its FID, ignore it directly. */
686 rc = SCRUB_NEXT_CONTINUE;
688 /* It is 2.4 or newer OST-object. */
689 rc = SCRUB_NEXT_OSTOBJ_OLD;
697 if (dev->od_scrub.os_scrub.os_convert_igif) {
698 lu_igif_build(fid, inode->i_ino,
699 inode->i_generation);
701 rc = SCRUB_NEXT_NOLMA;
705 /* It may be FID-on-OST, or may be FID for
706 * non-MDT0, anyway, we do not know how to
707 * generate its FID, ignore it directly. */
708 rc = SCRUB_NEXT_CONTINUE;
713 /* For OI scrub case only: the object has LMA but has no ff
714 * (or ff crashed). It may be MDT-object, may be OST-object
715 * with crashed ff. The last check is local FLDB. */
716 rc = osd_scrub_check_local_fldb(info, dev, fid);
722 static int osd_iit_iget(struct osd_thread_info *info, struct osd_device *dev,
723 struct lu_fid *fid, struct osd_inode_id *lid, __u32 pos,
724 struct super_block *sb, bool scrub)
730 /* Not handle the backend root object and agent parent object.
731 * They are neither visible to namespace nor have OI mappings. */
732 if (unlikely(pos == osd_sb(dev)->s_root->d_inode->i_ino ||
733 is_remote_parent_ino(dev, pos)))
734 RETURN(SCRUB_NEXT_CONTINUE);
736 /* Skip project quota inode since it is greater than s_first_ino. */
737 #ifdef HAVE_PROJECT_QUOTA
738 if (ldiskfs_has_feature_project(sb) &&
739 pos == le32_to_cpu(LDISKFS_SB(sb)->s_es->s_prj_quota_inum))
740 RETURN(SCRUB_NEXT_CONTINUE);
743 osd_id_gen(lid, pos, OSD_OII_NOGEN);
744 inode = osd_iget(info, dev, lid);
747 /* The inode may be removed after bitmap searching, or the
748 * file is new created without inode initialized yet. */
749 if (rc == -ENOENT || rc == -ESTALE)
750 RETURN(SCRUB_NEXT_CONTINUE);
752 CDEBUG(D_LFSCK, "%s: fail to read inode, ino# = %u: "
753 "rc = %d\n", osd_dev2name(dev), pos, rc);
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;
782 struct ptlrpc_thread *thread = &scrub->os_thread;
784 struct osd_inode_id *lid;
787 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0) {
788 struct l_wait_info lwi;
790 lwi = LWI_TIMEOUT(cfs_time_seconds(cfs_fail_val), NULL, NULL);
791 if (likely(lwi.lwi_timeout > 0))
792 l_wait_event(thread->t_ctl_waitq,
793 !list_empty(&scrub->os_inconsistent_items) ||
794 !thread_is_running(thread),
798 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_CRASH)) {
799 spin_lock(&scrub->os_lock);
800 thread_set_flags(thread, SVC_STOPPING);
801 spin_unlock(&scrub->os_lock);
802 return SCRUB_NEXT_CRASH;
805 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_FATAL))
806 return SCRUB_NEXT_FATAL;
808 if (unlikely(!thread_is_running(thread)))
809 return SCRUB_NEXT_EXIT;
811 if (!list_empty(&scrub->os_inconsistent_items)) {
812 spin_lock(&scrub->os_lock);
813 if (likely(!list_empty(&scrub->os_inconsistent_items))) {
814 struct osd_inconsistent_item *oii;
816 oii = list_entry(scrub->os_inconsistent_items.next,
817 struct osd_inconsistent_item, oii_list);
818 spin_unlock(&scrub->os_lock);
820 *oic = &oii->oii_cache;
821 scrub->os_in_prior = 1;
825 spin_unlock(&scrub->os_lock);
829 return SCRUB_NEXT_WAIT;
831 rc = osd_iit_next(param, &scrub->os_pos_current);
835 *oic = &dev->od_scrub.os_oic;
836 fid = &(*oic)->oic_fid;
837 lid = &(*oic)->oic_lid;
838 rc = osd_iit_iget(info, dev, fid, lid,
839 scrub->os_pos_current, param->sb, true);
843 static int osd_preload_next(struct osd_thread_info *info,
844 struct osd_device *dev, struct osd_iit_param *param,
845 struct osd_idmap_cache **oic, const bool noslot)
847 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
848 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
849 struct ptlrpc_thread *thread = &scrub->os_thread;
852 if (thread_is_running(thread) &&
853 ooc->ooc_pos_preload >= scrub->os_pos_current)
854 return SCRUB_NEXT_EXIT;
856 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
860 rc = osd_iit_iget(info, dev,
861 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
862 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
863 ooc->ooc_pos_preload, param->sb, false);
868 osd_scrub_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
870 spin_lock(&scrub->os_lock);
871 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
872 !list_empty(&scrub->os_inconsistent_items) ||
873 it->ooi_waiting || !thread_is_running(&scrub->os_thread))
874 scrub->os_waiting = 0;
876 scrub->os_waiting = 1;
877 spin_unlock(&scrub->os_lock);
879 return !scrub->os_waiting;
882 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
883 struct osd_iit_param *param,
884 struct osd_idmap_cache *oic, bool *noslot, int rc)
886 struct l_wait_info lwi = { 0 };
887 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
888 struct scrub_file *sf = &scrub->os_file;
889 struct ptlrpc_thread *thread = &scrub->os_thread;
890 struct osd_otable_it *it = dev->od_otable_it;
891 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
894 case SCRUB_NEXT_NOSCRUB:
895 down_write(&scrub->os_rwsem);
896 scrub->os_new_checked++;
897 sf->sf_items_noscrub++;
898 up_write(&scrub->os_rwsem);
899 case SCRUB_NEXT_CONTINUE:
900 case SCRUB_NEXT_WAIT:
904 rc = osd_scrub_check_update(info, dev, oic, rc);
906 scrub->os_in_prior = 0;
910 rc = scrub_checkpoint(info->oti_env, scrub);
912 CDEBUG(D_LFSCK, "%s: fail to checkpoint, pos = %llu: "
913 "rc = %d\n", osd_scrub2name(scrub),
914 scrub->os_pos_current, rc);
915 /* Continue, as long as the scrub itself can go ahead. */
918 if (scrub->os_in_prior) {
919 scrub->os_in_prior = 0;
924 if (it != NULL && it->ooi_waiting && ooc != NULL &&
925 ooc->ooc_pos_preload < scrub->os_pos_current) {
926 spin_lock(&scrub->os_lock);
928 wake_up_all(&thread->t_ctl_waitq);
929 spin_unlock(&scrub->os_lock);
932 if (rc == SCRUB_NEXT_CONTINUE)
935 if (scrub->os_full_speed || !ooc || osd_scrub_has_window(scrub, ooc)) {
941 l_wait_event(thread->t_ctl_waitq, osd_scrub_wakeup(scrub, it),
944 if (!ooc || osd_scrub_has_window(scrub, ooc))
951 static int osd_preload_exec(struct osd_thread_info *info,
952 struct osd_device *dev, struct osd_iit_param *param,
953 struct osd_idmap_cache *oic, bool *noslot, int rc)
955 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
958 ooc->ooc_cached_items++;
959 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
960 ~OSD_OTABLE_IT_CACHE_MASK;
962 return rc > 0 ? 0 : rc;
965 #define SCRUB_IT_ALL 1
966 #define SCRUB_IT_CRASH 2
968 static void osd_scrub_join(const struct lu_env *env, struct osd_device *dev,
969 __u32 flags, bool inconsistent)
971 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
972 struct ptlrpc_thread *thread = &scrub->os_thread;
973 struct scrub_file *sf = &scrub->os_file;
977 LASSERT(!(flags & SS_AUTO_PARTIAL));
979 down_write(&scrub->os_rwsem);
980 scrub->os_in_join = 1;
981 if (flags & SS_SET_FAILOUT)
982 sf->sf_param |= SP_FAILOUT;
983 else if (flags & SS_CLEAR_FAILOUT)
984 sf->sf_param &= ~SP_FAILOUT;
986 if (flags & SS_SET_DRYRUN)
987 sf->sf_param |= SP_DRYRUN;
988 else if (flags & SS_CLEAR_DRYRUN)
989 sf->sf_param &= ~SP_DRYRUN;
991 if (flags & SS_RESET) {
992 scrub_file_reset(scrub, LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
993 inconsistent ? SF_INCONSISTENT : 0);
994 sf->sf_status = SS_SCANNING;
997 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
998 scrub->os_full_speed = 1;
1000 scrub->os_full_speed = 0;
1002 if (flags & SS_AUTO_FULL) {
1003 sf->sf_flags |= SF_AUTO;
1004 scrub->os_full_speed = 1;
1007 scrub->os_new_checked = 0;
1008 if (sf->sf_pos_last_checkpoint != 0)
1009 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
1011 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
1013 scrub->os_pos_current = sf->sf_pos_latest_start;
1014 sf->sf_time_latest_start = ktime_get_real_seconds();
1015 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
1016 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
1017 rc = scrub_file_store(env, scrub);
1019 spin_lock(&scrub->os_lock);
1020 scrub->os_waiting = 0;
1021 scrub->os_paused = 0;
1022 scrub->os_partial_scan = 0;
1023 scrub->os_in_join = 0;
1024 scrub->os_full_scrub = 0;
1025 spin_unlock(&scrub->os_lock);
1026 wake_up_all(&thread->t_ctl_waitq);
1027 up_write(&scrub->os_rwsem);
1029 CDEBUG(D_LFSCK, "%s: joined in the OI scrub with flag %u: rc = %d\n",
1030 osd_scrub2name(scrub), flags, rc);
1035 static int osd_inode_iteration(struct osd_thread_info *info,
1036 struct osd_device *dev, __u32 max, bool preload)
1038 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1039 struct ptlrpc_thread *thread = &scrub->os_thread;
1040 struct scrub_file *sf = &scrub->os_file;
1041 osd_iit_next_policy next;
1042 osd_iit_exec_policy exec;
1045 struct osd_iit_param *param;
1046 struct l_wait_info lwi = { 0 };
1055 param = &dev->od_scrub.os_iit_param;
1056 memset(param, 0, sizeof(*param));
1057 param->sb = osd_sb(dev);
1059 while (scrub->os_partial_scan && !scrub->os_in_join) {
1060 struct osd_idmap_cache *oic = NULL;
1062 rc = osd_scrub_next(info, dev, param, &oic, noslot);
1064 case SCRUB_NEXT_EXIT:
1066 case SCRUB_NEXT_CRASH:
1067 RETURN(SCRUB_IT_CRASH);
1068 case SCRUB_NEXT_FATAL:
1070 case SCRUB_NEXT_WAIT: {
1071 struct kstatfs *ksfs = &info->oti_ksfs;
1074 if (dev->od_full_scrub_ratio == OFSR_NEVER ||
1075 unlikely(sf->sf_items_updated_prior == 0))
1078 if (dev->od_full_scrub_ratio == OFSR_DIRECTLY ||
1079 scrub->os_full_scrub) {
1080 osd_scrub_join(info->oti_env, dev,
1081 SS_AUTO_FULL | SS_RESET, true);
1085 rc = param->sb->s_op->statfs(param->sb->s_root, ksfs);
1087 __u64 used = ksfs->f_files - ksfs->f_ffree;
1089 do_div(used, sf->sf_items_updated_prior);
1090 /* If we hit too much inconsistent OI
1091 * mappings during the partial scan,
1092 * then scan the device completely. */
1093 if (used < dev->od_full_scrub_ratio) {
1094 osd_scrub_join(info->oti_env, dev,
1095 SS_AUTO_FULL | SS_RESET, true);
1101 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) &&
1105 saved_flags = sf->sf_flags;
1106 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
1107 SF_UPGRADE | SF_AUTO);
1108 sf->sf_status = SS_COMPLETED;
1109 l_wait_event(thread->t_ctl_waitq,
1110 !thread_is_running(thread) ||
1111 !scrub->os_partial_scan ||
1112 scrub->os_in_join ||
1113 !list_empty(&scrub->os_inconsistent_items),
1115 sf->sf_flags = saved_flags;
1116 sf->sf_status = SS_SCANNING;
1118 if (unlikely(!thread_is_running(thread)))
1121 if (!scrub->os_partial_scan || scrub->os_in_join)
1127 LASSERTF(rc == 0, "rc = %d\n", rc);
1129 osd_scrub_exec(info, dev, param, oic, &noslot, rc);
1136 l_wait_event(thread->t_ctl_waitq,
1137 !thread_is_running(thread) || !scrub->os_in_join,
1140 if (unlikely(!thread_is_running(thread)))
1146 next = osd_scrub_next;
1147 exec = osd_scrub_exec;
1148 pos = &scrub->os_pos_current;
1149 count = &scrub->os_new_checked;
1150 param->start = *pos;
1151 param->bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param->sb);
1153 (*pos - 1) % LDISKFS_INODES_PER_GROUP(param->sb);
1155 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1157 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1159 next = osd_preload_next;
1160 exec = osd_preload_exec;
1161 pos = &ooc->ooc_pos_preload;
1162 count = &ooc->ooc_cached_items;
1163 param = &dev->od_otable_it->ooi_iit_param;
1167 limit = le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count);
1168 while (*pos <= limit && *count < max) {
1169 struct ldiskfs_group_desc *desc;
1170 bool next_group = false;
1172 desc = ldiskfs_get_group_desc(param->sb, param->bg, NULL);
1176 if (desc->bg_flags & cpu_to_le16(LDISKFS_BG_INODE_UNINIT)) {
1181 param->bitmap = ldiskfs_read_inode_bitmap(param->sb, param->bg);
1182 if (!param->bitmap) {
1183 CERROR("%s: fail to read bitmap for %u, "
1184 "scrub will stop, urgent mode\n",
1185 osd_scrub2name(scrub), (__u32)param->bg);
1190 struct osd_idmap_cache *oic = NULL;
1193 ldiskfs_itable_unused_count(param->sb, desc) >=
1194 LDISKFS_INODES_PER_GROUP(param->sb)) {
1199 rc = next(info, dev, param, &oic, noslot);
1201 case SCRUB_NEXT_BREAK:
1204 case SCRUB_NEXT_EXIT:
1205 brelse(param->bitmap);
1207 case SCRUB_NEXT_CRASH:
1208 brelse(param->bitmap);
1209 RETURN(SCRUB_IT_CRASH);
1210 case SCRUB_NEXT_FATAL:
1211 brelse(param->bitmap);
1215 rc = exec(info, dev, param, oic, &noslot, rc);
1216 } while (!rc && *pos <= limit && *count < max);
1219 if (param->bitmap) {
1220 brelse(param->bitmap);
1221 param->bitmap = NULL;
1231 param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1232 *pos = param->gbase;
1233 param->start = *pos;
1238 RETURN(SCRUB_IT_ALL);
1244 static int osd_otable_it_preload(const struct lu_env *env,
1245 struct osd_otable_it *it)
1247 struct osd_device *dev = it->ooi_dev;
1248 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1249 struct osd_otable_cache *ooc = &it->ooi_cache;
1253 rc = osd_inode_iteration(osd_oti_get(env), dev,
1254 OSD_OTABLE_IT_CACHE_SIZE, true);
1255 if (rc == SCRUB_IT_ALL)
1256 it->ooi_all_cached = 1;
1258 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1259 spin_lock(&scrub->os_lock);
1260 scrub->os_waiting = 0;
1261 wake_up_all(&scrub->os_thread.t_ctl_waitq);
1262 spin_unlock(&scrub->os_lock);
1265 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1268 static int osd_scrub_main(void *args)
1271 struct osd_device *dev = (struct osd_device *)args;
1272 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1273 struct ptlrpc_thread *thread = &scrub->os_thread;
1277 rc = lu_env_init(&env, LCT_LOCAL | LCT_DT_THREAD);
1279 CDEBUG(D_LFSCK, "%s: OI scrub fail to init env: rc = %d\n",
1280 osd_scrub2name(scrub), rc);
1284 rc = osd_scrub_prep(&env, dev);
1286 CDEBUG(D_LFSCK, "%s: OI scrub fail to scrub prep: rc = %d\n",
1287 osd_scrub2name(scrub), rc);
1291 if (!scrub->os_full_speed && !scrub->os_partial_scan) {
1292 struct l_wait_info lwi = { 0 };
1293 struct osd_otable_it *it = dev->od_otable_it;
1294 struct osd_otable_cache *ooc = &it->ooi_cache;
1296 l_wait_event(thread->t_ctl_waitq,
1297 it->ooi_user_ready || !thread_is_running(thread),
1299 if (unlikely(!thread_is_running(thread)))
1302 scrub->os_pos_current = ooc->ooc_pos_preload;
1305 CDEBUG(D_LFSCK, "%s: OI scrub start, flags = 0x%x, pos = %llu\n",
1306 osd_scrub2name(scrub), scrub->os_start_flags,
1307 scrub->os_pos_current);
1309 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1310 if (unlikely(rc == SCRUB_IT_CRASH)) {
1311 spin_lock(&scrub->os_lock);
1312 thread_set_flags(&scrub->os_thread, SVC_STOPPING);
1313 spin_unlock(&scrub->os_lock);
1314 GOTO(out, rc = -EINVAL);
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);
1336 spin_lock(&scrub->os_lock);
1337 thread_set_flags(thread, SVC_STOPPED);
1338 wake_up_all(&thread->t_ctl_waitq);
1339 spin_unlock(&scrub->os_lock);
1343 /* initial OI scrub */
1345 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1346 struct dentry *, filldir_t filldir);
1348 #ifdef HAVE_FILLDIR_USE_CTX
1349 static int osd_ios_varfid_fill(struct dir_context *buf, const char *name,
1350 int namelen, loff_t offset, __u64 ino,
1352 static int osd_ios_lf_fill(struct dir_context *buf, const char *name,
1353 int namelen, loff_t offset, __u64 ino,
1355 static int osd_ios_dl_fill(struct dir_context *buf, const char *name,
1356 int namelen, loff_t offset, __u64 ino,
1358 static int osd_ios_uld_fill(struct dir_context *buf, const char *name,
1359 int namelen, loff_t offset, __u64 ino,
1362 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1363 loff_t offset, __u64 ino, unsigned d_type);
1364 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1365 loff_t offset, __u64 ino, unsigned d_type);
1366 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1367 loff_t offset, __u64 ino, unsigned d_type);
1368 static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
1369 loff_t offset, __u64 ino, unsigned d_type);
1373 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1374 struct dentry *dentry, filldir_t filldir);
1376 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1377 struct dentry *dentry, filldir_t filldir);
1380 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1381 struct dentry *dentry, filldir_t filldir);
1385 struct lu_fid olm_fid;
1388 scandir_t olm_scandir;
1389 filldir_t olm_filldir;
1392 /* Add the new introduced local files in the list in the future. */
1393 static const struct osd_lf_map osd_lf_maps[] = {
1396 .olm_name = CATLIST,
1398 .f_seq = FID_SEQ_LOCAL_FILE,
1399 .f_oid = LLOG_CATALOGS_OID,
1401 .olm_flags = OLF_SHOW_NAME,
1402 .olm_namelen = sizeof(CATLIST) - 1,
1407 .olm_name = MOUNT_CONFIGS_DIR,
1409 .f_seq = FID_SEQ_LOCAL_FILE,
1410 .f_oid = MGS_CONFIGS_OID,
1412 .olm_flags = OLF_SCAN_SUBITEMS,
1413 .olm_namelen = sizeof(MOUNT_CONFIGS_DIR) - 1,
1414 .olm_scandir = osd_ios_general_scan,
1415 .olm_filldir = osd_ios_varfid_fill,
1418 /* NIDTBL_VERSIONS */
1420 .olm_name = MGS_NIDTBL_DIR,
1421 .olm_flags = OLF_SCAN_SUBITEMS,
1422 .olm_namelen = sizeof(MGS_NIDTBL_DIR) - 1,
1423 .olm_scandir = osd_ios_general_scan,
1424 .olm_filldir = osd_ios_varfid_fill,
1429 .olm_name = MDT_ORPHAN_DIR,
1430 .olm_namelen = sizeof(MDT_ORPHAN_DIR) - 1,
1437 .f_seq = FID_SEQ_ROOT,
1438 .f_oid = FID_OID_ROOT,
1440 .olm_flags = OLF_SCAN_SUBITEMS | OLF_HIDE_FID,
1441 .olm_namelen = sizeof("ROOT") - 1,
1442 .olm_scandir = osd_ios_ROOT_scan,
1445 /* changelog_catalog */
1447 .olm_name = CHANGELOG_CATALOG,
1448 .olm_namelen = sizeof(CHANGELOG_CATALOG) - 1,
1451 /* changelog_users */
1453 .olm_name = CHANGELOG_USERS,
1454 .olm_namelen = sizeof(CHANGELOG_USERS) - 1,
1461 .f_seq = FID_SEQ_LOCAL_FILE,
1462 .f_oid = FLD_INDEX_OID,
1464 .olm_flags = OLF_SHOW_NAME,
1465 .olm_namelen = sizeof("fld") - 1,
1470 .olm_name = LAST_RCVD,
1472 .f_seq = FID_SEQ_LOCAL_FILE,
1473 .f_oid = LAST_RECV_OID,
1475 .olm_flags = OLF_SHOW_NAME,
1476 .olm_namelen = sizeof(LAST_RCVD) - 1,
1481 .olm_name = REPLY_DATA,
1483 .f_seq = FID_SEQ_LOCAL_FILE,
1484 .f_oid = REPLY_DATA_OID,
1486 .olm_flags = OLF_SHOW_NAME,
1487 .olm_namelen = sizeof(REPLY_DATA) - 1,
1492 .olm_name = LOV_OBJID,
1494 .f_seq = FID_SEQ_LOCAL_FILE,
1495 .f_oid = MDD_LOV_OBJ_OID,
1497 .olm_flags = OLF_SHOW_NAME,
1498 .olm_namelen = sizeof(LOV_OBJID) - 1,
1503 .olm_name = LOV_OBJSEQ,
1505 .f_seq = FID_SEQ_LOCAL_FILE,
1506 .f_oid = MDD_LOV_OBJ_OSEQ,
1508 .olm_flags = OLF_SHOW_NAME,
1509 .olm_namelen = sizeof(LOV_OBJSEQ) - 1,
1514 .olm_name = QMT_DIR,
1515 .olm_flags = OLF_SCAN_SUBITEMS,
1516 .olm_namelen = sizeof(QMT_DIR) - 1,
1517 .olm_scandir = osd_ios_general_scan,
1518 .olm_filldir = osd_ios_varfid_fill,
1523 .olm_name = QSD_DIR,
1524 .olm_flags = OLF_SCAN_SUBITEMS,
1525 .olm_namelen = sizeof(QSD_DIR) - 1,
1526 .olm_scandir = osd_ios_general_scan,
1527 .olm_filldir = osd_ios_varfid_fill,
1532 .olm_name = "seq_ctl",
1534 .f_seq = FID_SEQ_LOCAL_FILE,
1535 .f_oid = FID_SEQ_CTL_OID,
1537 .olm_flags = OLF_SHOW_NAME,
1538 .olm_namelen = sizeof("seq_ctl") - 1,
1543 .olm_name = "seq_srv",
1545 .f_seq = FID_SEQ_LOCAL_FILE,
1546 .f_oid = FID_SEQ_SRV_OID,
1548 .olm_flags = OLF_SHOW_NAME,
1549 .olm_namelen = sizeof("seq_srv") - 1,
1554 .olm_name = HEALTH_CHECK,
1556 .f_seq = FID_SEQ_LOCAL_FILE,
1557 .f_oid = OFD_HEALTH_CHECK_OID,
1559 .olm_flags = OLF_SHOW_NAME,
1560 .olm_namelen = sizeof(HEALTH_CHECK) - 1,
1565 .olm_name = LFSCK_DIR,
1566 .olm_flags = OLF_SCAN_SUBITEMS,
1567 .olm_namelen = sizeof(LFSCK_DIR) - 1,
1568 .olm_scandir = osd_ios_general_scan,
1569 .olm_filldir = osd_ios_varfid_fill,
1572 /* lfsck_bookmark */
1574 .olm_name = LFSCK_BOOKMARK,
1575 .olm_namelen = sizeof(LFSCK_BOOKMARK) - 1,
1580 .olm_name = LFSCK_LAYOUT,
1581 .olm_namelen = sizeof(LFSCK_LAYOUT) - 1,
1584 /* lfsck_namespace */
1586 .olm_name = LFSCK_NAMESPACE,
1587 .olm_namelen = sizeof(LFSCK_NAMESPACE) - 1,
1590 /* OBJECTS, upgrade from old device */
1592 .olm_name = OBJECTS,
1593 .olm_flags = OLF_SCAN_SUBITEMS,
1594 .olm_namelen = sizeof(OBJECTS) - 1,
1595 .olm_scandir = osd_ios_OBJECTS_scan,
1598 /* lquota_v2.user, upgrade from old device */
1600 .olm_name = "lquota_v2.user",
1601 .olm_namelen = sizeof("lquota_v2.user") - 1,
1604 /* lquota_v2.group, upgrade from old device */
1606 .olm_name = "lquota_v2.group",
1607 .olm_namelen = sizeof("lquota_v2.group") - 1,
1610 /* LAST_GROUP, upgrade from old device */
1612 .olm_name = "LAST_GROUP",
1614 .f_seq = FID_SEQ_LOCAL_FILE,
1615 .f_oid = OFD_LAST_GROUP_OID,
1617 .olm_flags = OLF_SHOW_NAME,
1618 .olm_namelen = sizeof("LAST_GROUP") - 1,
1621 /* committed batchid for cross-MDT operation */
1623 .olm_name = "BATCHID",
1625 .f_seq = FID_SEQ_LOCAL_FILE,
1626 .f_oid = BATCHID_COMMITTED_OID,
1628 .olm_flags = OLF_SHOW_NAME,
1629 .olm_namelen = sizeof("BATCHID") - 1,
1632 /* OSP update logs update_log{_dir} use f_seq = FID_SEQ_UPDATE_LOG{_DIR}
1633 * and f_oid = index for their log files. See lu_update_log{_dir}_fid()
1634 * for more details. */
1638 .olm_name = "update_log",
1640 .f_seq = FID_SEQ_UPDATE_LOG,
1642 .olm_flags = OLF_SHOW_NAME | OLF_IDX_IN_FID,
1643 .olm_namelen = sizeof("update_log") - 1,
1646 /* update_log_dir */
1648 .olm_name = "update_log_dir",
1650 .f_seq = FID_SEQ_UPDATE_LOG_DIR,
1652 .olm_flags = OLF_SHOW_NAME | OLF_SCAN_SUBITEMS |
1654 .olm_namelen = sizeof("update_log_dir") - 1,
1655 .olm_scandir = osd_ios_general_scan,
1656 .olm_filldir = osd_ios_uld_fill,
1661 .olm_name = "lost+found",
1663 .f_seq = FID_SEQ_LOCAL_FILE,
1664 .f_oid = OSD_LPF_OID,
1666 .olm_flags = OLF_SCAN_SUBITEMS,
1667 .olm_namelen = sizeof("lost+found") - 1,
1668 .olm_scandir = osd_ios_general_scan,
1669 .olm_filldir = osd_ios_lf_fill,
1674 .olm_name = HSM_ACTIONS,
1679 .olm_name = LUSTRE_NODEMAP_NAME,
1684 .olm_name = INDEX_BACKUP_DIR,
1686 .f_seq = FID_SEQ_LOCAL_FILE,
1687 .f_oid = INDEX_BACKUP_OID,
1689 .olm_flags = OLF_SCAN_SUBITEMS | OLF_NOT_BACKUP,
1690 .olm_namelen = sizeof(INDEX_BACKUP_DIR) - 1,
1691 .olm_scandir = osd_ios_general_scan,
1692 .olm_filldir = osd_ios_varfid_fill,
1700 /* Add the new introduced files under .lustre/ in the list in the future. */
1701 static const struct osd_lf_map osd_dl_maps[] = {
1706 .f_seq = FID_SEQ_DOT_LUSTRE,
1707 .f_oid = FID_OID_DOT_LUSTRE_OBF,
1709 .olm_namelen = sizeof("fid") - 1,
1712 /* .lustre/lost+found */
1714 .olm_name = "lost+found",
1716 .f_seq = FID_SEQ_DOT_LUSTRE,
1717 .f_oid = FID_OID_DOT_LUSTRE_LPF,
1719 .olm_namelen = sizeof("lost+found") - 1,
1727 struct osd_ios_item {
1728 struct list_head oii_list;
1729 struct dentry *oii_dentry;
1730 scandir_t oii_scandir;
1731 filldir_t oii_filldir;
1734 struct osd_ios_filldir_buf {
1735 #ifdef HAVE_DIR_CONTEXT
1736 /* please keep it as first member */
1737 struct dir_context ctx;
1739 struct osd_thread_info *oifb_info;
1740 struct osd_device *oifb_dev;
1741 struct dentry *oifb_dentry;
1745 static inline struct dentry *
1746 osd_ios_lookup_one_len(const char *name, struct dentry *parent, int namelen)
1748 struct dentry *dentry;
1750 dentry = ll_lookup_one_len(name, parent, namelen);
1751 if (IS_ERR(dentry)) {
1752 int rc = PTR_ERR(dentry);
1755 CERROR("Fail to find %.*s in %.*s (%lu/%u): rc = %d\n",
1756 namelen, name, parent->d_name.len,
1757 parent->d_name.name, parent->d_inode->i_ino,
1758 parent->d_inode->i_generation, rc);
1763 if (dentry->d_inode == NULL) {
1765 return ERR_PTR(-ENOENT);
1772 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1773 scandir_t scandir, filldir_t filldir)
1775 struct osd_ios_item *item;
1778 OBD_ALLOC_PTR(item);
1782 INIT_LIST_HEAD(&item->oii_list);
1783 item->oii_dentry = dget(dentry);
1784 item->oii_scandir = scandir;
1785 item->oii_filldir = filldir;
1786 list_add_tail(&item->oii_list, &dev->od_ios_list);
1791 static bool osd_index_need_recreate(const struct lu_env *env,
1792 struct osd_device *dev, struct inode *inode)
1794 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1795 struct iam_container *bag = &iam->od_container;
1799 rc = iam_container_init(bag, &iam->od_descr, inode);
1803 rc = iam_container_setup(bag);
1804 iam_container_fini(bag);
1811 static void osd_ios_index_register(const struct lu_env *env,
1812 struct osd_device *osd,
1813 const struct lu_fid *fid,
1814 struct inode *inode)
1816 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1817 struct iam_container *bag = &iam->od_container;
1818 struct super_block *sb = osd_sb(osd);
1819 struct iam_descr *descr;
1825 /* Index must be a regular file. */
1826 if (!S_ISREG(inode->i_mode))
1829 /* Index's size must be block aligned. */
1830 if (inode->i_size < sb->s_blocksize ||
1831 (inode->i_size & (sb->s_blocksize - 1)) != 0)
1834 iam_container_init(bag, &iam->od_descr, inode);
1835 rc = iam_container_setup(bag);
1839 descr = bag->ic_descr;
1840 /* May be regular file with IAM_LFIX_ROOT_MAGIC matched
1841 * coincidentally, or corrupted index object, skip it. */
1842 if (descr->id_ptr_size != 4)
1845 keysize = descr->id_key_size;
1846 recsize = descr->id_rec_size;
1847 rc = osd_index_register(osd, fid, keysize, recsize);
1852 iam_container_fini(bag);
1854 CDEBUG(D_LFSCK, "%s: index object "DFID" (%u/%u) registered\n",
1855 osd_name(osd), PFID(fid), keysize, recsize);
1858 static void osd_index_restore(const struct lu_env *env, struct osd_device *dev,
1859 struct lustre_index_restore_unit *liru,
1860 void *buf, int bufsize)
1862 struct osd_thread_info *info = osd_oti_get(env);
1863 struct osd_inode_id *id = &info->oti_id;
1864 struct lu_fid *tgt_fid = &liru->liru_cfid;
1865 struct inode *bak_inode = NULL;
1866 struct ldiskfs_dir_entry_2 *de = NULL;
1867 struct buffer_head *bh = NULL;
1868 struct dentry *dentry;
1870 struct lu_fid bak_fid;
1874 lustre_fid2lbx(name, tgt_fid, bufsize);
1875 dentry = osd_child_dentry_by_inode(env, dev->od_index_backup_inode,
1876 name, strlen(name));
1877 bh = osd_ldiskfs_find_entry(dev->od_index_backup_inode,
1878 &dentry->d_name, &de, NULL, NULL);
1880 GOTO(log, rc = PTR_ERR(bh));
1882 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
1884 bak_inode = osd_iget_fid(info, dev, id, &bak_fid);
1885 if (IS_ERR(bak_inode))
1886 GOTO(log, rc = PTR_ERR(bak_inode));
1889 /* The OI mapping for index may be invalid, since it will be
1890 * re-created, not update the OI mapping, just cache it in RAM. */
1891 osd_id_gen(id, liru->liru_clid, OSD_OII_NOGEN);
1892 osd_add_oi_cache(info, dev, id, tgt_fid);
1893 rc = lustre_index_restore(env, &dev->od_dt_dev, &liru->liru_pfid,
1894 tgt_fid, &bak_fid, liru->liru_name,
1895 &dev->od_index_backup_list, &dev->od_lock,
1900 CDEBUG(D_WARNING, "%s: restore index '%s' with "DFID": rc = %d\n",
1901 osd_name(dev), liru->liru_name, PFID(tgt_fid), rc);
1905 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1907 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1908 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1909 * reference the inode, or fixed if it is missing or references another inode.
1912 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1913 struct inode *parent, struct inode *inode,
1914 const struct lu_fid *fid, const char *name,
1915 int namelen, int flags)
1917 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1918 struct osd_inode_id *id = &info->oti_id;
1919 struct osd_inode_id *id2 = &info->oti_id2;
1920 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1921 struct scrub_file *sf = &scrub->os_file;
1926 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
1927 &info->oti_ost_attrs);
1928 if (rc != 0 && rc != -ENODATA) {
1929 CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
1930 "rc = %d\n", osd_name(dev), rc);
1935 osd_id_gen(id, inode->i_ino, inode->i_generation);
1936 if (rc == -ENODATA) {
1937 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID) {
1938 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1941 if (flags & OLF_IDX_IN_FID) {
1942 LASSERT(dev->od_index >= 0);
1944 tfid.f_oid = dev->od_index;
1947 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1949 CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
1950 "scrub: rc = %d\n", osd_name(dev), rc);
1955 if (lma->lma_compat & LMAC_NOT_IN_OI)
1958 tfid = lma->lma_self_fid;
1959 if (lma->lma_compat & LMAC_IDX_BACKUP &&
1960 osd_index_need_recreate(info->oti_env, dev, inode)) {
1961 struct lu_fid *pfid = &info->oti_fid3;
1963 if (parent == osd_sb(dev)->s_root->d_inode) {
1964 lu_local_obj_fid(pfid, OSD_FS_ROOT_OID);
1966 rc = osd_scrub_get_fid(info, dev, parent, pfid,
1972 rc = lustre_liru_new(&dev->od_index_restore_list, pfid,
1973 &tfid, inode->i_ino, name, namelen);
1978 if (!(flags & OLF_NOT_BACKUP))
1979 osd_ios_index_register(info->oti_env, dev, &tfid,
1983 rc = osd_oi_lookup(info, dev, &tfid, id2, 0);
1988 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1989 DTO_INDEX_INSERT, true, 0, NULL);
1996 if (osd_id_eq_strict(id, id2))
1999 if (!(sf->sf_flags & SF_INCONSISTENT)) {
2000 scrub_file_reset(scrub, LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
2002 rc = scrub_file_store(info->oti_env, scrub);
2007 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
2008 DTO_INDEX_UPDATE, true, 0, NULL);
2016 * It scans the /lost+found, and for the OST-object (with filter_fid
2017 * or filter_fid_18_23), move them back to its proper /O/<seq>/d<x>.
2019 #ifdef HAVE_FILLDIR_USE_CTX
2020 static int osd_ios_lf_fill(struct dir_context *buf,
2022 static int osd_ios_lf_fill(void *buf,
2024 const char *name, int namelen,
2025 loff_t offset, __u64 ino, unsigned d_type)
2027 struct osd_ios_filldir_buf *fill_buf =
2028 (struct osd_ios_filldir_buf *)buf;
2029 struct osd_thread_info *info = fill_buf->oifb_info;
2030 struct osd_device *dev = fill_buf->oifb_dev;
2031 struct lu_fid *fid = &info->oti_fid;
2032 struct osd_scrub *scrub = &dev->od_scrub;
2033 struct dentry *parent = fill_buf->oifb_dentry;
2034 struct dentry *child;
2035 struct inode *dir = parent->d_inode;
2036 struct inode *inode;
2040 fill_buf->oifb_items++;
2042 /* skip any '.' started names */
2046 scrub->os_lf_scanned++;
2047 child = osd_ios_lookup_one_len(name, parent, namelen);
2048 if (IS_ERR(child)) {
2049 CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
2050 osd_name(dev), namelen, name, (int)PTR_ERR(child));
2054 inode = child->d_inode;
2055 if (S_ISDIR(inode->i_mode)) {
2056 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2059 CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
2060 "rc = %d\n", osd_name(dev), namelen, name, rc);
2064 if (!S_ISREG(inode->i_mode))
2067 rc = osd_scrub_get_fid(info, dev, inode, fid, true);
2068 if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
2069 rc = osd_obj_map_recover(info, dev, dir, child, fid);
2071 CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
2072 "/lost+found.\n", namelen, name, PFID(fid));
2073 scrub->os_lf_repaired++;
2075 CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
2077 osd_name(dev), namelen, name, PFID(fid), rc);
2081 /* XXX: For MDT-objects, we can move them from /lost+found to namespace
2082 * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
2083 * can process them in furtuer. */
2089 scrub->os_lf_failed++;
2091 /* skip the failure to make the scanning to continue. */
2095 #ifdef HAVE_FILLDIR_USE_CTX
2096 static int osd_ios_varfid_fill(struct dir_context *buf,
2098 static int osd_ios_varfid_fill(void *buf,
2100 const char *name, int namelen,
2101 loff_t offset, __u64 ino, unsigned d_type)
2103 struct osd_ios_filldir_buf *fill_buf =
2104 (struct osd_ios_filldir_buf *)buf;
2105 struct osd_device *dev = fill_buf->oifb_dev;
2106 struct dentry *child;
2110 fill_buf->oifb_items++;
2112 /* skip any '.' started names */
2116 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
2118 RETURN(PTR_ERR(child));
2120 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2121 fill_buf->oifb_dentry->d_inode, child->d_inode,
2122 NULL, name, namelen, 0);
2123 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
2124 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2125 osd_ios_varfid_fill);
2131 #ifdef HAVE_FILLDIR_USE_CTX
2132 static int osd_ios_dl_fill(struct dir_context *buf,
2134 static int osd_ios_dl_fill(void *buf,
2136 const char *name, int namelen,
2137 loff_t offset, __u64 ino, unsigned d_type)
2139 struct osd_ios_filldir_buf *fill_buf =
2140 (struct osd_ios_filldir_buf *)buf;
2141 struct osd_device *dev = fill_buf->oifb_dev;
2142 const struct osd_lf_map *map;
2143 struct dentry *child;
2147 fill_buf->oifb_items++;
2149 /* skip any '.' started names */
2153 for (map = osd_dl_maps; map->olm_name != NULL; map++) {
2154 if (map->olm_namelen != namelen)
2157 if (strncmp(map->olm_name, name, namelen) == 0)
2161 if (map->olm_name == NULL)
2164 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
2166 RETURN(PTR_ERR(child));
2168 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2169 fill_buf->oifb_dentry->d_inode, child->d_inode,
2170 &map->olm_fid, name, namelen, map->olm_flags);
2176 #ifdef HAVE_FILLDIR_USE_CTX
2177 static int osd_ios_uld_fill(struct dir_context *buf,
2179 static int osd_ios_uld_fill(void *buf,
2181 const char *name, int namelen,
2182 loff_t offset, __u64 ino, unsigned d_type)
2184 struct osd_ios_filldir_buf *fill_buf =
2185 (struct osd_ios_filldir_buf *)buf;
2186 struct dentry *child;
2191 fill_buf->oifb_items++;
2193 /* skip any non-DFID format name */
2197 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
2199 RETURN(PTR_ERR(child));
2201 /* skip the start '[' */
2202 sscanf(&name[1], SFID, RFID(&tfid));
2203 if (fid_is_sane(&tfid))
2204 rc = osd_ios_scan_one(fill_buf->oifb_info, fill_buf->oifb_dev,
2205 fill_buf->oifb_dentry->d_inode,
2206 child->d_inode, &tfid, name, namelen, 0);
2214 #ifdef HAVE_FILLDIR_USE_CTX
2215 static int osd_ios_root_fill(struct dir_context *buf,
2217 static int osd_ios_root_fill(void *buf,
2219 const char *name, int namelen,
2220 loff_t offset, __u64 ino, unsigned d_type)
2222 struct osd_ios_filldir_buf *fill_buf =
2223 (struct osd_ios_filldir_buf *)buf;
2224 struct osd_device *dev = fill_buf->oifb_dev;
2225 const struct osd_lf_map *map;
2226 struct dentry *child;
2230 fill_buf->oifb_items++;
2232 /* skip any '.' started names */
2236 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
2237 if (map->olm_namelen != namelen)
2240 if (strncmp(map->olm_name, name, namelen) == 0)
2244 if (map->olm_name == NULL)
2247 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
2249 RETURN(PTR_ERR(child));
2251 if (!(map->olm_flags & OLF_NO_OI))
2252 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2253 fill_buf->oifb_dentry->d_inode, child->d_inode,
2254 &map->olm_fid, name, namelen, map->olm_flags);
2255 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
2256 rc = osd_ios_new_item(dev, child, map->olm_scandir,
2264 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
2265 struct dentry *dentry, filldir_t filldir)
2267 struct osd_ios_filldir_buf buf = {
2268 #ifdef HAVE_DIR_CONTEXT
2269 .ctx.actor = filldir,
2273 .oifb_dentry = dentry };
2274 struct file *filp = &info->oti_file;
2275 struct inode *inode = dentry->d_inode;
2276 const struct file_operations *fops = inode->i_fop;
2280 LASSERT(filldir != NULL);
2283 filp->f_path.dentry = dentry;
2284 filp->f_mode = FMODE_64BITHASH;
2285 filp->f_mapping = inode->i_mapping;
2287 filp->private_data = NULL;
2288 set_file_inode(filp, inode);
2292 #ifdef HAVE_DIR_CONTEXT
2293 buf.ctx.pos = filp->f_pos;
2294 #ifdef HAVE_ITERATE_SHARED
2295 rc = fops->iterate_shared(filp, &buf.ctx);
2297 rc = fops->iterate(filp, &buf.ctx);
2299 filp->f_pos = buf.ctx.pos;
2301 rc = fops->readdir(filp, &buf, filldir);
2303 } while (rc >= 0 && buf.oifb_items > 0 &&
2304 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
2305 fops->release(inode, filp);
2311 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
2312 struct dentry *dentry, filldir_t filldir)
2314 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2315 struct scrub_file *sf = &scrub->os_file;
2316 struct dentry *child;
2320 /* It is existing MDT0 device. We only allow the case of object without
2321 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
2322 * can generate IGIF mode FID for the object and related OI mapping. If
2323 * it is on other MDTs, then becuase file-level backup/restore, related
2324 * OI mapping may be invalid already, we do not know which is the right
2325 * FID for the object. We only allow IGIF objects to reside on the MDT0.
2327 * XXX: For the case of object on non-MDT0 device with neither LMA nor
2328 * "fid" xattr, then something crashed. We cannot re-generate the
2329 * FID directly, instead, the OI scrub will scan the OI structure
2330 * and try to re-generate the LMA from the OI mapping. But if the
2331 * OI mapping crashed or lost also, then we have to give up under
2332 * double failure cases. */
2333 scrub->os_convert_igif = 1;
2334 child = osd_ios_lookup_one_len(dot_lustre_name, dentry,
2335 strlen(dot_lustre_name));
2336 if (IS_ERR(child)) {
2337 rc = PTR_ERR(child);
2338 if (rc == -ENOENT) {
2339 /* It is 1.8 MDT device. */
2340 if (!(sf->sf_flags & SF_UPGRADE)) {
2341 scrub_file_reset(scrub,
2342 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
2344 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2345 rc = scrub_file_store(info->oti_env, scrub);
2351 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
2352 * so the client will get IGIF for the ".lustre" object when
2355 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
2356 * it does not know whether there are some old clients cached
2357 * the ".lustre" IGIF during the upgrading. Two choices:
2359 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
2360 * It will allow the old connected clients to access the
2361 * ".lustre" with cached IGIF. But it will cause others
2362 * on the MDT failed to check "fid_is_dot_lustre()".
2364 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
2365 * for ".lustre" in spite of whether there are some clients
2366 * cached the ".lustre" IGIF or not. It enables the check
2367 * "fid_is_dot_lustre()" on the MDT, although it will cause
2368 * that the old connected clients cannot access the ".lustre"
2369 * with the cached IGIF.
2371 * Usually, it is rare case for the old connected clients
2372 * to access the ".lustre" with cached IGIF. So we prefer
2373 * to the solution 2). */
2374 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2375 child->d_inode, &LU_DOT_LUSTRE_FID,
2377 strlen(dot_lustre_name), 0);
2379 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2388 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
2389 struct dentry *dentry, filldir_t filldir)
2391 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2392 struct scrub_file *sf = &scrub->os_file;
2393 struct dentry *child;
2397 if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
2398 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2399 rc = scrub_file_store(info->oti_env, scrub);
2404 child = osd_ios_lookup_one_len(ADMIN_USR, dentry, strlen(ADMIN_USR));
2405 if (!IS_ERR(child)) {
2406 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2407 child->d_inode, NULL, ADMIN_USR,
2408 strlen(ADMIN_USR), 0);
2411 rc = PTR_ERR(child);
2414 if (rc != 0 && rc != -ENOENT)
2417 child = osd_ios_lookup_one_len(ADMIN_GRP, dentry, strlen(ADMIN_GRP));
2418 if (!IS_ERR(child)) {
2419 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2420 child->d_inode, NULL, ADMIN_GRP,
2421 strlen(ADMIN_GRP), 0);
2424 rc = PTR_ERR(child);
2433 static void osd_initial_OI_scrub(struct osd_thread_info *info,
2434 struct osd_device *dev)
2436 struct osd_ios_item *item = NULL;
2437 scandir_t scandir = osd_ios_general_scan;
2438 filldir_t filldir = osd_ios_root_fill;
2439 struct dentry *dentry = osd_sb(dev)->s_root;
2440 const struct osd_lf_map *map = osd_lf_maps;
2443 /* Lookup IGIF in OI by force for initial OI scrub. */
2444 dev->od_igif_inoi = 1;
2447 scandir(info, dev, dentry, filldir);
2449 dput(item->oii_dentry);
2453 if (list_empty(&dev->od_ios_list))
2456 item = list_entry(dev->od_ios_list.next,
2457 struct osd_ios_item, oii_list);
2458 list_del_init(&item->oii_list);
2460 LASSERT(item->oii_scandir != NULL);
2461 scandir = item->oii_scandir;
2462 filldir = item->oii_filldir;
2463 dentry = item->oii_dentry;
2466 /* There maybe the case that the object has been removed, but its OI
2467 * mapping is still in the OI file, such as the "CATALOGS" after MDT
2468 * file-level backup/restore. So here cleanup the stale OI mappings. */
2469 while (map->olm_name != NULL) {
2470 struct dentry *child;
2472 if (fid_is_zero(&map->olm_fid)) {
2477 child = osd_ios_lookup_one_len(map->olm_name,
2478 osd_sb(dev)->s_root,
2482 else if (PTR_ERR(child) == -ENOENT)
2483 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
2484 NULL, DTO_INDEX_DELETE,
2489 if (!list_empty(&dev->od_index_restore_list)) {
2492 OBD_ALLOC_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2494 CERROR("%s: not enough RAM for rebuild index\n",
2497 while (!list_empty(&dev->od_index_restore_list)) {
2498 struct lustre_index_restore_unit *liru;
2500 liru = list_entry(dev->od_index_restore_list.next,
2501 struct lustre_index_restore_unit,
2503 list_del(&liru->liru_link);
2505 osd_index_restore(info->oti_env, dev, liru,
2506 buf, INDEX_BACKUP_BUFSIZE);
2507 OBD_FREE(liru, liru->liru_len);
2511 OBD_FREE_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2517 char *osd_lf_fid2name(const struct lu_fid *fid)
2519 const struct osd_lf_map *map = osd_lf_maps;
2521 while (map->olm_name != NULL) {
2522 if (!lu_fid_eq(fid, &map->olm_fid)) {
2527 if (map->olm_flags & OLF_SHOW_NAME)
2528 return map->olm_name;
2536 /* OI scrub start/stop */
2538 int osd_scrub_start(const struct lu_env *env, struct osd_device *dev,
2541 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2545 if (dev->od_dt_dev.dd_rdonly)
2548 /* od_otable_mutex: prevent curcurrent start/stop */
2549 mutex_lock(&dev->od_otable_mutex);
2550 rc = scrub_start(osd_scrub_main, scrub, dev, flags);
2551 if (rc == -EALREADY) {
2553 if ((scrub->os_file.sf_flags & SF_AUTO ||
2554 scrub->os_partial_scan) &&
2555 !(flags & SS_AUTO_PARTIAL))
2556 osd_scrub_join(env, dev, flags, false);
2558 mutex_unlock(&dev->od_otable_mutex);
2563 void osd_scrub_stop(struct osd_device *dev)
2565 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2567 /* od_otable_mutex: prevent curcurrent start/stop */
2568 mutex_lock(&dev->od_otable_mutex);
2569 scrub->os_paused = 1;
2571 mutex_unlock(&dev->od_otable_mutex);
2574 /* OI scrub setup/cleanup */
2576 static const char osd_scrub_name[] = "OI_scrub";
2578 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
2580 struct osd_thread_info *info = osd_oti_get(env);
2581 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2582 struct lvfs_run_ctxt *ctxt = &dev->od_scrub.os_ctxt;
2583 struct scrub_file *sf = &scrub->os_file;
2584 struct super_block *sb = osd_sb(dev);
2585 struct ldiskfs_super_block *es = LDISKFS_SB(sb)->s_es;
2586 struct lvfs_run_ctxt saved;
2588 struct inode *inode;
2589 struct lu_fid *fid = &info->oti_fid;
2590 struct osd_inode_id *id = &info->oti_id;
2591 struct dt_object *obj;
2593 bool restored = false;
2597 memset(&dev->od_scrub, 0, sizeof(struct osd_scrub));
2598 OBD_SET_CTXT_MAGIC(ctxt);
2599 ctxt->pwdmnt = dev->od_mnt;
2600 ctxt->pwd = dev->od_mnt->mnt_root;
2601 ctxt->fs = get_ds();
2603 init_waitqueue_head(&scrub->os_thread.t_ctl_waitq);
2604 init_rwsem(&scrub->os_rwsem);
2605 spin_lock_init(&scrub->os_lock);
2606 INIT_LIST_HEAD(&scrub->os_inconsistent_items);
2607 scrub->os_name = osd_name(dev);
2609 push_ctxt(&saved, ctxt);
2610 filp = filp_open(osd_scrub_name, O_RDWR |
2611 (dev->od_dt_dev.dd_rdonly ? 0 : O_CREAT), 0644);
2613 pop_ctxt(&saved, ctxt);
2614 RETURN(PTR_ERR(filp));
2617 inode = file_inode(filp);
2618 if (!dev->od_dt_dev.dd_rdonly) {
2619 /* 'What the @fid is' is not imporatant, because the object
2620 * has no OI mapping, and only is visible inside the OSD.*/
2621 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2622 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
2624 filp_close(filp, NULL);
2625 pop_ctxt(&saved, ctxt);
2630 osd_id_gen(id, inode->i_ino, inode->i_generation);
2631 osd_add_oi_cache(info, dev, id, fid);
2632 filp_close(filp, NULL);
2633 pop_ctxt(&saved, ctxt);
2635 obj = lu2dt(lu_object_find_slice(env, osd2lu_dev(dev), fid, NULL));
2636 if (IS_ERR_OR_NULL(obj))
2637 RETURN(obj ? PTR_ERR(obj) : -ENOENT);
2639 scrub->os_obj = obj;
2640 rc = scrub_file_load(env, scrub);
2641 if (rc == -ENOENT || rc == -EFAULT) {
2642 scrub_file_init(scrub, es->s_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 (memcmp(sf->sf_uuid, es->s_uuid, 16) != 0) {
2662 struct obd_uuid *old_uuid;
2663 struct obd_uuid *new_uuid;
2665 OBD_ALLOC_PTR(old_uuid);
2666 OBD_ALLOC_PTR(new_uuid);
2667 if (old_uuid == NULL || new_uuid == NULL) {
2668 CERROR("%s: UUID has been changed, but"
2669 "failed to allocate RAM for report\n",
2672 class_uuid_unparse(sf->sf_uuid, old_uuid);
2673 class_uuid_unparse(es->s_uuid, new_uuid);
2674 CDEBUG(D_LFSCK, "%s: UUID has been changed "
2675 "from %s to %s\n", osd_dev2name(dev),
2676 old_uuid->uuid, new_uuid->uuid);
2678 scrub_file_reset(scrub, es->s_uuid, SF_INCONSISTENT);
2681 if (old_uuid != NULL)
2682 OBD_FREE_PTR(old_uuid);
2683 if (new_uuid != NULL)
2684 OBD_FREE_PTR(new_uuid);
2685 } else if (sf->sf_status == SS_SCANNING) {
2686 sf->sf_status = SS_CRASHED;
2690 if ((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) {
2691 LCONSOLE_WARN("%s: invalid oi count %d, set it to %d\n",
2692 osd_dev2name(dev), sf->sf_oi_count,
2694 sf->sf_oi_count = osd_oi_count;
2699 if (sf->sf_pos_last_checkpoint != 0)
2700 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
2702 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
2705 rc = scrub_file_store(env, scrub);
2707 GOTO(cleanup_obj, rc);
2710 /* Initialize OI files. */
2711 rc = osd_oi_init(info, dev, restored);
2713 GOTO(cleanup_obj, rc);
2715 if (!dev->od_dt_dev.dd_rdonly)
2716 osd_initial_OI_scrub(info, dev);
2718 if (sf->sf_flags & SF_UPGRADE ||
2719 !(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID ||
2720 sf->sf_success_count > 0)) {
2721 dev->od_igif_inoi = 0;
2722 dev->od_check_ff = dev->od_is_ost;
2724 dev->od_igif_inoi = 1;
2725 dev->od_check_ff = 0;
2728 if (sf->sf_flags & SF_INCONSISTENT)
2729 /* The 'od_igif_inoi' will be set under the
2731 * 1) new created system, or
2732 * 2) restored from file-level backup, or
2733 * 3) the upgrading completed.
2735 * The 'od_igif_inoi' may be cleared by OI scrub
2736 * later if found that the system is upgrading. */
2737 dev->od_igif_inoi = 1;
2739 if (!dev->od_dt_dev.dd_rdonly &&
2740 dev->od_auto_scrub_interval != AS_NEVER &&
2741 ((sf->sf_status == SS_PAUSED) ||
2742 (sf->sf_status == SS_CRASHED &&
2743 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2744 SF_UPGRADE | SF_AUTO)) ||
2745 (sf->sf_status == SS_INIT &&
2746 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2748 rc = osd_scrub_start(env, dev, SS_AUTO_FULL);
2751 GOTO(cleanup_oi, rc);
2753 /* it is possible that dcache entries may keep objects after they are
2754 * deleted by OSD. While it looks safe this can cause object data to
2755 * stay until umount causing failures in tests calculating free space,
2756 * e.g. replay-ost-single. Since those dcache entries are not used
2757 * anymore let's just free them after use here */
2758 shrink_dcache_sb(sb);
2762 osd_oi_fini(info, dev);
2764 dt_object_put_nocache(env, scrub->os_obj);
2765 scrub->os_obj = NULL;
2770 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
2772 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2774 LASSERT(dev->od_otable_it == NULL);
2776 if (scrub->os_obj != NULL) {
2777 osd_scrub_stop(dev);
2778 dt_object_put_nocache(env, scrub->os_obj);
2779 scrub->os_obj = NULL;
2781 if (dev->od_oi_table != NULL)
2782 osd_oi_fini(osd_oti_get(env), dev);
2785 /* object table based iteration APIs */
2787 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
2788 struct dt_object *dt, __u32 attr)
2790 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
2791 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
2792 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
2793 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2794 struct osd_otable_it *it;
2799 /* od_otable_mutex: prevent curcurrent init/fini */
2800 mutex_lock(&dev->od_otable_mutex);
2801 if (dev->od_otable_it != NULL)
2802 GOTO(out, it = ERR_PTR(-EALREADY));
2806 GOTO(out, it = ERR_PTR(-ENOMEM));
2808 dev->od_otable_it = it;
2810 it->ooi_cache.ooc_consumer_idx = -1;
2811 if (flags & DOIF_OUTUSED)
2812 it->ooi_used_outside = 1;
2814 if (flags & DOIF_RESET)
2817 if (valid & DOIV_ERROR_HANDLE) {
2818 if (flags & DOIF_FAILOUT)
2819 start |= SS_SET_FAILOUT;
2821 start |= SS_CLEAR_FAILOUT;
2824 if (valid & DOIV_DRYRUN) {
2825 if (flags & DOIF_DRYRUN)
2826 start |= SS_SET_DRYRUN;
2828 start |= SS_CLEAR_DRYRUN;
2831 rc = scrub_start(osd_scrub_main, scrub, dev, start & ~SS_AUTO_PARTIAL);
2832 if (rc == -EALREADY) {
2833 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2834 } else if (rc < 0) {
2835 dev->od_otable_it = NULL;
2839 /* We have to start from the begining. */
2840 it->ooi_cache.ooc_pos_preload =
2841 LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2847 mutex_unlock(&dev->od_otable_mutex);
2848 return (struct dt_it *)it;
2851 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2853 struct osd_otable_it *it = (struct osd_otable_it *)di;
2854 struct osd_device *dev = it->ooi_dev;
2856 /* od_otable_mutex: prevent curcurrent init/fini */
2857 mutex_lock(&dev->od_otable_mutex);
2858 scrub_stop(&dev->od_scrub.os_scrub);
2859 LASSERT(dev->od_otable_it == it);
2861 dev->od_otable_it = NULL;
2862 mutex_unlock(&dev->od_otable_mutex);
2866 static int osd_otable_it_get(const struct lu_env *env,
2867 struct dt_it *di, const struct dt_key *key)
2872 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2877 osd_otable_it_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
2879 spin_lock(&scrub->os_lock);
2880 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2881 scrub->os_waiting ||
2882 !thread_is_running(&scrub->os_thread))
2883 it->ooi_waiting = 0;
2885 it->ooi_waiting = 1;
2886 spin_unlock(&scrub->os_lock);
2888 return !it->ooi_waiting;
2891 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2893 struct osd_otable_it *it = (struct osd_otable_it *)di;
2894 struct osd_device *dev = it->ooi_dev;
2895 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2896 struct osd_otable_cache *ooc = &it->ooi_cache;
2897 struct ptlrpc_thread *thread = &scrub->os_thread;
2898 struct l_wait_info lwi = { 0 };
2902 LASSERT(it->ooi_user_ready);
2905 if (!thread_is_running(thread) && !it->ooi_used_outside)
2908 if (ooc->ooc_cached_items > 0) {
2909 ooc->ooc_cached_items--;
2910 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2911 ~OSD_OTABLE_IT_CACHE_MASK;
2915 if (it->ooi_all_cached) {
2916 l_wait_event(thread->t_ctl_waitq,
2917 !thread_is_running(thread),
2922 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2923 spin_lock(&scrub->os_lock);
2924 scrub->os_waiting = 0;
2925 wake_up_all(&scrub->os_thread.t_ctl_waitq);
2926 spin_unlock(&scrub->os_lock);
2929 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2930 l_wait_event(thread->t_ctl_waitq,
2931 osd_otable_it_wakeup(scrub, it),
2934 if (!thread_is_running(thread) && !it->ooi_used_outside)
2937 rc = osd_otable_it_preload(env, it);
2944 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2945 const struct dt_it *di)
2950 static int osd_otable_it_key_size(const struct lu_env *env,
2951 const struct dt_it *di)
2953 return sizeof(__u64);
2956 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2957 struct dt_rec *rec, __u32 attr)
2959 struct osd_otable_it *it = (struct osd_otable_it *)di;
2960 struct osd_otable_cache *ooc = &it->ooi_cache;
2962 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2964 /* Filter out Invald FID already. */
2965 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2966 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2967 PFID((struct lu_fid *)rec),
2968 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2973 static __u64 osd_otable_it_store(const struct lu_env *env,
2974 const struct dt_it *di)
2976 struct osd_otable_it *it = (struct osd_otable_it *)di;
2977 struct osd_otable_cache *ooc = &it->ooi_cache;
2980 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2981 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2983 hash = ooc->ooc_pos_preload;
2988 * Set the OSD layer iteration start position as the specified hash.
2990 static int osd_otable_it_load(const struct lu_env *env,
2991 const struct dt_it *di, __u64 hash)
2993 struct osd_otable_it *it = (struct osd_otable_it *)di;
2994 struct osd_device *dev = it->ooi_dev;
2995 struct osd_otable_cache *ooc = &it->ooi_cache;
2996 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2997 struct osd_iit_param *param = &it->ooi_iit_param;
3001 /* Forbid to set iteration position after iteration started. */
3002 if (it->ooi_user_ready)
3005 LASSERT(!scrub->os_partial_scan);
3007 if (hash > OSD_OTABLE_MAX_HASH)
3008 hash = OSD_OTABLE_MAX_HASH;
3010 /* The hash is the last checkpoint position,
3011 * we will start from the next one. */
3012 ooc->ooc_pos_preload = hash + 1;
3013 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
3014 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
3016 it->ooi_user_ready = 1;
3017 if (!scrub->os_full_speed)
3018 wake_up_all(&scrub->os_thread.t_ctl_waitq);
3020 memset(param, 0, sizeof(*param));
3021 param->sb = osd_sb(dev);
3022 param->start = ooc->ooc_pos_preload;
3023 param->bg = (ooc->ooc_pos_preload - 1) /
3024 LDISKFS_INODES_PER_GROUP(param->sb);
3025 param->offset = (ooc->ooc_pos_preload - 1) %
3026 LDISKFS_INODES_PER_GROUP(param->sb);
3027 param->gbase = 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
3029 /* Unplug OSD layer iteration by the first next() call. */
3030 rc = osd_otable_it_next(env, (struct dt_it *)it);
3035 static int osd_otable_it_key_rec(const struct lu_env *env,
3036 const struct dt_it *di, void *key_rec)
3041 const struct dt_index_operations osd_otable_ops = {
3043 .init = osd_otable_it_init,
3044 .fini = osd_otable_it_fini,
3045 .get = osd_otable_it_get,
3046 .put = osd_otable_it_put,
3047 .next = osd_otable_it_next,
3048 .key = osd_otable_it_key,
3049 .key_size = osd_otable_it_key_size,
3050 .rec = osd_otable_it_rec,
3051 .store = osd_otable_it_store,
3052 .load = osd_otable_it_load,
3053 .key_rec = osd_otable_it_key_rec,
3057 /* high priority inconsistent items list APIs */
3059 #define SCRUB_BAD_OIMAP_DECAY_INTERVAL 60
3061 int osd_oii_insert(struct osd_device *dev, struct osd_idmap_cache *oic,
3064 struct osd_inconsistent_item *oii;
3065 struct osd_scrub *oscrub = &dev->od_scrub;
3066 struct lustre_scrub *lscrub = &oscrub->os_scrub;
3067 struct ptlrpc_thread *thread = &lscrub->os_thread;
3072 if (unlikely(oii == NULL))
3075 INIT_LIST_HEAD(&oii->oii_list);
3076 oii->oii_cache = *oic;
3077 oii->oii_insert = insert;
3079 if (lscrub->os_partial_scan) {
3080 __u64 now = ktime_get_real_seconds();
3082 /* If there haven't been errors in a long time,
3083 * decay old count until either the errors are
3084 * gone or we reach the current interval. */
3085 while (unlikely(oscrub->os_bad_oimap_count > 0 &&
3086 oscrub->os_bad_oimap_time +
3087 SCRUB_BAD_OIMAP_DECAY_INTERVAL < now)) {
3088 oscrub->os_bad_oimap_count >>= 1;
3089 oscrub->os_bad_oimap_time +=
3090 SCRUB_BAD_OIMAP_DECAY_INTERVAL;
3093 oscrub->os_bad_oimap_time = now;
3094 if (++oscrub->os_bad_oimap_count >
3095 dev->od_full_scrub_threshold_rate)
3096 lscrub->os_full_scrub = 1;
3099 spin_lock(&lscrub->os_lock);
3100 if (unlikely(!thread_is_running(thread))) {
3101 spin_unlock(&lscrub->os_lock);
3106 if (list_empty(&lscrub->os_inconsistent_items))
3108 list_add_tail(&oii->oii_list, &lscrub->os_inconsistent_items);
3109 spin_unlock(&lscrub->os_lock);
3112 wake_up_all(&thread->t_ctl_waitq);
3117 int osd_oii_lookup(struct osd_device *dev, const struct lu_fid *fid,
3118 struct osd_inode_id *id)
3120 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3121 struct osd_inconsistent_item *oii;
3124 spin_lock(&scrub->os_lock);
3125 list_for_each_entry(oii, &scrub->os_inconsistent_items, oii_list) {
3126 if (lu_fid_eq(fid, &oii->oii_cache.oic_fid)) {
3127 *id = oii->oii_cache.oic_lid;
3128 spin_unlock(&scrub->os_lock);
3132 spin_unlock(&scrub->os_lock);
3137 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
3139 struct osd_scrub *scrub = &dev->od_scrub;
3141 scrub_dump(m, &scrub->os_scrub);
3142 seq_printf(m, "lf_scanned: %llu\n"
3144 "lf_failed: %llu\n",
3145 scrub->os_lf_scanned,
3146 scrub->os_scrub.os_file.sf_param & SP_DRYRUN ?
3147 "inconsistent" : "repaired",
3148 scrub->os_lf_repaired,
3149 scrub->os_lf_failed);