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)))
342 if (!scrub->os_partial_scan) {
343 spin_lock(&scrub->os_lock);
344 scrub->os_full_speed = 1;
345 spin_unlock(&scrub->os_lock);
349 case SCRUB_NEXT_NOLMA:
350 sf->sf_flags |= SF_UPGRADE;
351 if (!(sf->sf_param & SP_DRYRUN)) {
352 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
357 if (!(sf->sf_flags & SF_INCONSISTENT))
358 dev->od_igif_inoi = 0;
360 case SCRUB_NEXT_OSTOBJ:
361 sf->sf_flags |= SF_INCONSISTENT;
362 case SCRUB_NEXT_OSTOBJ_OLD:
367 } else if (osd_id_eq(lid, lid2)) {
369 sf->sf_items_updated++;
373 if (!scrub->os_partial_scan) {
374 spin_lock(&scrub->os_lock);
375 scrub->os_full_speed = 1;
376 spin_unlock(&scrub->os_lock);
378 sf->sf_flags |= SF_INCONSISTENT;
380 /* XXX: If the device is restored from file-level backup, then
381 * some IGIFs may have been already in OI files, and some
382 * may be not yet. Means upgrading from 1.8 may be partly
383 * processed, but some clients may hold some immobilized
384 * IGIFs, and use them to access related objects. Under
385 * such case, OSD does not know whether an given IGIF has
386 * been processed or to be processed, and it also cannot
387 * generate local ino#/gen# directly from the immobilized
388 * IGIF because of the backup/restore. Then force OSD to
389 * lookup the given IGIF in OI files, and if no entry,
390 * then ask the client to retry after upgrading completed.
391 * No better choice. */
392 dev->od_igif_inoi = 1;
395 rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops, false,
396 (val == SCRUB_NEXT_OSTOBJ ||
397 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0,
400 if (scrub->os_in_prior)
401 sf->sf_items_updated_prior++;
403 sf->sf_items_updated++;
405 if (ops == DTO_INDEX_INSERT && val == 0 && !exist) {
406 int idx = osd_oi_fid2idx(dev, fid);
408 sf->sf_flags |= SF_RECREATED;
409 if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
410 ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
418 sf->sf_items_failed++;
419 if (sf->sf_pos_first_inconsistent == 0 ||
420 sf->sf_pos_first_inconsistent > lid->oii_ino)
421 sf->sf_pos_first_inconsistent = lid->oii_ino;
426 /* There may be conflict unlink during the OI scrub,
427 * if happend, then remove the new added OI mapping. */
428 if (ops == DTO_INDEX_INSERT && inode != NULL && !IS_ERR(inode) &&
429 unlikely(ldiskfs_test_inode_state(inode,
430 LDISKFS_STATE_LUSTRE_DESTROY)))
431 osd_scrub_refresh_mapping(info, dev, fid, lid,
432 DTO_INDEX_DELETE, false,
433 (val == SCRUB_NEXT_OSTOBJ ||
434 val == SCRUB_NEXT_OSTOBJ_OLD) ?
435 OI_KNOWN_ON_OST : 0, NULL);
436 up_write(&scrub->os_rwsem);
438 if (inode != NULL && !IS_ERR(inode))
442 spin_lock(&scrub->os_lock);
443 if (likely(!list_empty(&oii->oii_list)))
444 list_del(&oii->oii_list);
445 spin_unlock(&scrub->os_lock);
450 RETURN(sf->sf_param & SP_FAILOUT ? rc : 0);
453 static int osd_scrub_prep(const struct lu_env *env, struct osd_device *dev)
455 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
456 struct ptlrpc_thread *thread = &scrub->os_thread;
457 struct scrub_file *sf = &scrub->os_file;
458 __u32 flags = scrub->os_start_flags;
460 bool drop_dryrun = false;
463 CDEBUG(D_LFSCK, "%s: OI scrub prep, flags = 0x%x\n",
464 osd_scrub2name(scrub), flags);
466 down_write(&scrub->os_rwsem);
467 if (flags & SS_SET_FAILOUT)
468 sf->sf_param |= SP_FAILOUT;
469 else if (flags & SS_CLEAR_FAILOUT)
470 sf->sf_param &= ~SP_FAILOUT;
472 if (flags & SS_SET_DRYRUN) {
473 sf->sf_param |= SP_DRYRUN;
474 } else if (flags & SS_CLEAR_DRYRUN && sf->sf_param & SP_DRYRUN) {
475 sf->sf_param &= ~SP_DRYRUN;
479 if (flags & SS_RESET)
480 scrub_file_reset(scrub, dev->od_uuid, 0);
482 spin_lock(&scrub->os_lock);
483 if (flags & SS_AUTO_FULL) {
484 scrub->os_full_speed = 1;
485 scrub->os_partial_scan = 0;
486 sf->sf_flags |= SF_AUTO;
487 } else if (flags & SS_AUTO_PARTIAL) {
488 scrub->os_full_speed = 0;
489 scrub->os_partial_scan = 1;
490 sf->sf_flags |= SF_AUTO;
491 } else if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
493 scrub->os_full_speed = 1;
494 scrub->os_partial_scan = 0;
496 scrub->os_full_speed = 0;
497 scrub->os_partial_scan = 0;
500 scrub->os_in_prior = 0;
501 scrub->os_waiting = 0;
502 scrub->os_paused = 0;
503 scrub->os_in_join = 0;
504 scrub->os_full_scrub = 0;
505 spin_unlock(&scrub->os_lock);
506 scrub->os_new_checked = 0;
507 if (drop_dryrun && sf->sf_pos_first_inconsistent != 0)
508 sf->sf_pos_latest_start = sf->sf_pos_first_inconsistent;
509 else if (sf->sf_pos_last_checkpoint != 0)
510 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
512 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
514 scrub->os_pos_current = sf->sf_pos_latest_start;
515 sf->sf_status = SS_SCANNING;
516 sf->sf_time_latest_start = ktime_get_real_seconds();
517 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
518 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
519 rc = scrub_file_store(env, scrub);
521 spin_lock(&scrub->os_lock);
522 thread_set_flags(thread, SVC_RUNNING);
523 spin_unlock(&scrub->os_lock);
524 wake_up_all(&thread->t_ctl_waitq);
526 up_write(&scrub->os_rwsem);
531 static int osd_scrub_post(const struct lu_env *env, struct osd_device *dev,
534 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
535 struct scrub_file *sf = &scrub->os_file;
539 CDEBUG(D_LFSCK, "%s: OI scrub post with result = %d\n",
540 osd_scrub2name(scrub), result);
542 down_write(&scrub->os_rwsem);
543 spin_lock(&scrub->os_lock);
544 thread_set_flags(&scrub->os_thread, SVC_STOPPING);
545 spin_unlock(&scrub->os_lock);
546 if (scrub->os_new_checked > 0) {
547 sf->sf_items_checked += scrub->os_new_checked;
548 scrub->os_new_checked = 0;
549 sf->sf_pos_last_checkpoint = scrub->os_pos_current;
551 sf->sf_time_last_checkpoint = ktime_get_real_seconds();
553 dev->od_igif_inoi = 1;
554 dev->od_check_ff = 0;
555 sf->sf_status = SS_COMPLETED;
556 if (!(sf->sf_param & SP_DRYRUN)) {
557 memset(sf->sf_oi_bitmap, 0, SCRUB_OI_BITMAP_SIZE);
558 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
559 SF_UPGRADE | SF_AUTO);
561 sf->sf_time_last_complete = sf->sf_time_last_checkpoint;
562 sf->sf_success_count++;
563 } else if (result == 0) {
564 if (scrub->os_paused)
565 sf->sf_status = SS_PAUSED;
567 sf->sf_status = SS_STOPPED;
569 sf->sf_status = SS_FAILED;
571 sf->sf_run_time += ktime_get_seconds() -
572 scrub->os_time_last_checkpoint;
574 rc = scrub_file_store(env, scrub);
575 up_write(&scrub->os_rwsem);
577 RETURN(rc < 0 ? rc : result);
580 /* iteration engine */
582 typedef int (*osd_iit_next_policy)(struct osd_thread_info *info,
583 struct osd_device *dev,
584 struct osd_iit_param *param,
585 struct osd_idmap_cache **oic,
588 typedef int (*osd_iit_exec_policy)(struct osd_thread_info *info,
589 struct osd_device *dev,
590 struct osd_iit_param *param,
591 struct osd_idmap_cache *oic,
592 bool *noslot, int rc);
594 static int osd_iit_next(struct osd_iit_param *param, __u64 *pos)
599 param->offset = ldiskfs_find_next_bit(param->bitmap->b_data,
600 LDISKFS_INODES_PER_GROUP(param->sb), param->offset);
601 if (param->offset >= LDISKFS_INODES_PER_GROUP(param->sb)) {
602 *pos = 1 + (param->bg+1) * LDISKFS_INODES_PER_GROUP(param->sb);
603 return SCRUB_NEXT_BREAK;
606 offset = param->offset++;
607 if (unlikely(*pos == param->gbase + offset && *pos != param->start)) {
608 /* We should NOT find the same object more than once. */
609 CERROR("%s: scan the same object multiple times at the pos: "
610 "group = %u, base = %u, offset = %u, start = %u\n",
611 param->sb->s_id, (__u32)param->bg, param->gbase,
612 offset, param->start);
616 *pos = param->gbase + offset;
621 * \retval SCRUB_NEXT_OSTOBJ_OLD: FID-on-OST
622 * \retval 0: FID-on-MDT
624 static int osd_scrub_check_local_fldb(struct osd_thread_info *info,
625 struct osd_device *dev,
628 /* XXX: The initial OI scrub will scan the top level /O to generate
629 * a small local FLDB according to the <seq>. If the given FID
630 * is in the local FLDB, then it is FID-on-OST; otherwise it's
631 * quite possible for FID-on-MDT. */
633 return SCRUB_NEXT_OSTOBJ_OLD;
638 static int osd_scrub_get_fid(struct osd_thread_info *info,
639 struct osd_device *dev, struct inode *inode,
640 struct lu_fid *fid, bool scrub)
642 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
643 bool has_lma = false;
646 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
647 &info->oti_ost_attrs);
650 if (lma->lma_compat & LMAC_NOT_IN_OI ||
651 lma->lma_incompat & LMAI_AGENT)
652 return SCRUB_NEXT_CONTINUE;
654 *fid = lma->lma_self_fid;
658 if (lma->lma_compat & LMAC_FID_ON_OST)
659 return SCRUB_NEXT_OSTOBJ;
661 if (fid_is_idif(fid))
662 return SCRUB_NEXT_OSTOBJ_OLD;
664 /* For local object. */
665 if (fid_is_internal(fid))
668 /* For external visible MDT-object with non-normal FID. */
669 if (fid_is_namespace_visible(fid) && !fid_is_norm(fid))
672 /* For the object with normal FID, it may be MDT-object,
673 * or may be 2.4 OST-object, need further distinguish.
674 * Fall through to next section. */
677 if (rc == -ENODATA || rc == 0) {
678 rc = osd_get_idif(info, inode, &info->oti_obj_dentry, fid);
681 /* It is 2.3 or older OST-object. */
682 rc = SCRUB_NEXT_OSTOBJ_OLD;
688 /* It is FID-on-OST, but we do not know how
689 * to generate its FID, ignore it directly. */
690 rc = SCRUB_NEXT_CONTINUE;
692 /* It is 2.4 or newer OST-object. */
693 rc = SCRUB_NEXT_OSTOBJ_OLD;
701 if (dev->od_scrub.os_scrub.os_convert_igif) {
702 lu_igif_build(fid, inode->i_ino,
703 inode->i_generation);
705 rc = SCRUB_NEXT_NOLMA;
709 /* It may be FID-on-OST, or may be FID for
710 * non-MDT0, anyway, we do not know how to
711 * generate its FID, ignore it directly. */
712 rc = SCRUB_NEXT_CONTINUE;
717 /* For OI scrub case only: the object has LMA but has no ff
718 * (or ff crashed). It may be MDT-object, may be OST-object
719 * with crashed ff. The last check is local FLDB. */
720 rc = osd_scrub_check_local_fldb(info, dev, fid);
726 static int osd_iit_iget(struct osd_thread_info *info, struct osd_device *dev,
727 struct lu_fid *fid, struct osd_inode_id *lid, __u32 pos,
728 struct super_block *sb, bool scrub)
734 /* Not handle the backend root object and agent parent object.
735 * They are neither visible to namespace nor have OI mappings. */
736 if (unlikely(pos == osd_sb(dev)->s_root->d_inode->i_ino ||
737 is_remote_parent_ino(dev, pos)))
738 RETURN(SCRUB_NEXT_CONTINUE);
740 /* Skip project quota inode since it is greater than s_first_ino. */
741 #ifdef HAVE_PROJECT_QUOTA
742 if (ldiskfs_has_feature_project(sb) &&
743 pos == le32_to_cpu(LDISKFS_SB(sb)->s_es->s_prj_quota_inum))
744 RETURN(SCRUB_NEXT_CONTINUE);
747 osd_id_gen(lid, pos, OSD_OII_NOGEN);
748 inode = osd_iget(info, dev, lid);
751 /* The inode may be removed after bitmap searching, or the
752 * file is new created without inode initialized yet. */
753 if (rc == -ENOENT || rc == -ESTALE)
754 RETURN(SCRUB_NEXT_CONTINUE);
756 CDEBUG(D_LFSCK, "%s: fail to read inode, ino# = %u: "
757 "rc = %d\n", osd_dev2name(dev), pos, rc);
761 /* It is an EA inode, no OI mapping for it, skip it. */
762 if (osd_is_ea_inode(inode))
763 GOTO(put, rc = SCRUB_NEXT_CONTINUE);
766 ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB)) {
767 /* Only skip it for the first OI scrub accessing. */
768 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
769 GOTO(put, rc = SCRUB_NEXT_NOSCRUB);
772 rc = osd_scrub_get_fid(info, dev, inode, fid, scrub);
781 static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
782 struct osd_iit_param *param,
783 struct osd_idmap_cache **oic, const bool noslot)
785 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
786 struct ptlrpc_thread *thread = &scrub->os_thread;
788 struct osd_inode_id *lid;
791 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0)
792 wait_event_idle_timeout(
794 !list_empty(&scrub->os_inconsistent_items) ||
795 !thread_is_running(thread),
796 cfs_time_seconds(cfs_fail_val));
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);
819 *oic = &oii->oii_cache;
820 scrub->os_in_prior = 1;
821 spin_unlock(&scrub->os_lock);
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 lustre_scrub *scrub = &dev->od_scrub.os_scrub;
887 struct scrub_file *sf = &scrub->os_file;
888 struct ptlrpc_thread *thread = &scrub->os_thread;
889 struct osd_otable_it *it = dev->od_otable_it;
890 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
893 case SCRUB_NEXT_NOSCRUB:
894 down_write(&scrub->os_rwsem);
895 scrub->os_new_checked++;
896 sf->sf_items_noscrub++;
897 up_write(&scrub->os_rwsem);
898 case SCRUB_NEXT_CONTINUE:
899 case SCRUB_NEXT_WAIT:
903 rc = osd_scrub_check_update(info, dev, oic, rc);
905 spin_lock(&scrub->os_lock);
906 scrub->os_in_prior = 0;
907 spin_unlock(&scrub->os_lock);
911 rc = scrub_checkpoint(info->oti_env, scrub);
913 CDEBUG(D_LFSCK, "%s: fail to checkpoint, pos = %llu: "
914 "rc = %d\n", osd_scrub2name(scrub),
915 scrub->os_pos_current, rc);
916 /* Continue, as long as the scrub itself can go ahead. */
919 if (scrub->os_in_prior) {
920 spin_lock(&scrub->os_lock);
921 scrub->os_in_prior = 0;
922 spin_unlock(&scrub->os_lock);
927 if (it != NULL && it->ooi_waiting && ooc != NULL &&
928 ooc->ooc_pos_preload < scrub->os_pos_current) {
929 spin_lock(&scrub->os_lock);
931 wake_up_all(&thread->t_ctl_waitq);
932 spin_unlock(&scrub->os_lock);
935 if (rc == SCRUB_NEXT_CONTINUE)
938 if (scrub->os_full_speed || !ooc || osd_scrub_has_window(scrub, ooc)) {
944 wait_event_idle(thread->t_ctl_waitq,
945 osd_scrub_wakeup(scrub, it));
947 if (!ooc || osd_scrub_has_window(scrub, ooc))
954 static int osd_preload_exec(struct osd_thread_info *info,
955 struct osd_device *dev, struct osd_iit_param *param,
956 struct osd_idmap_cache *oic, bool *noslot, int rc)
958 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
961 ooc->ooc_cached_items++;
962 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
963 ~OSD_OTABLE_IT_CACHE_MASK;
965 return rc > 0 ? 0 : rc;
968 #define SCRUB_IT_ALL 1
969 #define SCRUB_IT_CRASH 2
971 static void osd_scrub_join(const struct lu_env *env, struct osd_device *dev,
972 __u32 flags, bool inconsistent)
974 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
975 struct ptlrpc_thread *thread = &scrub->os_thread;
976 struct scrub_file *sf = &scrub->os_file;
980 LASSERT(!(flags & SS_AUTO_PARTIAL));
982 down_write(&scrub->os_rwsem);
983 spin_lock(&scrub->os_lock);
984 scrub->os_in_join = 1;
985 if (flags & SS_SET_FAILOUT)
986 sf->sf_param |= SP_FAILOUT;
987 else if (flags & SS_CLEAR_FAILOUT)
988 sf->sf_param &= ~SP_FAILOUT;
990 if (flags & SS_SET_DRYRUN)
991 sf->sf_param |= SP_DRYRUN;
992 else if (flags & SS_CLEAR_DRYRUN)
993 sf->sf_param &= ~SP_DRYRUN;
995 if (flags & SS_RESET) {
996 scrub_file_reset(scrub, dev->od_uuid,
997 inconsistent ? SF_INCONSISTENT : 0);
998 sf->sf_status = SS_SCANNING;
1001 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
1002 scrub->os_full_speed = 1;
1004 scrub->os_full_speed = 0;
1006 if (flags & SS_AUTO_FULL) {
1007 sf->sf_flags |= SF_AUTO;
1008 scrub->os_full_speed = 1;
1010 spin_unlock(&scrub->os_lock);
1012 scrub->os_new_checked = 0;
1013 if (sf->sf_pos_last_checkpoint != 0)
1014 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
1016 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
1018 scrub->os_pos_current = sf->sf_pos_latest_start;
1019 sf->sf_time_latest_start = ktime_get_real_seconds();
1020 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
1021 sf->sf_pos_last_checkpoint = sf->sf_pos_latest_start - 1;
1022 rc = scrub_file_store(env, scrub);
1024 spin_lock(&scrub->os_lock);
1025 scrub->os_waiting = 0;
1026 scrub->os_paused = 0;
1027 scrub->os_partial_scan = 0;
1028 scrub->os_in_join = 0;
1029 scrub->os_full_scrub = 0;
1030 spin_unlock(&scrub->os_lock);
1031 wake_up_all(&thread->t_ctl_waitq);
1032 up_write(&scrub->os_rwsem);
1034 CDEBUG(D_LFSCK, "%s: joined in the OI scrub with flag %u: rc = %d\n",
1035 osd_scrub2name(scrub), flags, rc);
1040 static int osd_inode_iteration(struct osd_thread_info *info,
1041 struct osd_device *dev, __u32 max, bool preload)
1043 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1044 struct ptlrpc_thread *thread = &scrub->os_thread;
1045 struct scrub_file *sf = &scrub->os_file;
1046 osd_iit_next_policy next;
1047 osd_iit_exec_policy exec;
1050 struct osd_iit_param *param;
1059 param = &dev->od_scrub.os_iit_param;
1060 memset(param, 0, sizeof(*param));
1061 param->sb = osd_sb(dev);
1063 while (scrub->os_partial_scan && !scrub->os_in_join) {
1064 struct osd_idmap_cache *oic = NULL;
1066 rc = osd_scrub_next(info, dev, param, &oic, noslot);
1068 case SCRUB_NEXT_EXIT:
1070 case SCRUB_NEXT_CRASH:
1071 RETURN(SCRUB_IT_CRASH);
1072 case SCRUB_NEXT_FATAL:
1074 case SCRUB_NEXT_WAIT: {
1075 struct kstatfs *ksfs = &info->oti_ksfs;
1078 if (dev->od_full_scrub_ratio == OFSR_NEVER ||
1079 unlikely(sf->sf_items_updated_prior == 0))
1082 if (dev->od_full_scrub_ratio == OFSR_DIRECTLY ||
1083 scrub->os_full_scrub) {
1084 osd_scrub_join(info->oti_env, dev,
1085 SS_AUTO_FULL | SS_RESET, true);
1089 rc = param->sb->s_op->statfs(param->sb->s_root, ksfs);
1091 __u64 used = ksfs->f_files - ksfs->f_ffree;
1093 used = div64_u64(used, sf->sf_items_updated_prior);
1094 /* If we hit too much inconsistent OI
1095 * mappings during the partial scan,
1096 * then scan the device completely. */
1097 if (used < dev->od_full_scrub_ratio) {
1098 osd_scrub_join(info->oti_env, dev,
1099 SS_AUTO_FULL | SS_RESET, true);
1105 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) &&
1109 saved_flags = sf->sf_flags;
1110 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
1111 SF_UPGRADE | SF_AUTO);
1112 sf->sf_status = SS_COMPLETED;
1114 thread->t_ctl_waitq,
1115 !thread_is_running(thread) ||
1116 !scrub->os_partial_scan ||
1117 scrub->os_in_join ||
1118 !list_empty(&scrub->os_inconsistent_items));
1119 sf->sf_flags = saved_flags;
1120 sf->sf_status = SS_SCANNING;
1122 if (unlikely(!thread_is_running(thread)))
1125 if (!scrub->os_partial_scan || scrub->os_in_join)
1131 LASSERTF(rc == 0, "rc = %d\n", rc);
1133 osd_scrub_exec(info, dev, param, oic, &noslot, rc);
1140 wait_event_idle(thread->t_ctl_waitq,
1141 !thread_is_running(thread) ||
1142 !scrub->os_in_join);
1144 if (unlikely(!thread_is_running(thread)))
1150 next = osd_scrub_next;
1151 exec = osd_scrub_exec;
1152 pos = &scrub->os_pos_current;
1153 count = &scrub->os_new_checked;
1154 param->start = *pos;
1155 param->bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param->sb);
1157 (*pos - 1) % LDISKFS_INODES_PER_GROUP(param->sb);
1159 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1161 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1163 next = osd_preload_next;
1164 exec = osd_preload_exec;
1165 pos = &ooc->ooc_pos_preload;
1166 count = &ooc->ooc_cached_items;
1167 param = &dev->od_otable_it->ooi_iit_param;
1171 limit = le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count);
1172 while (*pos <= limit && *count < max) {
1173 struct ldiskfs_group_desc *desc;
1174 bool next_group = false;
1176 desc = ldiskfs_get_group_desc(param->sb, param->bg, NULL);
1180 if (desc->bg_flags & cpu_to_le16(LDISKFS_BG_INODE_UNINIT)) {
1185 param->bitmap = ldiskfs_read_inode_bitmap(param->sb, param->bg);
1186 if (!param->bitmap) {
1187 CERROR("%s: fail to read bitmap for %u, "
1188 "scrub will stop, urgent mode\n",
1189 osd_scrub2name(scrub), (__u32)param->bg);
1194 struct osd_idmap_cache *oic = NULL;
1197 ldiskfs_itable_unused_count(param->sb, desc) >=
1198 LDISKFS_INODES_PER_GROUP(param->sb)) {
1203 rc = next(info, dev, param, &oic, noslot);
1205 case SCRUB_NEXT_BREAK:
1208 case SCRUB_NEXT_EXIT:
1209 brelse(param->bitmap);
1211 case SCRUB_NEXT_CRASH:
1212 brelse(param->bitmap);
1213 RETURN(SCRUB_IT_CRASH);
1214 case SCRUB_NEXT_FATAL:
1215 brelse(param->bitmap);
1219 rc = exec(info, dev, param, oic, &noslot, rc);
1220 } while (!rc && *pos <= limit && *count < max);
1223 if (param->bitmap) {
1224 brelse(param->bitmap);
1225 param->bitmap = NULL;
1235 param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
1236 *pos = param->gbase;
1237 param->start = *pos;
1242 RETURN(SCRUB_IT_ALL);
1248 static int osd_otable_it_preload(const struct lu_env *env,
1249 struct osd_otable_it *it)
1251 struct osd_device *dev = it->ooi_dev;
1252 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1253 struct osd_otable_cache *ooc = &it->ooi_cache;
1257 rc = osd_inode_iteration(osd_oti_get(env), dev,
1258 OSD_OTABLE_IT_CACHE_SIZE, true);
1259 if (rc == SCRUB_IT_ALL)
1260 it->ooi_all_cached = 1;
1262 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1263 spin_lock(&scrub->os_lock);
1264 scrub->os_waiting = 0;
1265 wake_up_all(&scrub->os_thread.t_ctl_waitq);
1266 spin_unlock(&scrub->os_lock);
1269 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1272 static int osd_scrub_main(void *args)
1275 struct osd_device *dev = (struct osd_device *)args;
1276 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1277 struct ptlrpc_thread *thread = &scrub->os_thread;
1281 rc = lu_env_init(&env, LCT_LOCAL | LCT_DT_THREAD);
1283 CDEBUG(D_LFSCK, "%s: OI scrub fail to init env: rc = %d\n",
1284 osd_scrub2name(scrub), rc);
1288 rc = osd_scrub_prep(&env, dev);
1290 CDEBUG(D_LFSCK, "%s: OI scrub fail to scrub prep: rc = %d\n",
1291 osd_scrub2name(scrub), rc);
1295 if (!scrub->os_full_speed && !scrub->os_partial_scan) {
1296 struct osd_otable_it *it = dev->od_otable_it;
1297 struct osd_otable_cache *ooc = &it->ooi_cache;
1299 wait_event_idle(thread->t_ctl_waitq,
1300 it->ooi_user_ready ||
1301 !thread_is_running(thread));
1302 if (unlikely(!thread_is_running(thread)))
1305 scrub->os_pos_current = ooc->ooc_pos_preload;
1308 CDEBUG(D_LFSCK, "%s: OI scrub start, flags = 0x%x, pos = %llu\n",
1309 osd_scrub2name(scrub), scrub->os_start_flags,
1310 scrub->os_pos_current);
1312 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1313 if (unlikely(rc == SCRUB_IT_CRASH)) {
1314 spin_lock(&scrub->os_lock);
1315 thread_set_flags(&scrub->os_thread, SVC_STOPPING);
1316 spin_unlock(&scrub->os_lock);
1317 GOTO(out, rc = -EINVAL);
1323 rc = osd_scrub_post(&env, dev, rc);
1324 CDEBUG(D_LFSCK, "%s: OI scrub: stop, pos = %llu: rc = %d\n",
1325 osd_scrub2name(scrub), scrub->os_pos_current, rc);
1328 while (!list_empty(&scrub->os_inconsistent_items)) {
1329 struct osd_inconsistent_item *oii;
1331 oii = list_entry(scrub->os_inconsistent_items.next,
1332 struct osd_inconsistent_item, oii_list);
1333 list_del_init(&oii->oii_list);
1339 spin_lock(&scrub->os_lock);
1340 thread_set_flags(thread, SVC_STOPPED);
1341 wake_up_all(&thread->t_ctl_waitq);
1342 spin_unlock(&scrub->os_lock);
1346 /* initial OI scrub */
1348 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1349 struct dentry *, filldir_t filldir);
1351 #ifdef HAVE_FILLDIR_USE_CTX
1352 static int osd_ios_varfid_fill(struct dir_context *buf, const char *name,
1353 int namelen, loff_t offset, __u64 ino,
1355 static int osd_ios_lf_fill(struct dir_context *buf, const char *name,
1356 int namelen, loff_t offset, __u64 ino,
1358 static int osd_ios_dl_fill(struct dir_context *buf, const char *name,
1359 int namelen, loff_t offset, __u64 ino,
1361 static int osd_ios_uld_fill(struct dir_context *buf, const char *name,
1362 int namelen, loff_t offset, __u64 ino,
1365 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1366 loff_t offset, __u64 ino, unsigned d_type);
1367 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1368 loff_t offset, __u64 ino, unsigned d_type);
1369 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1370 loff_t offset, __u64 ino, unsigned d_type);
1371 static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
1372 loff_t offset, __u64 ino, unsigned d_type);
1376 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1377 struct dentry *dentry, filldir_t filldir);
1379 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1380 struct dentry *dentry, filldir_t filldir);
1383 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1384 struct dentry *dentry, filldir_t filldir);
1388 struct lu_fid olm_fid;
1391 scandir_t olm_scandir;
1392 filldir_t olm_filldir;
1395 /* Add the new introduced local files in the list in the future. */
1396 static const struct osd_lf_map osd_lf_maps[] = {
1399 .olm_name = CATLIST,
1401 .f_seq = FID_SEQ_LOCAL_FILE,
1402 .f_oid = LLOG_CATALOGS_OID,
1404 .olm_flags = OLF_SHOW_NAME,
1405 .olm_namelen = sizeof(CATLIST) - 1,
1410 .olm_name = MOUNT_CONFIGS_DIR,
1412 .f_seq = FID_SEQ_LOCAL_FILE,
1413 .f_oid = MGS_CONFIGS_OID,
1415 .olm_flags = OLF_SCAN_SUBITEMS,
1416 .olm_namelen = sizeof(MOUNT_CONFIGS_DIR) - 1,
1417 .olm_scandir = osd_ios_general_scan,
1418 .olm_filldir = osd_ios_varfid_fill,
1421 /* NIDTBL_VERSIONS */
1423 .olm_name = MGS_NIDTBL_DIR,
1424 .olm_flags = OLF_SCAN_SUBITEMS,
1425 .olm_namelen = sizeof(MGS_NIDTBL_DIR) - 1,
1426 .olm_scandir = osd_ios_general_scan,
1427 .olm_filldir = osd_ios_varfid_fill,
1432 .olm_name = MDT_ORPHAN_DIR,
1433 .olm_namelen = sizeof(MDT_ORPHAN_DIR) - 1,
1440 .f_seq = FID_SEQ_ROOT,
1441 .f_oid = FID_OID_ROOT,
1443 .olm_flags = OLF_SCAN_SUBITEMS | OLF_HIDE_FID,
1444 .olm_namelen = sizeof("ROOT") - 1,
1445 .olm_scandir = osd_ios_ROOT_scan,
1448 /* changelog_catalog */
1450 .olm_name = CHANGELOG_CATALOG,
1451 .olm_namelen = sizeof(CHANGELOG_CATALOG) - 1,
1454 /* changelog_users */
1456 .olm_name = CHANGELOG_USERS,
1457 .olm_namelen = sizeof(CHANGELOG_USERS) - 1,
1464 .f_seq = FID_SEQ_LOCAL_FILE,
1465 .f_oid = FLD_INDEX_OID,
1467 .olm_flags = OLF_SHOW_NAME,
1468 .olm_namelen = sizeof("fld") - 1,
1473 .olm_name = LAST_RCVD,
1475 .f_seq = FID_SEQ_LOCAL_FILE,
1476 .f_oid = LAST_RECV_OID,
1478 .olm_flags = OLF_SHOW_NAME,
1479 .olm_namelen = sizeof(LAST_RCVD) - 1,
1484 .olm_name = REPLY_DATA,
1486 .f_seq = FID_SEQ_LOCAL_FILE,
1487 .f_oid = REPLY_DATA_OID,
1489 .olm_flags = OLF_SHOW_NAME,
1490 .olm_namelen = sizeof(REPLY_DATA) - 1,
1495 .olm_name = LOV_OBJID,
1497 .f_seq = FID_SEQ_LOCAL_FILE,
1498 .f_oid = MDD_LOV_OBJ_OID,
1500 .olm_flags = OLF_SHOW_NAME,
1501 .olm_namelen = sizeof(LOV_OBJID) - 1,
1506 .olm_name = LOV_OBJSEQ,
1508 .f_seq = FID_SEQ_LOCAL_FILE,
1509 .f_oid = MDD_LOV_OBJ_OSEQ,
1511 .olm_flags = OLF_SHOW_NAME,
1512 .olm_namelen = sizeof(LOV_OBJSEQ) - 1,
1517 .olm_name = QMT_DIR,
1518 .olm_flags = OLF_SCAN_SUBITEMS,
1519 .olm_namelen = sizeof(QMT_DIR) - 1,
1520 .olm_scandir = osd_ios_general_scan,
1521 .olm_filldir = osd_ios_varfid_fill,
1526 .olm_name = QSD_DIR,
1527 .olm_flags = OLF_SCAN_SUBITEMS,
1528 .olm_namelen = sizeof(QSD_DIR) - 1,
1529 .olm_scandir = osd_ios_general_scan,
1530 .olm_filldir = osd_ios_varfid_fill,
1535 .olm_name = "seq_ctl",
1537 .f_seq = FID_SEQ_LOCAL_FILE,
1538 .f_oid = FID_SEQ_CTL_OID,
1540 .olm_flags = OLF_SHOW_NAME,
1541 .olm_namelen = sizeof("seq_ctl") - 1,
1546 .olm_name = "seq_srv",
1548 .f_seq = FID_SEQ_LOCAL_FILE,
1549 .f_oid = FID_SEQ_SRV_OID,
1551 .olm_flags = OLF_SHOW_NAME,
1552 .olm_namelen = sizeof("seq_srv") - 1,
1557 .olm_name = HEALTH_CHECK,
1559 .f_seq = FID_SEQ_LOCAL_FILE,
1560 .f_oid = OFD_HEALTH_CHECK_OID,
1562 .olm_flags = OLF_SHOW_NAME,
1563 .olm_namelen = sizeof(HEALTH_CHECK) - 1,
1568 .olm_name = LFSCK_DIR,
1569 .olm_flags = OLF_SCAN_SUBITEMS,
1570 .olm_namelen = sizeof(LFSCK_DIR) - 1,
1571 .olm_scandir = osd_ios_general_scan,
1572 .olm_filldir = osd_ios_varfid_fill,
1575 /* lfsck_bookmark */
1577 .olm_name = LFSCK_BOOKMARK,
1578 .olm_namelen = sizeof(LFSCK_BOOKMARK) - 1,
1583 .olm_name = LFSCK_LAYOUT,
1584 .olm_namelen = sizeof(LFSCK_LAYOUT) - 1,
1587 /* lfsck_namespace */
1589 .olm_name = LFSCK_NAMESPACE,
1590 .olm_namelen = sizeof(LFSCK_NAMESPACE) - 1,
1593 /* OBJECTS, upgrade from old device */
1595 .olm_name = OBJECTS,
1596 .olm_flags = OLF_SCAN_SUBITEMS,
1597 .olm_namelen = sizeof(OBJECTS) - 1,
1598 .olm_scandir = osd_ios_OBJECTS_scan,
1601 /* lquota_v2.user, upgrade from old device */
1603 .olm_name = "lquota_v2.user",
1604 .olm_namelen = sizeof("lquota_v2.user") - 1,
1607 /* lquota_v2.group, upgrade from old device */
1609 .olm_name = "lquota_v2.group",
1610 .olm_namelen = sizeof("lquota_v2.group") - 1,
1613 /* LAST_GROUP, upgrade from old device */
1615 .olm_name = "LAST_GROUP",
1617 .f_seq = FID_SEQ_LOCAL_FILE,
1618 .f_oid = OFD_LAST_GROUP_OID,
1620 .olm_flags = OLF_SHOW_NAME,
1621 .olm_namelen = sizeof("LAST_GROUP") - 1,
1624 /* committed batchid for cross-MDT operation */
1626 .olm_name = "BATCHID",
1628 .f_seq = FID_SEQ_LOCAL_FILE,
1629 .f_oid = BATCHID_COMMITTED_OID,
1631 .olm_flags = OLF_SHOW_NAME,
1632 .olm_namelen = sizeof("BATCHID") - 1,
1635 /* OSP update logs update_log{_dir} use f_seq = FID_SEQ_UPDATE_LOG{_DIR}
1636 * and f_oid = index for their log files. See lu_update_log{_dir}_fid()
1637 * for more details. */
1641 .olm_name = "update_log",
1643 .f_seq = FID_SEQ_UPDATE_LOG,
1645 .olm_flags = OLF_SHOW_NAME | OLF_IDX_IN_FID,
1646 .olm_namelen = sizeof("update_log") - 1,
1649 /* update_log_dir */
1651 .olm_name = "update_log_dir",
1653 .f_seq = FID_SEQ_UPDATE_LOG_DIR,
1655 .olm_flags = OLF_SHOW_NAME | OLF_SCAN_SUBITEMS |
1657 .olm_namelen = sizeof("update_log_dir") - 1,
1658 .olm_scandir = osd_ios_general_scan,
1659 .olm_filldir = osd_ios_uld_fill,
1664 .olm_name = "lost+found",
1666 .f_seq = FID_SEQ_LOCAL_FILE,
1667 .f_oid = OSD_LPF_OID,
1669 .olm_flags = OLF_SCAN_SUBITEMS,
1670 .olm_namelen = sizeof("lost+found") - 1,
1671 .olm_scandir = osd_ios_general_scan,
1672 .olm_filldir = osd_ios_lf_fill,
1677 .olm_name = HSM_ACTIONS,
1682 .olm_name = LUSTRE_NODEMAP_NAME,
1687 .olm_name = INDEX_BACKUP_DIR,
1689 .f_seq = FID_SEQ_LOCAL_FILE,
1690 .f_oid = INDEX_BACKUP_OID,
1692 .olm_flags = OLF_SCAN_SUBITEMS | OLF_NOT_BACKUP,
1693 .olm_namelen = sizeof(INDEX_BACKUP_DIR) - 1,
1694 .olm_scandir = osd_ios_general_scan,
1695 .olm_filldir = osd_ios_varfid_fill,
1703 /* Add the new introduced files under .lustre/ in the list in the future. */
1704 static const struct osd_lf_map osd_dl_maps[] = {
1709 .f_seq = FID_SEQ_DOT_LUSTRE,
1710 .f_oid = FID_OID_DOT_LUSTRE_OBF,
1712 .olm_namelen = sizeof("fid") - 1,
1715 /* .lustre/lost+found */
1717 .olm_name = "lost+found",
1719 .f_seq = FID_SEQ_DOT_LUSTRE,
1720 .f_oid = FID_OID_DOT_LUSTRE_LPF,
1722 .olm_namelen = sizeof("lost+found") - 1,
1730 struct osd_ios_item {
1731 struct list_head oii_list;
1732 struct dentry *oii_dentry;
1733 scandir_t oii_scandir;
1734 filldir_t oii_filldir;
1737 struct osd_ios_filldir_buf {
1738 /* please keep it as first member */
1739 struct dir_context ctx;
1740 struct osd_thread_info *oifb_info;
1741 struct osd_device *oifb_dev;
1742 struct dentry *oifb_dentry;
1747 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1748 scandir_t scandir, filldir_t filldir)
1750 struct osd_ios_item *item;
1753 OBD_ALLOC_PTR(item);
1757 INIT_LIST_HEAD(&item->oii_list);
1758 item->oii_dentry = dget(dentry);
1759 item->oii_scandir = scandir;
1760 item->oii_filldir = filldir;
1761 list_add_tail(&item->oii_list, &dev->od_ios_list);
1766 static bool osd_index_need_recreate(const struct lu_env *env,
1767 struct osd_device *dev, struct inode *inode)
1769 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1770 struct iam_container *bag = &iam->od_container;
1774 rc = iam_container_init(bag, &iam->od_descr, inode);
1778 rc = iam_container_setup(bag);
1779 iam_container_fini(bag);
1786 static void osd_ios_index_register(const struct lu_env *env,
1787 struct osd_device *osd,
1788 const struct lu_fid *fid,
1789 struct inode *inode)
1791 struct osd_directory *iam = &osd_oti_get(env)->oti_iam;
1792 struct iam_container *bag = &iam->od_container;
1793 struct super_block *sb = osd_sb(osd);
1794 struct iam_descr *descr;
1800 /* Index must be a regular file. */
1801 if (!S_ISREG(inode->i_mode))
1804 /* Index's size must be block aligned. */
1805 if (inode->i_size < sb->s_blocksize ||
1806 (inode->i_size & (sb->s_blocksize - 1)) != 0)
1809 iam_container_init(bag, &iam->od_descr, inode);
1810 rc = iam_container_setup(bag);
1814 descr = bag->ic_descr;
1815 /* May be regular file with IAM_LFIX_ROOT_MAGIC matched
1816 * coincidentally, or corrupted index object, skip it. */
1817 if (descr->id_ptr_size != 4)
1820 keysize = descr->id_key_size;
1821 recsize = descr->id_rec_size;
1822 rc = osd_index_register(osd, fid, keysize, recsize);
1827 iam_container_fini(bag);
1829 CDEBUG(D_LFSCK, "%s: index object "DFID" (%u/%u) registered\n",
1830 osd_name(osd), PFID(fid), keysize, recsize);
1833 static void osd_index_restore(const struct lu_env *env, struct osd_device *dev,
1834 struct lustre_index_restore_unit *liru,
1835 void *buf, int bufsize)
1837 struct osd_thread_info *info = osd_oti_get(env);
1838 struct osd_inode_id *id = &info->oti_id;
1839 struct lu_fid *tgt_fid = &liru->liru_cfid;
1840 struct inode *bak_inode = NULL;
1841 struct ldiskfs_dir_entry_2 *de = NULL;
1842 struct buffer_head *bh = NULL;
1843 struct dentry *dentry;
1845 struct lu_fid bak_fid;
1849 lustre_fid2lbx(name, tgt_fid, bufsize);
1850 dentry = osd_child_dentry_by_inode(env, dev->od_index_backup_inode,
1851 name, strlen(name));
1852 bh = osd_ldiskfs_find_entry(dev->od_index_backup_inode,
1853 &dentry->d_name, &de, NULL, NULL);
1855 GOTO(log, rc = PTR_ERR(bh));
1857 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
1859 bak_inode = osd_iget_fid(info, dev, id, &bak_fid);
1860 if (IS_ERR(bak_inode))
1861 GOTO(log, rc = PTR_ERR(bak_inode));
1864 /* The OI mapping for index may be invalid, since it will be
1865 * re-created, not update the OI mapping, just cache it in RAM. */
1866 osd_id_gen(id, liru->liru_clid, OSD_OII_NOGEN);
1867 osd_add_oi_cache(info, dev, id, tgt_fid);
1868 rc = lustre_index_restore(env, &dev->od_dt_dev, &liru->liru_pfid,
1869 tgt_fid, &bak_fid, liru->liru_name,
1870 &dev->od_index_backup_list, &dev->od_lock,
1875 CDEBUG(D_WARNING, "%s: restore index '%s' with "DFID": rc = %d\n",
1876 osd_name(dev), liru->liru_name, PFID(tgt_fid), rc);
1880 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1882 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1883 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1884 * reference the inode, or fixed if it is missing or references another inode.
1887 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1888 struct inode *parent, struct inode *inode,
1889 const struct lu_fid *fid, const char *name,
1890 int namelen, int flags)
1892 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1893 struct osd_inode_id *id = &info->oti_id;
1894 struct osd_inode_id *id2 = &info->oti_id2;
1895 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
1896 struct scrub_file *sf = &scrub->os_file;
1902 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode: rc = -2\n",
1903 osd_name(dev), namelen, name);
1907 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
1908 &info->oti_ost_attrs);
1909 if (rc != 0 && rc != -ENODATA) {
1910 CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
1911 "rc = %d\n", osd_name(dev), rc);
1916 osd_id_gen(id, inode->i_ino, inode->i_generation);
1917 if (rc == -ENODATA) {
1918 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID) {
1919 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1922 if (flags & OLF_IDX_IN_FID) {
1923 LASSERT(dev->od_index >= 0);
1925 tfid.f_oid = dev->od_index;
1928 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1930 CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
1931 "scrub: rc = %d\n", osd_name(dev), rc);
1936 if (lma->lma_compat & LMAC_NOT_IN_OI)
1939 tfid = lma->lma_self_fid;
1940 if (lma->lma_compat & LMAC_IDX_BACKUP &&
1941 osd_index_need_recreate(info->oti_env, dev, inode)) {
1942 struct lu_fid *pfid = &info->oti_fid3;
1944 if (parent == osd_sb(dev)->s_root->d_inode) {
1945 lu_local_obj_fid(pfid, OSD_FS_ROOT_OID);
1947 rc = osd_scrub_get_fid(info, dev, parent, pfid,
1953 rc = lustre_liru_new(&dev->od_index_restore_list, pfid,
1954 &tfid, inode->i_ino, name, namelen);
1959 if (!(flags & OLF_NOT_BACKUP))
1960 osd_ios_index_register(info->oti_env, dev, &tfid,
1964 /* Since this called from iterate_dir() the inode lock will be taken */
1965 rc = osd_oi_lookup(info, dev, &tfid, id2, OI_LOCKED);
1970 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1971 DTO_INDEX_INSERT, true, 0, NULL);
1978 if (osd_id_eq_strict(id, id2))
1981 if (!(sf->sf_flags & SF_INCONSISTENT)) {
1982 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
1983 rc = scrub_file_store(info->oti_env, scrub);
1988 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1989 DTO_INDEX_UPDATE, true, 0, NULL);
1997 * It scans the /lost+found, and for the OST-object (with filter_fid
1998 * or filter_fid_18_23), move them back to its proper /O/<seq>/d<x>.
2000 #ifdef HAVE_FILLDIR_USE_CTX
2001 static int osd_ios_lf_fill(struct dir_context *buf,
2003 static int osd_ios_lf_fill(void *buf,
2005 const char *name, int namelen,
2006 loff_t offset, __u64 ino, unsigned d_type)
2008 struct osd_ios_filldir_buf *fill_buf =
2009 (struct osd_ios_filldir_buf *)buf;
2010 struct osd_thread_info *info = fill_buf->oifb_info;
2011 struct osd_device *dev = fill_buf->oifb_dev;
2012 struct lu_fid *fid = &info->oti_fid;
2013 struct osd_scrub *scrub = &dev->od_scrub;
2014 struct dentry *parent = fill_buf->oifb_dentry;
2015 struct dentry *child;
2016 struct inode *dir = parent->d_inode;
2017 struct inode *inode;
2021 fill_buf->oifb_items++;
2023 /* skip any '.' started names */
2027 scrub->os_lf_scanned++;
2028 child = osd_lookup_one_len(dev, name, parent, namelen);
2029 if (IS_ERR(child)) {
2030 rc = PTR_ERR(child);
2031 CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
2032 osd_name(dev), namelen, name, rc);
2034 } else if (!child->d_inode) {
2036 CDEBUG(D_INODE, "%s: child '%.*s' lacks inode\n",
2037 osd_name(dev), namelen, name);
2041 inode = child->d_inode;
2042 if (S_ISDIR(inode->i_mode)) {
2043 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2046 CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
2047 "rc = %d\n", osd_name(dev), namelen, name, rc);
2051 if (!S_ISREG(inode->i_mode))
2054 rc = osd_scrub_get_fid(info, dev, inode, fid, true);
2055 if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
2056 rc = osd_obj_map_recover(info, dev, dir, child, fid);
2058 CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
2059 "/lost+found.\n", namelen, name, PFID(fid));
2060 scrub->os_lf_repaired++;
2062 CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
2064 osd_name(dev), namelen, name, PFID(fid), rc);
2068 /* XXX: For MDT-objects, we can move them from /lost+found to namespace
2069 * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
2070 * can process them in furtuer. */
2076 scrub->os_lf_failed++;
2078 /* skip the failure to make the scanning to continue. */
2082 #ifdef HAVE_FILLDIR_USE_CTX
2083 static int osd_ios_varfid_fill(struct dir_context *buf,
2085 static int osd_ios_varfid_fill(void *buf,
2087 const char *name, int namelen,
2088 loff_t offset, __u64 ino, unsigned d_type)
2090 struct osd_ios_filldir_buf *fill_buf =
2091 (struct osd_ios_filldir_buf *)buf;
2092 struct osd_device *dev = fill_buf->oifb_dev;
2093 struct dentry *child;
2097 fill_buf->oifb_items++;
2099 /* skip any '.' started names */
2103 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2105 RETURN(PTR_ERR(child));
2107 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2108 fill_buf->oifb_dentry->d_inode, child->d_inode,
2109 NULL, name, namelen, 0);
2110 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
2111 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2112 osd_ios_varfid_fill);
2118 #ifdef HAVE_FILLDIR_USE_CTX
2119 static int osd_ios_dl_fill(struct dir_context *buf,
2121 static int osd_ios_dl_fill(void *buf,
2123 const char *name, int namelen,
2124 loff_t offset, __u64 ino, unsigned d_type)
2126 struct osd_ios_filldir_buf *fill_buf =
2127 (struct osd_ios_filldir_buf *)buf;
2128 struct osd_device *dev = fill_buf->oifb_dev;
2129 const struct osd_lf_map *map;
2130 struct dentry *child;
2134 fill_buf->oifb_items++;
2136 /* skip any '.' started names */
2140 for (map = osd_dl_maps; map->olm_name != NULL; map++) {
2141 if (map->olm_namelen != namelen)
2144 if (strncmp(map->olm_name, name, namelen) == 0)
2148 if (map->olm_name == NULL)
2151 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2153 RETURN(PTR_ERR(child));
2155 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2156 fill_buf->oifb_dentry->d_inode, child->d_inode,
2157 &map->olm_fid, name, namelen, map->olm_flags);
2163 #ifdef HAVE_FILLDIR_USE_CTX
2164 static int osd_ios_uld_fill(struct dir_context *buf,
2166 static int osd_ios_uld_fill(void *buf,
2168 const char *name, int namelen,
2169 loff_t offset, __u64 ino, unsigned d_type)
2171 struct osd_ios_filldir_buf *fill_buf =
2172 (struct osd_ios_filldir_buf *)buf;
2173 struct osd_device *dev = fill_buf->oifb_dev;
2174 struct dentry *child;
2179 fill_buf->oifb_items++;
2181 /* skip any non-DFID format name */
2185 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2187 RETURN(PTR_ERR(child));
2189 /* skip the start '[' */
2190 sscanf(&name[1], SFID, RFID(&tfid));
2191 if (fid_is_sane(&tfid))
2192 rc = osd_ios_scan_one(fill_buf->oifb_info, fill_buf->oifb_dev,
2193 fill_buf->oifb_dentry->d_inode,
2194 child->d_inode, &tfid, name, namelen, 0);
2202 #ifdef HAVE_FILLDIR_USE_CTX
2203 static int osd_ios_root_fill(struct dir_context *buf,
2205 static int osd_ios_root_fill(void *buf,
2207 const char *name, int namelen,
2208 loff_t offset, __u64 ino, unsigned d_type)
2210 struct osd_ios_filldir_buf *fill_buf =
2211 (struct osd_ios_filldir_buf *)buf;
2212 struct osd_device *dev = fill_buf->oifb_dev;
2213 const struct osd_lf_map *map;
2214 struct dentry *child;
2218 fill_buf->oifb_items++;
2220 /* skip any '.' started names */
2224 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
2225 if (map->olm_namelen != namelen)
2228 if (strncmp(map->olm_name, name, namelen) == 0)
2232 if (map->olm_name == NULL)
2235 child = osd_lookup_one_len(dev, name, fill_buf->oifb_dentry, namelen);
2237 RETURN(PTR_ERR(child));
2238 else if (!child->d_inode)
2239 GOTO(out_put, rc = -ENOENT);
2241 if (!(map->olm_flags & OLF_NO_OI))
2242 rc = osd_ios_scan_one(fill_buf->oifb_info, dev,
2243 fill_buf->oifb_dentry->d_inode, child->d_inode,
2244 &map->olm_fid, name, namelen, map->olm_flags);
2245 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
2246 rc = osd_ios_new_item(dev, child, map->olm_scandir,
2255 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
2256 struct dentry *dentry, filldir_t filldir)
2258 struct osd_ios_filldir_buf buf = {
2259 .ctx.actor = filldir,
2262 .oifb_dentry = dentry };
2263 struct file *filp = &info->oti_file;
2264 struct inode *inode = dentry->d_inode;
2265 const struct file_operations *fops = inode->i_fop;
2269 LASSERT(filldir != NULL);
2272 filp->f_path.dentry = dentry;
2273 filp->f_flags |= O_NOATIME;
2274 filp->f_mode = FMODE_64BITHASH | FMODE_NONOTIFY;
2275 filp->f_mapping = inode->i_mapping;
2277 filp->private_data = NULL;
2278 filp->f_cred = current_cred();
2279 filp->f_inode = inode;
2280 rc = osd_security_file_alloc(filp);
2286 rc = iterate_dir(filp, &buf.ctx);
2287 } while (rc >= 0 && buf.oifb_items > 0 &&
2288 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
2289 fops->release(inode, filp);
2295 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
2296 struct dentry *dentry, filldir_t filldir)
2298 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2299 struct scrub_file *sf = &scrub->os_file;
2300 struct dentry *child;
2304 /* It is existing MDT0 device. We only allow the case of object without
2305 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
2306 * can generate IGIF mode FID for the object and related OI mapping. If
2307 * it is on other MDTs, then becuase file-level backup/restore, related
2308 * OI mapping may be invalid already, we do not know which is the right
2309 * FID for the object. We only allow IGIF objects to reside on the MDT0.
2311 * XXX: For the case of object on non-MDT0 device with neither LMA nor
2312 * "fid" xattr, then something crashed. We cannot re-generate the
2313 * FID directly, instead, the OI scrub will scan the OI structure
2314 * and try to re-generate the LMA from the OI mapping. But if the
2315 * OI mapping crashed or lost also, then we have to give up under
2316 * double failure cases.
2318 spin_lock(&scrub->os_lock);
2319 scrub->os_convert_igif = 1;
2320 spin_unlock(&scrub->os_lock);
2321 child = osd_lookup_one_len_unlocked(dev, dot_lustre_name, dentry,
2322 strlen(dot_lustre_name));
2323 if (IS_ERR(child)) {
2324 if (PTR_ERR(child) != -ENOENT)
2325 RETURN(PTR_ERR(child));
2329 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
2330 * so the client will get IGIF for the ".lustre" object when
2333 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
2334 * it does not know whether there are some old clients cached
2335 * the ".lustre" IGIF during the upgrading. Two choices:
2337 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
2338 * It will allow the old connected clients to access the
2339 * ".lustre" with cached IGIF. But it will cause others
2340 * on the MDT failed to check "fid_is_dot_lustre()".
2342 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
2343 * for ".lustre" in spite of whether there are some clients
2344 * cached the ".lustre" IGIF or not. It enables the check
2345 * "fid_is_dot_lustre()" on the MDT, although it will cause
2346 * that the old connected clients cannot access the ".lustre"
2347 * with the cached IGIF.
2349 * Usually, it is rare case for the old connected clients
2350 * to access the ".lustre" with cached IGIF. So we prefer
2351 * to the solution 2).
2353 inode_lock(dentry->d_inode);
2354 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2355 child->d_inode, &LU_DOT_LUSTRE_FID,
2357 strlen(dot_lustre_name), 0);
2358 inode_unlock(dentry->d_inode);
2359 if (rc == -ENOENT) {
2361 /* It is 1.8 MDT device. */
2362 if (!(sf->sf_flags & SF_UPGRADE)) {
2363 scrub_file_reset(scrub, dev->od_uuid,
2365 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2366 rc = scrub_file_store(info->oti_env, scrub);
2370 } else if (rc == 0) {
2371 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2380 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
2381 struct dentry *dentry, filldir_t filldir)
2383 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2384 struct scrub_file *sf = &scrub->os_file;
2385 struct dentry *child;
2389 if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
2390 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2391 rc = scrub_file_store(info->oti_env, scrub);
2396 child = osd_lookup_one_len_unlocked(dev, ADMIN_USR, dentry,
2398 if (IS_ERR(child)) {
2399 rc = PTR_ERR(child);
2401 inode_lock(dentry->d_inode);
2402 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2403 child->d_inode, NULL, ADMIN_USR,
2404 strlen(ADMIN_USR), 0);
2405 inode_unlock(dentry->d_inode);
2409 if (rc != 0 && rc != -ENOENT)
2412 child = osd_lookup_one_len_unlocked(dev, ADMIN_GRP, dentry,
2415 GOTO(out, rc = PTR_ERR(child));
2417 inode_lock(dentry->d_inode);
2418 rc = osd_ios_scan_one(info, dev, dentry->d_inode,
2419 child->d_inode, NULL, ADMIN_GRP,
2420 strlen(ADMIN_GRP), 0);
2421 inode_unlock(dentry->d_inode);
2424 RETURN(rc == -ENOENT ? 0 : rc);
2427 static void osd_initial_OI_scrub(struct osd_thread_info *info,
2428 struct osd_device *dev)
2430 struct osd_ios_item *item = NULL;
2431 scandir_t scandir = osd_ios_general_scan;
2432 filldir_t filldir = osd_ios_root_fill;
2433 struct dentry *dentry = osd_sb(dev)->s_root;
2434 const struct osd_lf_map *map = osd_lf_maps;
2437 /* Lookup IGIF in OI by force for initial OI scrub. */
2438 dev->od_igif_inoi = 1;
2441 /* Don't take inode_lock here since scandir() callbacks
2442 * can call VFS functions which may manully take the
2443 * inode lock itself like iterate_dir(). Since this
2444 * is the case it is best to leave the scandir()
2445 * callbacks to managing the inode lock.
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_lookup_one_len_unlocked(dev, map->olm_name,
2478 osd_sb(dev)->s_root,
2480 if (PTR_ERR(child) == -ENOENT ||
2481 (!IS_ERR(child) && !child->d_inode))
2482 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
2483 NULL, DTO_INDEX_DELETE,
2490 if (!list_empty(&dev->od_index_restore_list)) {
2493 OBD_ALLOC_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2495 CERROR("%s: not enough RAM for rebuild index\n",
2498 while (!list_empty(&dev->od_index_restore_list)) {
2499 struct lustre_index_restore_unit *liru;
2501 liru = list_entry(dev->od_index_restore_list.next,
2502 struct lustre_index_restore_unit,
2504 list_del(&liru->liru_link);
2506 osd_index_restore(info->oti_env, dev, liru,
2507 buf, INDEX_BACKUP_BUFSIZE);
2508 OBD_FREE(liru, liru->liru_len);
2512 OBD_FREE_LARGE(buf, INDEX_BACKUP_BUFSIZE);
2518 char *osd_lf_fid2name(const struct lu_fid *fid)
2520 const struct osd_lf_map *map = osd_lf_maps;
2522 while (map->olm_name != NULL) {
2523 if (!lu_fid_eq(fid, &map->olm_fid)) {
2528 if (map->olm_flags & OLF_SHOW_NAME)
2529 return map->olm_name;
2537 /* OI scrub start/stop */
2539 int osd_scrub_start(const struct lu_env *env, struct osd_device *dev,
2542 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2546 if (dev->od_dt_dev.dd_rdonly)
2549 /* od_otable_mutex: prevent curcurrent start/stop */
2550 mutex_lock(&dev->od_otable_mutex);
2551 rc = scrub_start(osd_scrub_main, scrub, dev, flags);
2552 if (rc == -EALREADY) {
2554 if ((scrub->os_file.sf_flags & SF_AUTO ||
2555 scrub->os_partial_scan) &&
2556 !(flags & SS_AUTO_PARTIAL))
2557 osd_scrub_join(env, dev, flags, false);
2559 mutex_unlock(&dev->od_otable_mutex);
2564 void osd_scrub_stop(struct osd_device *dev)
2566 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2568 /* od_otable_mutex: prevent curcurrent start/stop */
2569 mutex_lock(&dev->od_otable_mutex);
2570 spin_lock(&scrub->os_lock);
2571 scrub->os_paused = 1;
2572 spin_unlock(&scrub->os_lock);
2574 mutex_unlock(&dev->od_otable_mutex);
2577 /* OI scrub setup/cleanup */
2579 static const char osd_scrub_name[] = "OI_scrub";
2581 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
2583 struct osd_thread_info *info = osd_oti_get(env);
2584 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2585 struct lvfs_run_ctxt *ctxt = &dev->od_scrub.os_ctxt;
2586 struct scrub_file *sf = &scrub->os_file;
2587 struct super_block *sb = osd_sb(dev);
2588 struct lvfs_run_ctxt saved;
2590 struct inode *inode;
2591 struct lu_fid *fid = &info->oti_fid;
2592 struct osd_inode_id *id = &info->oti_id;
2593 struct dt_object *obj;
2595 bool restored = false;
2599 memset(&dev->od_scrub, 0, sizeof(struct osd_scrub));
2600 OBD_SET_CTXT_MAGIC(ctxt);
2601 ctxt->pwdmnt = dev->od_mnt;
2602 ctxt->pwd = dev->od_mnt->mnt_root;
2603 ctxt->fs = KERNEL_DS;
2605 init_waitqueue_head(&scrub->os_thread.t_ctl_waitq);
2606 init_rwsem(&scrub->os_rwsem);
2607 spin_lock_init(&scrub->os_lock);
2608 INIT_LIST_HEAD(&scrub->os_inconsistent_items);
2609 scrub->os_name = osd_name(dev);
2611 push_ctxt(&saved, ctxt);
2612 filp = filp_open(osd_scrub_name, O_RDWR |
2613 (dev->od_dt_dev.dd_rdonly ? 0 : O_CREAT), 0644);
2615 pop_ctxt(&saved, ctxt);
2616 RETURN(PTR_ERR(filp));
2619 inode = file_inode(filp);
2620 ldiskfs_set_inode_flag(inode, LDISKFS_INODE_JOURNAL_DATA);
2621 if (!dev->od_dt_dev.dd_rdonly) {
2622 /* 'What the @fid is' is not imporatant, because the object
2623 * has no OI mapping, and only is visible inside the OSD.*/
2624 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2625 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
2627 filp_close(filp, NULL);
2628 pop_ctxt(&saved, ctxt);
2633 osd_id_gen(id, inode->i_ino, inode->i_generation);
2634 osd_add_oi_cache(info, dev, id, fid);
2635 filp_close(filp, NULL);
2636 pop_ctxt(&saved, ctxt);
2638 obj = lu2dt(lu_object_find_slice(env, osd2lu_dev(dev), fid, NULL));
2639 if (IS_ERR_OR_NULL(obj))
2640 RETURN(obj ? PTR_ERR(obj) : -ENOENT);
2642 #ifndef HAVE_S_UUID_AS_UUID_T
2643 memcpy(dev->od_uuid.b, sb->s_uuid, sizeof(dev->od_uuid));
2645 uuid_copy(&dev->od_uuid, &sb->s_uuid);
2647 scrub->os_obj = obj;
2648 rc = scrub_file_load(env, scrub);
2649 if (rc == -ENOENT || rc == -EFAULT) {
2650 scrub_file_init(scrub, dev->od_uuid);
2651 /* If the "/O" dir does not exist when mount (indicated by
2652 * osd_device::od_maybe_new), neither for the "/OI_scrub",
2653 * then it is quite probably that the device is a new one,
2654 * under such case, mark it as SIF_NO_HANDLE_OLD_FID.
2656 * For the rare case that "/O" and "OI_scrub" both lost on
2657 * an old device, it can be found and cleared later.
2659 * For the system with "SIF_NO_HANDLE_OLD_FID", we do not
2660 * need to check "filter_fid_18_23" and to convert it to
2661 * "filter_fid" for each object, and all the IGIF should
2662 * have their FID mapping in OI files already. */
2663 if (dev->od_maybe_new && rc == -ENOENT)
2664 sf->sf_internal_flags = SIF_NO_HANDLE_OLD_FID;
2666 } else if (rc < 0) {
2667 GOTO(cleanup_obj, rc);
2669 if (!uuid_equal(&sf->sf_uuid, &dev->od_uuid)) {
2671 "%s: UUID has been changed from %pU to %pU\n",
2672 osd_dev2name(dev), &sf->sf_uuid, &dev->od_uuid);
2673 scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
2676 } else if (sf->sf_status == SS_SCANNING) {
2677 sf->sf_status = SS_CRASHED;
2681 if ((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) {
2682 LCONSOLE_WARN("%s: invalid oi count %d, set it to %d\n",
2683 osd_dev2name(dev), sf->sf_oi_count,
2685 sf->sf_oi_count = osd_oi_count;
2690 if (sf->sf_pos_last_checkpoint != 0)
2691 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
2693 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
2696 rc = scrub_file_store(env, scrub);
2698 GOTO(cleanup_obj, rc);
2701 /* Initialize OI files. */
2702 rc = osd_oi_init(info, dev, restored);
2704 GOTO(cleanup_obj, rc);
2706 if (!dev->od_dt_dev.dd_rdonly)
2707 osd_initial_OI_scrub(info, dev);
2709 if (sf->sf_flags & SF_UPGRADE ||
2710 !(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID ||
2711 sf->sf_success_count > 0)) {
2712 dev->od_igif_inoi = 0;
2713 dev->od_check_ff = dev->od_is_ost;
2715 dev->od_igif_inoi = 1;
2716 dev->od_check_ff = 0;
2719 if (sf->sf_flags & SF_INCONSISTENT)
2720 /* The 'od_igif_inoi' will be set under the
2722 * 1) new created system, or
2723 * 2) restored from file-level backup, or
2724 * 3) the upgrading completed.
2726 * The 'od_igif_inoi' may be cleared by OI scrub
2727 * later if found that the system is upgrading. */
2728 dev->od_igif_inoi = 1;
2730 if (!dev->od_dt_dev.dd_rdonly &&
2731 dev->od_auto_scrub_interval != AS_NEVER &&
2732 ((sf->sf_status == SS_PAUSED) ||
2733 (sf->sf_status == SS_CRASHED &&
2734 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2735 SF_UPGRADE | SF_AUTO)) ||
2736 (sf->sf_status == SS_INIT &&
2737 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2739 rc = osd_scrub_start(env, dev, SS_AUTO_FULL);
2742 GOTO(cleanup_oi, rc);
2744 /* it is possible that dcache entries may keep objects after they are
2745 * deleted by OSD. While it looks safe this can cause object data to
2746 * stay until umount causing failures in tests calculating free space,
2747 * e.g. replay-ost-single. Since those dcache entries are not used
2748 * anymore let's just free them after use here */
2749 shrink_dcache_sb(sb);
2753 osd_oi_fini(info, dev);
2755 dt_object_put_nocache(env, scrub->os_obj);
2756 scrub->os_obj = NULL;
2761 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
2763 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2765 LASSERT(dev->od_otable_it == NULL);
2767 if (scrub->os_obj != NULL) {
2768 osd_scrub_stop(dev);
2769 dt_object_put_nocache(env, scrub->os_obj);
2770 scrub->os_obj = NULL;
2774 /* object table based iteration APIs */
2776 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
2777 struct dt_object *dt, __u32 attr)
2779 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
2780 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
2781 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
2782 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2783 struct osd_otable_it *it;
2788 /* od_otable_mutex: prevent curcurrent init/fini */
2789 mutex_lock(&dev->od_otable_mutex);
2790 if (dev->od_otable_it != NULL)
2791 GOTO(out, it = ERR_PTR(-EALREADY));
2795 GOTO(out, it = ERR_PTR(-ENOMEM));
2797 dev->od_otable_it = it;
2799 it->ooi_cache.ooc_consumer_idx = -1;
2800 if (flags & DOIF_OUTUSED)
2801 it->ooi_used_outside = 1;
2803 if (flags & DOIF_RESET)
2806 if (valid & DOIV_ERROR_HANDLE) {
2807 if (flags & DOIF_FAILOUT)
2808 start |= SS_SET_FAILOUT;
2810 start |= SS_CLEAR_FAILOUT;
2813 if (valid & DOIV_DRYRUN) {
2814 if (flags & DOIF_DRYRUN)
2815 start |= SS_SET_DRYRUN;
2817 start |= SS_CLEAR_DRYRUN;
2820 rc = scrub_start(osd_scrub_main, scrub, dev, start & ~SS_AUTO_PARTIAL);
2821 if (rc == -EALREADY) {
2822 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2823 } else if (rc < 0) {
2824 dev->od_otable_it = NULL;
2828 /* We have to start from the begining. */
2829 it->ooi_cache.ooc_pos_preload =
2830 LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2836 mutex_unlock(&dev->od_otable_mutex);
2837 return (struct dt_it *)it;
2840 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2842 struct osd_otable_it *it = (struct osd_otable_it *)di;
2843 struct osd_device *dev = it->ooi_dev;
2845 /* od_otable_mutex: prevent curcurrent init/fini */
2846 mutex_lock(&dev->od_otable_mutex);
2847 scrub_stop(&dev->od_scrub.os_scrub);
2848 LASSERT(dev->od_otable_it == it);
2850 dev->od_otable_it = NULL;
2851 mutex_unlock(&dev->od_otable_mutex);
2855 static int osd_otable_it_get(const struct lu_env *env,
2856 struct dt_it *di, const struct dt_key *key)
2861 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2866 osd_otable_it_wakeup(struct lustre_scrub *scrub, struct osd_otable_it *it)
2868 spin_lock(&scrub->os_lock);
2869 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2870 scrub->os_waiting ||
2871 !thread_is_running(&scrub->os_thread))
2872 it->ooi_waiting = 0;
2874 it->ooi_waiting = 1;
2875 spin_unlock(&scrub->os_lock);
2877 return !it->ooi_waiting;
2880 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2882 struct osd_otable_it *it = (struct osd_otable_it *)di;
2883 struct osd_device *dev = it->ooi_dev;
2884 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2885 struct osd_otable_cache *ooc = &it->ooi_cache;
2886 struct ptlrpc_thread *thread = &scrub->os_thread;
2890 LASSERT(it->ooi_user_ready);
2893 if (!thread_is_running(thread) && !it->ooi_used_outside)
2896 if (ooc->ooc_cached_items > 0) {
2897 ooc->ooc_cached_items--;
2898 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2899 ~OSD_OTABLE_IT_CACHE_MASK;
2903 if (it->ooi_all_cached) {
2904 wait_event_idle(thread->t_ctl_waitq,
2905 !thread_is_running(thread));
2909 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2910 spin_lock(&scrub->os_lock);
2911 scrub->os_waiting = 0;
2912 wake_up_all(&scrub->os_thread.t_ctl_waitq);
2913 spin_unlock(&scrub->os_lock);
2916 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2917 wait_event_idle(thread->t_ctl_waitq,
2918 osd_otable_it_wakeup(scrub, it));
2920 if (!thread_is_running(thread) && !it->ooi_used_outside)
2923 rc = osd_otable_it_preload(env, it);
2930 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2931 const struct dt_it *di)
2936 static int osd_otable_it_key_size(const struct lu_env *env,
2937 const struct dt_it *di)
2939 return sizeof(__u64);
2942 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2943 struct dt_rec *rec, __u32 attr)
2945 struct osd_otable_it *it = (struct osd_otable_it *)di;
2946 struct osd_otable_cache *ooc = &it->ooi_cache;
2948 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2950 /* Filter out Invald FID already. */
2951 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2952 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2953 PFID((struct lu_fid *)rec),
2954 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2959 static __u64 osd_otable_it_store(const struct lu_env *env,
2960 const struct dt_it *di)
2962 struct osd_otable_it *it = (struct osd_otable_it *)di;
2963 struct osd_otable_cache *ooc = &it->ooi_cache;
2966 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2967 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2969 hash = ooc->ooc_pos_preload;
2974 * Set the OSD layer iteration start position as the specified hash.
2976 static int osd_otable_it_load(const struct lu_env *env,
2977 const struct dt_it *di, __u64 hash)
2979 struct osd_otable_it *it = (struct osd_otable_it *)di;
2980 struct osd_device *dev = it->ooi_dev;
2981 struct osd_otable_cache *ooc = &it->ooi_cache;
2982 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
2983 struct osd_iit_param *param = &it->ooi_iit_param;
2987 /* Forbid to set iteration position after iteration started. */
2988 if (it->ooi_user_ready)
2991 LASSERT(!scrub->os_partial_scan);
2993 if (hash > OSD_OTABLE_MAX_HASH)
2994 hash = OSD_OTABLE_MAX_HASH;
2996 /* The hash is the last checkpoint position,
2997 * we will start from the next one. */
2998 ooc->ooc_pos_preload = hash + 1;
2999 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
3000 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
3002 it->ooi_user_ready = 1;
3003 if (!scrub->os_full_speed)
3004 wake_up_all(&scrub->os_thread.t_ctl_waitq);
3006 memset(param, 0, sizeof(*param));
3007 param->sb = osd_sb(dev);
3008 param->start = ooc->ooc_pos_preload;
3009 param->bg = (ooc->ooc_pos_preload - 1) /
3010 LDISKFS_INODES_PER_GROUP(param->sb);
3011 param->offset = (ooc->ooc_pos_preload - 1) %
3012 LDISKFS_INODES_PER_GROUP(param->sb);
3013 param->gbase = 1 + param->bg * LDISKFS_INODES_PER_GROUP(param->sb);
3015 /* Unplug OSD layer iteration by the first next() call. */
3016 rc = osd_otable_it_next(env, (struct dt_it *)it);
3021 static int osd_otable_it_key_rec(const struct lu_env *env,
3022 const struct dt_it *di, void *key_rec)
3027 const struct dt_index_operations osd_otable_ops = {
3029 .init = osd_otable_it_init,
3030 .fini = osd_otable_it_fini,
3031 .get = osd_otable_it_get,
3032 .put = osd_otable_it_put,
3033 .next = osd_otable_it_next,
3034 .key = osd_otable_it_key,
3035 .key_size = osd_otable_it_key_size,
3036 .rec = osd_otable_it_rec,
3037 .store = osd_otable_it_store,
3038 .load = osd_otable_it_load,
3039 .key_rec = osd_otable_it_key_rec,
3043 /* high priority inconsistent items list APIs */
3045 #define SCRUB_BAD_OIMAP_DECAY_INTERVAL 60
3047 int osd_oii_insert(struct osd_device *dev, struct osd_idmap_cache *oic,
3050 struct osd_inconsistent_item *oii;
3051 struct osd_scrub *oscrub = &dev->od_scrub;
3052 struct lustre_scrub *lscrub = &oscrub->os_scrub;
3053 struct ptlrpc_thread *thread = &lscrub->os_thread;
3058 if (unlikely(oii == NULL))
3061 INIT_LIST_HEAD(&oii->oii_list);
3062 oii->oii_cache = *oic;
3063 oii->oii_insert = insert;
3065 spin_lock(&lscrub->os_lock);
3066 if (lscrub->os_partial_scan) {
3067 __u64 now = ktime_get_real_seconds();
3069 /* If there haven't been errors in a long time,
3070 * decay old count until either the errors are
3071 * gone or we reach the current interval. */
3072 while (unlikely(oscrub->os_bad_oimap_count > 0 &&
3073 oscrub->os_bad_oimap_time +
3074 SCRUB_BAD_OIMAP_DECAY_INTERVAL < now)) {
3075 oscrub->os_bad_oimap_count >>= 1;
3076 oscrub->os_bad_oimap_time +=
3077 SCRUB_BAD_OIMAP_DECAY_INTERVAL;
3080 oscrub->os_bad_oimap_time = now;
3081 if (++oscrub->os_bad_oimap_count >
3082 dev->od_full_scrub_threshold_rate)
3083 lscrub->os_full_scrub = 1;
3086 if (unlikely(!thread_is_running(thread))) {
3087 spin_unlock(&lscrub->os_lock);
3092 if (list_empty(&lscrub->os_inconsistent_items))
3094 list_add_tail(&oii->oii_list, &lscrub->os_inconsistent_items);
3095 spin_unlock(&lscrub->os_lock);
3098 wake_up_all(&thread->t_ctl_waitq);
3103 int osd_oii_lookup(struct osd_device *dev, const struct lu_fid *fid,
3104 struct osd_inode_id *id)
3106 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
3107 struct osd_inconsistent_item *oii;
3110 spin_lock(&scrub->os_lock);
3111 list_for_each_entry(oii, &scrub->os_inconsistent_items, oii_list) {
3112 if (lu_fid_eq(fid, &oii->oii_cache.oic_fid)) {
3113 *id = oii->oii_cache.oic_lid;
3114 spin_unlock(&scrub->os_lock);
3118 spin_unlock(&scrub->os_lock);
3123 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
3125 struct osd_scrub *scrub = &dev->od_scrub;
3127 scrub_dump(m, &scrub->os_scrub);
3128 seq_printf(m, "lf_scanned: %llu\n"
3130 "lf_failed: %llu\n",
3131 scrub->os_lf_scanned,
3132 scrub->os_scrub.os_file.sf_param & SP_DRYRUN ?
3133 "inconsistent" : "repaired",
3134 scrub->os_lf_repaired,
3135 scrub->os_lf_failed);