+ rc = exec(info, dev, ¶m, oic, &noslot, rc);
+ if (rc != 0) {
+ brelse(param.bitmap);
+ RETURN(rc);
+ }
+ }
+
+next_group:
+ brelse(param.bitmap);
+ }
+
+ if (*pos > limit)
+ RETURN(SCRUB_IT_ALL);
+ RETURN(0);
+}
+
+static int osd_otable_it_preload(const struct lu_env *env,
+ struct osd_otable_it *it)
+{
+ struct osd_device *dev = it->ooi_dev;
+ struct osd_scrub *scrub = &dev->od_scrub;
+ struct osd_otable_cache *ooc = &it->ooi_cache;
+ int rc;
+ ENTRY;
+
+ rc = osd_inode_iteration(osd_oti_get(env), dev,
+ OSD_OTABLE_IT_CACHE_SIZE, true);
+ if (rc == SCRUB_IT_ALL)
+ it->ooi_all_cached = 1;
+
+ if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
+ spin_lock(&scrub->os_lock);
+ scrub->os_waiting = 0;
+ wake_up_all(&scrub->os_thread.t_ctl_waitq);
+ spin_unlock(&scrub->os_lock);
+ }
+
+ RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
+}
+
+static int osd_scrub_main(void *args)
+{
+ struct lu_env env;
+ struct osd_device *dev = (struct osd_device *)args;
+ struct osd_scrub *scrub = &dev->od_scrub;
+ struct ptlrpc_thread *thread = &scrub->os_thread;
+ int rc;
+ ENTRY;
+
+ rc = lu_env_init(&env, LCT_LOCAL);
+ if (rc != 0) {
+ CDEBUG(D_LFSCK, "%.16s: OI scrub fail to init env: rc = %d\n",
+ osd_scrub2name(scrub), rc);
+ GOTO(noenv, rc);
+ }
+
+ rc = osd_scrub_prep(dev);
+ if (rc != 0) {
+ CDEBUG(D_LFSCK, "%.16s: OI scrub fail to scrub prep: rc = %d\n",
+ osd_scrub2name(scrub), rc);
+ GOTO(out, rc);
+ }
+
+ if (!scrub->os_full_speed && !scrub->os_partial_scan) {
+ struct l_wait_info lwi = { 0 };
+ struct osd_otable_it *it = dev->od_otable_it;
+ struct osd_otable_cache *ooc = &it->ooi_cache;
+
+ l_wait_event(thread->t_ctl_waitq,
+ it->ooi_user_ready || !thread_is_running(thread),
+ &lwi);
+ if (unlikely(!thread_is_running(thread)))
+ GOTO(post, rc = 0);
+
+ scrub->os_pos_current = ooc->ooc_pos_preload;
+ }
+
+ CDEBUG(D_LFSCK, "%.16s: OI scrub start, flags = 0x%x, pos = %u\n",
+ osd_scrub2name(scrub), scrub->os_start_flags,
+ scrub->os_pos_current);
+
+ rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
+ if (unlikely(rc == SCRUB_IT_CRASH))
+ GOTO(out, rc = -EINVAL);
+ GOTO(post, rc);
+
+post:
+ rc = osd_scrub_post(scrub, rc);
+ CDEBUG(D_LFSCK, "%.16s: OI scrub: stop, pos = %u: rc = %d\n",
+ osd_scrub2name(scrub), scrub->os_pos_current, rc);
+
+out:
+ while (!list_empty(&scrub->os_inconsistent_items)) {
+ struct osd_inconsistent_item *oii;
+
+ oii = list_entry(scrub->os_inconsistent_items.next,
+ struct osd_inconsistent_item, oii_list);
+ list_del_init(&oii->oii_list);
+ OBD_FREE_PTR(oii);
+ }
+ lu_env_fini(&env);
+
+noenv:
+ spin_lock(&scrub->os_lock);
+ thread_set_flags(thread, SVC_STOPPED);
+ wake_up_all(&thread->t_ctl_waitq);
+ spin_unlock(&scrub->os_lock);
+ return rc;
+}
+
+/* initial OI scrub */
+
+typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
+ struct dentry *, filldir_t filldir);
+
+#ifdef HAVE_FILLDIR_USE_CTX
+static int osd_ios_varfid_fill(struct dir_context *buf, const char *name,
+ int namelen, loff_t offset, __u64 ino,
+ unsigned d_type);
+static int osd_ios_lf_fill(struct dir_context *buf, const char *name,
+ int namelen, loff_t offset, __u64 ino,
+ unsigned d_type);
+static int osd_ios_dl_fill(struct dir_context *buf, const char *name,
+ int namelen, loff_t offset, __u64 ino,
+ unsigned d_type);
+static int osd_ios_uld_fill(struct dir_context *buf, const char *name,
+ int namelen, loff_t offset, __u64 ino,
+ unsigned d_type);
+#else
+static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type);
+static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type);
+static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type);
+static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type);
+#endif
+
+static int
+osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
+ struct dentry *dentry, filldir_t filldir);
+static int
+osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
+ struct dentry *dentry, filldir_t filldir);
+
+static int
+osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
+ struct dentry *dentry, filldir_t filldir);
+
+enum osd_lf_flags {
+ OLF_SCAN_SUBITEMS = 0x0001,
+ OLF_HIDE_FID = 0x0002,
+ OLF_SHOW_NAME = 0x0004,
+ OLF_NO_OI = 0x0008,
+ OLF_IDX_IN_FID = 0x0010,
+};
+
+struct osd_lf_map {
+ char *olm_name;
+ struct lu_fid olm_fid;
+ __u16 olm_flags;
+ __u16 olm_namelen;
+ scandir_t olm_scandir;
+ filldir_t olm_filldir;
+};
+
+/* Add the new introduced local files in the list in the future. */
+static const struct osd_lf_map osd_lf_maps[] = {
+ /* CATALOGS */
+ { CATLIST, { FID_SEQ_LOCAL_FILE, LLOG_CATALOGS_OID, 0 }, OLF_SHOW_NAME,
+ sizeof(CATLIST) - 1, NULL, NULL },
+
+ /* CONFIGS */
+ { MOUNT_CONFIGS_DIR, { FID_SEQ_LOCAL_FILE, MGS_CONFIGS_OID, 0 },
+ OLF_SCAN_SUBITEMS, sizeof(MOUNT_CONFIGS_DIR) - 1,
+ osd_ios_general_scan, osd_ios_varfid_fill },
+
+ /* NIDTBL_VERSIONS */
+ { MGS_NIDTBL_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
+ sizeof(MGS_NIDTBL_DIR) - 1, osd_ios_general_scan,
+ osd_ios_varfid_fill },
+
+ /* PENDING */
+ { "PENDING", { 0, 0, 0 }, 0, sizeof("PENDING") - 1, NULL, NULL },
+
+ /* ROOT */
+ { "ROOT", { FID_SEQ_ROOT, FID_OID_ROOT, 0 },
+ OLF_SCAN_SUBITEMS | OLF_HIDE_FID, sizeof("ROOT") - 1,
+ osd_ios_ROOT_scan, NULL },
+
+ /* changelog_catalog */
+ { CHANGELOG_CATALOG, { 0, 0, 0 }, 0, sizeof(CHANGELOG_CATALOG) - 1,
+ NULL, NULL },
+
+ /* changelog_users */
+ { CHANGELOG_USERS, { 0, 0, 0 }, 0, sizeof(CHANGELOG_USERS) - 1,
+ NULL, NULL },
+
+ /* fld */
+ { "fld", { FID_SEQ_LOCAL_FILE, FLD_INDEX_OID, 0 }, OLF_SHOW_NAME,
+ sizeof("fld") - 1, NULL, NULL },
+
+ /* last_rcvd */
+ { LAST_RCVD, { FID_SEQ_LOCAL_FILE, LAST_RECV_OID, 0 }, OLF_SHOW_NAME,
+ sizeof(LAST_RCVD) - 1, NULL, NULL },
+
+ /* reply_data */
+ { REPLY_DATA, { FID_SEQ_LOCAL_FILE, REPLY_DATA_OID, 0 }, OLF_SHOW_NAME,
+ sizeof(REPLY_DATA) - 1, NULL, NULL },
+
+ /* lov_objid */
+ { LOV_OBJID, { FID_SEQ_LOCAL_FILE, MDD_LOV_OBJ_OID, 0 }, OLF_SHOW_NAME,
+ sizeof(LOV_OBJID) - 1, NULL, NULL },
+
+ /* lov_objseq */
+ { LOV_OBJSEQ, { FID_SEQ_LOCAL_FILE, MDD_LOV_OBJ_OSEQ, 0 },
+ OLF_SHOW_NAME, sizeof(LOV_OBJSEQ) - 1, NULL, NULL },
+
+ /* quota_master */
+ { QMT_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS, sizeof(QMT_DIR) - 1,
+ osd_ios_general_scan, osd_ios_varfid_fill },
+
+ /* quota_slave */
+ { QSD_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS, sizeof(QSD_DIR) - 1,
+ osd_ios_general_scan, osd_ios_varfid_fill },
+
+ /* seq_ctl */
+ { "seq_ctl", { FID_SEQ_LOCAL_FILE, FID_SEQ_CTL_OID, 0 },
+ OLF_SHOW_NAME, sizeof("seq_ctl") - 1, NULL, NULL },
+
+ /* seq_srv */
+ { "seq_srv", { FID_SEQ_LOCAL_FILE, FID_SEQ_SRV_OID, 0 },
+ OLF_SHOW_NAME, sizeof("seq_srv") - 1, NULL, NULL },
+
+ /* health_check */
+ { HEALTH_CHECK, { FID_SEQ_LOCAL_FILE, OFD_HEALTH_CHECK_OID, 0 },
+ OLF_SHOW_NAME, sizeof(HEALTH_CHECK) - 1, NULL, NULL },
+
+ /* LFSCK */
+ { LFSCK_DIR, { 0, 0, 0 }, 0, sizeof(LFSCK_DIR) - 1,
+ osd_ios_general_scan, osd_ios_varfid_fill },
+
+ /* lfsck_bookmark */
+ { LFSCK_BOOKMARK, { 0, 0, 0 }, 0, sizeof(LFSCK_BOOKMARK) - 1,
+ NULL, NULL },
+
+ /* lfsck_layout */
+ { LFSCK_LAYOUT, { 0, 0, 0 }, 0, sizeof(LFSCK_LAYOUT) - 1,
+ NULL, NULL },
+
+ /* lfsck_namespace */
+ { LFSCK_NAMESPACE, { 0, 0, 0 }, 0, sizeof(LFSCK_NAMESPACE) - 1,
+ NULL, NULL },
+
+ /* OBJECTS, upgrade from old device */
+ { OBJECTS, { 0, 0, 0 }, OLF_SCAN_SUBITEMS, sizeof(OBJECTS) - 1,
+ osd_ios_OBJECTS_scan, NULL },
+
+ /* lquota_v2.user, upgrade from old device */
+ { "lquota_v2.user", { 0, 0, 0 }, 0, sizeof("lquota_v2.user") - 1,
+ NULL, NULL },
+
+ /* lquota_v2.group, upgrade from old device */
+ { "lquota_v2.group", { 0, 0, 0 }, 0, sizeof("lquota_v2.group") - 1,
+ NULL, NULL },
+
+ /* LAST_GROUP, upgrade from old device */
+ { "LAST_GROUP", { FID_SEQ_LOCAL_FILE, OFD_LAST_GROUP_OID, 0 },
+ OLF_SHOW_NAME, sizeof("LAST_GROUP") - 1, NULL, NULL },
+
+ /* committed batchid for cross-MDT operation */
+ { "BATCHID", { FID_SEQ_LOCAL_FILE, BATCHID_COMMITTED_OID, 0 },
+ OLF_SHOW_NAME, sizeof("BATCHID") - 1, NULL, NULL },
+
+ /* OSP update logs update_log{_dir} use f_seq = FID_SEQ_UPDATE_LOG{_DIR}
+ * and f_oid = index for their log files. See lu_update_log{_dir}_fid()
+ * for more details. */
+
+ /* update_log */
+ { "update_log", { FID_SEQ_UPDATE_LOG, 0, 0 },
+ OLF_SHOW_NAME | OLF_IDX_IN_FID, sizeof("update_log") - 1,
+ NULL, NULL },
+
+ /* update_log_dir */
+ { "update_log_dir", { FID_SEQ_UPDATE_LOG_DIR, 0, 0 },
+ OLF_SHOW_NAME | OLF_SCAN_SUBITEMS | OLF_IDX_IN_FID,
+ sizeof("update_log_dir") - 1,
+ osd_ios_general_scan, osd_ios_uld_fill },
+
+ /* lost+found */
+ { "lost+found", { FID_SEQ_LOCAL_FILE, OSD_LPF_OID, 0 },
+ OLF_SCAN_SUBITEMS, sizeof("lost+found") - 1,
+ osd_ios_general_scan, osd_ios_lf_fill },
+
+ { NULL, { 0, 0, 0 }, 0, 0, NULL, NULL }
+};
+
+/* Add the new introduced files under .lustre/ in the list in the future. */
+static const struct osd_lf_map osd_dl_maps[] = {
+ /* .lustre/fid */
+ { "fid", { FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE_OBF, 0 }, 0,
+ sizeof("fid") - 1, NULL, NULL },
+
+ /* .lustre/lost+found */
+ { "lost+found", { FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE_LPF, 0 }, 0,
+ sizeof("lost+found") - 1, NULL, NULL },
+
+ { NULL, { 0, 0, 0 }, 0, 0, NULL, NULL }
+};
+
+struct osd_ios_item {
+ struct list_head oii_list;
+ struct dentry *oii_dentry;
+ scandir_t oii_scandir;
+ filldir_t oii_filldir;
+};
+
+struct osd_ios_filldir_buf {
+#ifdef HAVE_DIR_CONTEXT
+ /* please keep it as first member */
+ struct dir_context ctx;
+#endif
+ struct osd_thread_info *oifb_info;
+ struct osd_device *oifb_dev;
+ struct dentry *oifb_dentry;
+};
+
+static inline struct dentry *
+osd_ios_lookup_one_len(const char *name, struct dentry *parent, int namelen)
+{
+ struct dentry *dentry;
+
+ dentry = ll_lookup_one_len(name, parent, namelen);
+ if (IS_ERR(dentry)) {
+ int rc = PTR_ERR(dentry);
+
+ if (rc != -ENOENT)
+ CERROR("Fail to find %.*s in %.*s (%lu/%u): rc = %d\n",
+ namelen, name, parent->d_name.len,
+ parent->d_name.name, parent->d_inode->i_ino,
+ parent->d_inode->i_generation, rc);
+
+ return dentry;
+ }
+
+ if (dentry->d_inode == NULL) {
+ dput(dentry);
+ return ERR_PTR(-ENOENT);
+ }
+
+ return dentry;
+}
+
+static int
+osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
+ scandir_t scandir, filldir_t filldir)
+{
+ struct osd_ios_item *item;
+ ENTRY;
+
+ OBD_ALLOC_PTR(item);
+ if (item == NULL)
+ RETURN(-ENOMEM);
+
+ INIT_LIST_HEAD(&item->oii_list);
+ item->oii_dentry = dget(dentry);
+ item->oii_scandir = scandir;
+ item->oii_filldir = filldir;
+ list_add_tail(&item->oii_list, &dev->od_ios_list);
+
+ RETURN(0);
+}
+
+/**
+ * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
+ *
+ * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
+ * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
+ * reference the inode, or fixed if it is missing or references another inode.
+ */
+static int
+osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
+ struct inode *inode, const struct lu_fid *fid, int flags)
+{
+ struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
+ struct osd_inode_id *id = &info->oti_id;
+ struct osd_inode_id *id2 = &info->oti_id2;
+ struct osd_scrub *scrub = &dev->od_scrub;
+ struct scrub_file *sf = &scrub->os_file;
+ struct lu_fid tfid;
+ int rc;
+ ENTRY;
+
+ rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
+ if (rc != 0 && rc != -ENODATA) {
+ CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
+ "rc = %d\n", osd_name(dev), rc);
+
+ RETURN(rc);
+ }
+
+ osd_id_gen(id, inode->i_ino, inode->i_generation);
+ if (rc == -ENODATA) {
+ if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID) {
+ lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
+ } else {
+ tfid = *fid;
+ if (flags & OLF_IDX_IN_FID) {
+ LASSERT(dev->od_index >= 0);
+
+ tfid.f_oid = dev->od_index;
+ }
+ }
+ rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
+ if (rc != 0) {
+ CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
+ "scrub: rc = %d\n", osd_name(dev), rc);
+
+ RETURN(rc);
+ }
+ } else {
+ if (lma->lma_compat & LMAC_NOT_IN_OI)
+ RETURN(0);
+
+ tfid = lma->lma_self_fid;
+ }
+
+ rc = osd_oi_lookup(info, dev, &tfid, id2, 0);
+ if (rc != 0) {
+ if (rc != -ENOENT)
+ RETURN(rc);
+
+ rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
+ DTO_INDEX_INSERT, true, 0, NULL);
+ if (rc > 0)
+ rc = 0;
+
+ RETURN(rc);
+ }
+
+ if (osd_id_eq_strict(id, id2))
+ RETURN(0);
+
+ if (!(sf->sf_flags & SF_INCONSISTENT)) {
+ osd_scrub_file_reset(scrub,
+ LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
+ SF_INCONSISTENT);
+ rc = osd_scrub_file_store(scrub);
+ if (rc != 0)
+ RETURN(rc);
+ }
+
+ rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
+ DTO_INDEX_UPDATE, true, 0, NULL);
+ if (rc > 0)
+ rc = 0;
+
+ RETURN(rc);
+}
+
+/**
+ * It scans the /lost+found, and for the OST-object (with filter_fid
+ * or filter_fid_old), move them back to its proper /O/<seq>/d<x>.
+ */
+#ifdef HAVE_FILLDIR_USE_CTX
+static int osd_ios_lf_fill(struct dir_context *buf,
+#else
+static int osd_ios_lf_fill(void *buf,
+#endif
+ const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type)
+{
+ struct osd_ios_filldir_buf *fill_buf =
+ (struct osd_ios_filldir_buf *)buf;
+ struct osd_thread_info *info = fill_buf->oifb_info;
+ struct osd_device *dev = fill_buf->oifb_dev;
+ struct lu_fid *fid = &info->oti_fid;
+ struct osd_scrub *scrub = &dev->od_scrub;
+ struct dentry *parent = fill_buf->oifb_dentry;
+ struct dentry *child;
+ struct inode *dir = parent->d_inode;
+ struct inode *inode;
+ int rc;
+ ENTRY;
+
+ /* skip any '.' started names */
+ if (name[0] == '.')
+ RETURN(0);
+
+ scrub->os_lf_scanned++;
+ child = osd_ios_lookup_one_len(name, parent, namelen);
+ if (IS_ERR(child)) {
+ CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
+ osd_name(dev), namelen, name, (int)PTR_ERR(child));
+ RETURN(0);
+ }
+
+ inode = child->d_inode;
+ if (S_ISDIR(inode->i_mode)) {
+ rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
+ osd_ios_lf_fill);
+ if (rc != 0)
+ CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
+ "rc = %d\n", osd_name(dev), namelen, name, rc);
+ GOTO(put, rc);
+ }
+
+ if (!S_ISREG(inode->i_mode))
+ GOTO(put, rc = 0);
+
+ rc = osd_scrub_get_fid(info, dev, inode, fid, true);
+ if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
+ rc = osd_obj_map_recover(info, dev, dir, child, fid);
+ if (rc == 0) {
+ CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
+ "/lost+found.\n", namelen, name, PFID(fid));
+ scrub->os_lf_repaired++;
+ } else {
+ CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
+ DFID": rc = %d\n",
+ osd_name(dev), namelen, name, PFID(fid), rc);
+ }
+ }
+
+ /* XXX: For MDT-objects, we can move them from /lost+found to namespace
+ * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
+ * can process them in furtuer. */
+
+ GOTO(put, rc);
+
+put:
+ if (rc < 0)
+ scrub->os_lf_failed++;
+ dput(child);
+ /* skip the failure to make the scanning to continue. */
+ return 0;
+}
+
+#ifdef HAVE_FILLDIR_USE_CTX
+static int osd_ios_varfid_fill(struct dir_context *buf,
+#else
+static int osd_ios_varfid_fill(void *buf,
+#endif
+ const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type)
+{
+ struct osd_ios_filldir_buf *fill_buf =
+ (struct osd_ios_filldir_buf *)buf;
+ struct osd_device *dev = fill_buf->oifb_dev;
+ struct dentry *child;
+ int rc;
+ ENTRY;
+
+ /* skip any '.' started names */
+ if (name[0] == '.')
+ RETURN(0);
+
+ child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
+ if (IS_ERR(child))
+ RETURN(PTR_ERR(child));
+
+ rc = osd_ios_scan_one(fill_buf->oifb_info, dev, child->d_inode,
+ NULL, 0);
+ if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
+ rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
+ osd_ios_varfid_fill);
+ dput(child);
+
+ RETURN(rc);
+}
+
+#ifdef HAVE_FILLDIR_USE_CTX
+static int osd_ios_dl_fill(struct dir_context *buf,
+#else
+static int osd_ios_dl_fill(void *buf,
+#endif
+ const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type)
+{
+ struct osd_ios_filldir_buf *fill_buf =
+ (struct osd_ios_filldir_buf *)buf;
+ struct osd_device *dev = fill_buf->oifb_dev;
+ const struct osd_lf_map *map;
+ struct dentry *child;
+ int rc = 0;
+ ENTRY;
+
+ /* skip any '.' started names */
+ if (name[0] == '.')
+ RETURN(0);
+
+ for (map = osd_dl_maps; map->olm_name != NULL; map++) {
+ if (map->olm_namelen != namelen)
+ continue;
+
+ if (strncmp(map->olm_name, name, namelen) == 0)
+ break;
+ }
+
+ if (map->olm_name == NULL)
+ RETURN(0);
+
+ child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
+ if (IS_ERR(child))
+ RETURN(PTR_ERR(child));
+
+ rc = osd_ios_scan_one(fill_buf->oifb_info, dev, child->d_inode,
+ &map->olm_fid, map->olm_flags);
+ dput(child);
+
+ RETURN(rc);
+}
+
+#ifdef HAVE_FILLDIR_USE_CTX
+static int osd_ios_uld_fill(struct dir_context *buf,
+#else
+static int osd_ios_uld_fill(void *buf,
+#endif
+ const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type)
+{
+ struct osd_ios_filldir_buf *fill_buf =
+ (struct osd_ios_filldir_buf *)buf;
+ struct dentry *child;
+ struct lu_fid tfid;
+ int rc = 0;
+ ENTRY;
+
+ /* skip any non-DFID format name */
+ if (name[0] != '[')
+ RETURN(0);
+
+ child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
+ if (IS_ERR(child))
+ RETURN(PTR_ERR(child));
+
+ /* skip the start '[' */
+ sscanf(&name[1], SFID, RFID(&tfid));
+ if (fid_is_sane(&tfid))
+ rc = osd_ios_scan_one(fill_buf->oifb_info, fill_buf->oifb_dev,
+ child->d_inode, &tfid, 0);
+ else
+ rc = -EIO;
+ dput(child);
+
+ RETURN(rc);
+}
+
+#ifdef HAVE_FILLDIR_USE_CTX
+static int osd_ios_root_fill(struct dir_context *buf,
+#else
+static int osd_ios_root_fill(void *buf,
+#endif
+ const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type)
+{
+ struct osd_ios_filldir_buf *fill_buf =
+ (struct osd_ios_filldir_buf *)buf;
+ struct osd_device *dev = fill_buf->oifb_dev;
+ const struct osd_lf_map *map;
+ struct dentry *child;
+ int rc = 0;
+ ENTRY;
+
+ /* skip any '.' started names */
+ if (name[0] == '.')
+ RETURN(0);
+
+ for (map = osd_lf_maps; map->olm_name != NULL; map++) {
+ if (map->olm_namelen != namelen)
+ continue;
+
+ if (strncmp(map->olm_name, name, namelen) == 0)
+ break;
+ }
+
+ if (map->olm_name == NULL)
+ RETURN(0);
+
+ child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
+ if (IS_ERR(child))
+ RETURN(PTR_ERR(child));
+
+ if (!(map->olm_flags & OLF_NO_OI))
+ rc = osd_ios_scan_one(fill_buf->oifb_info, dev, child->d_inode,
+ &map->olm_fid, map->olm_flags);
+ if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
+ rc = osd_ios_new_item(dev, child, map->olm_scandir,
+ map->olm_filldir);
+ dput(child);
+
+ RETURN(rc);
+}
+
+static int
+osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
+ struct dentry *dentry, filldir_t filldir)
+{
+ struct osd_ios_filldir_buf buf = {
+#ifdef HAVE_DIR_CONTEXT
+ .ctx.actor = filldir,
+#endif
+ .oifb_info = info,
+ .oifb_dev = dev,
+ .oifb_dentry = dentry };
+ struct file *filp = &info->oti_file;
+ struct inode *inode = dentry->d_inode;
+ const struct file_operations *fops = inode->i_fop;
+ int rc;
+ ENTRY;
+
+ LASSERT(filldir != NULL);
+
+ filp->f_pos = 0;
+ filp->f_path.dentry = dentry;
+ filp->f_mode = FMODE_64BITHASH;
+ filp->f_mapping = inode->i_mapping;
+ filp->f_op = fops;
+ filp->private_data = NULL;
+ set_file_inode(filp, inode);
+
+#ifdef HAVE_DIR_CONTEXT
+ buf.ctx.pos = filp->f_pos;
+ rc = fops->iterate(filp, &buf.ctx);
+ filp->f_pos = buf.ctx.pos;
+#else
+ rc = fops->readdir(filp, &buf, filldir);
+#endif
+ fops->release(inode, filp);
+
+ RETURN(rc);
+}
+
+static int
+osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
+ struct dentry *dentry, filldir_t filldir)
+{
+ struct osd_scrub *scrub = &dev->od_scrub;
+ struct scrub_file *sf = &scrub->os_file;
+ struct dentry *child;
+ int rc;
+ ENTRY;
+
+ /* It is existing MDT0 device. We only allow the case of object without
+ * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
+ * can generate IGIF mode FID for the object and related OI mapping. If
+ * it is on other MDTs, then becuase file-level backup/restore, related
+ * OI mapping may be invalid already, we do not know which is the right
+ * FID for the object. We only allow IGIF objects to reside on the MDT0.
+ *
+ * XXX: For the case of object on non-MDT0 device with neither LMA nor
+ * "fid" xattr, then something crashed. We cannot re-generate the
+ * FID directly, instead, the OI scrub will scan the OI structure
+ * and try to re-generate the LMA from the OI mapping. But if the
+ * OI mapping crashed or lost also, then we have to give up under
+ * double failure cases. */
+ scrub->os_convert_igif = 1;
+ child = osd_ios_lookup_one_len(dot_lustre_name, dentry,
+ strlen(dot_lustre_name));
+ if (IS_ERR(child)) {
+ rc = PTR_ERR(child);
+ if (rc == -ENOENT) {
+ /* It is 1.8 MDT device. */
+ if (!(sf->sf_flags & SF_UPGRADE)) {
+ osd_scrub_file_reset(scrub,
+ LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
+ SF_UPGRADE);
+ sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
+ rc = osd_scrub_file_store(scrub);
+ } else {
+ rc = 0;