+ if (!preload) {
+ struct osd_scrub *scrub = &dev->od_scrub;
+
+ next = osd_scrub_next;
+ exec = osd_scrub_exec;
+ pos = &scrub->os_pos_current;
+ count = &scrub->os_new_checked;
+ } else {
+ struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
+
+ next = osd_preload_next;
+ exec = osd_preload_exec;
+ pos = &ooc->ooc_pos_preload;
+ count = &ooc->ooc_cached_items;
+ }
+ param.sb = osd_sb(dev);
+ limit = le32_to_cpu(LDISKFS_SB(param.sb)->s_es->s_inodes_count);
+
+ while (*pos <= limit && *count < max) {
+ struct osd_idmap_cache *oic = NULL;
+
+ param.bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param.sb);
+ param.offset = (*pos - 1) % LDISKFS_INODES_PER_GROUP(param.sb);
+ param.gbase = 1 + param.bg * LDISKFS_INODES_PER_GROUP(param.sb);
+ param.bitmap = ldiskfs_read_inode_bitmap(param.sb, param.bg);
+ if (param.bitmap == NULL) {
+ CERROR("%.16s: fail to read bitmap for %u, "
+ "scrub will stop, urgent mode\n",
+ LDISKFS_SB(param.sb)->s_es->s_volume_name,
+ (__u32)param.bg);
+ RETURN(-EIO);
+ }
+
+ while (param.offset < LDISKFS_INODES_PER_GROUP(param.sb) &&
+ *count < max) {
+ rc = next(info, dev, ¶m, &oic, noslot);
+ switch (rc) {
+ case SCRUB_NEXT_BREAK:
+ goto next_group;
+ case SCRUB_NEXT_EXIT:
+ brelse(param.bitmap);
+ RETURN(0);
+ case SCRUB_NEXT_CRASH:
+ brelse(param.bitmap);
+ RETURN(SCRUB_IT_CRASH);
+ case SCRUB_NEXT_FATAL:
+ brelse(param.bitmap);
+ RETURN(-EINVAL);
+ }
+
+ 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;
+
+ CDEBUG(D_LFSCK, "OSD pre-loaded: max = %u, preload = %u, rc = %d\n",
+ le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count),
+ ooc->ooc_pos_preload, rc);
+
+ 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;
+ struct super_block *sb = osd_sb(dev);
+ int rc;
+ ENTRY;
+
+ rc = lu_env_init(&env, LCT_LOCAL);
+ if (rc != 0) {
+ CERROR("%.16s: OI scrub, fail to init env, rc = %d\n",
+ LDISKFS_SB(sb)->s_es->s_volume_name, rc);
+ GOTO(noenv, rc);
+ }
+
+ rc = osd_scrub_prep(dev);
+ if (rc != 0) {
+ CERROR("%.16s: OI scrub, fail to scrub prep, rc = %d\n",
+ LDISKFS_SB(sb)->s_es->s_volume_name, rc);
+ GOTO(out, rc);
+ }
+
+ if (!scrub->os_full_speed) {
+ 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, "OI scrub: flags = 0x%x, pos = %u\n",
+ 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:
+ osd_scrub_post(scrub, rc);
+ CDEBUG(D_LFSCK, "OI scrub: stop, rc = %d, pos = %u\n",
+ rc, scrub->os_pos_current);
+
+out:
+ while (!cfs_list_empty(&scrub->os_inconsistent_items)) {
+ struct osd_inconsistent_item *oii;
+
+ oii = cfs_list_entry(scrub->os_inconsistent_items.next,
+ struct osd_inconsistent_item, oii_list);
+ cfs_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);
+
+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_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,
+};
+
+struct osd_lf_map {
+ char *olm_name;
+ struct lu_fid olm_fid;
+ __u16 olm_flags;
+ 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,
+ NULL, NULL },
+
+ /* CONFIGS */
+ { MOUNT_CONFIGS_DIR, { FID_SEQ_LOCAL_FILE, MGS_CONFIGS_OID, 0 },
+ OLF_SCAN_SUBITEMS, osd_ios_general_scan,
+ osd_ios_varfid_fill },
+
+ /* NIDTBL_VERSIONS */
+ { MGS_NIDTBL_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
+ osd_ios_general_scan, osd_ios_varfid_fill },
+
+ /* PENDING */
+ { "PENDING", { 0, 0, 0 }, 0, NULL, NULL },
+
+ /* ROOT */
+ { "ROOT", { FID_SEQ_ROOT, 1, 0 },
+ OLF_SCAN_SUBITEMS | OLF_HIDE_FID, osd_ios_ROOT_scan, NULL },
+
+ /* changelog_catalog */
+ { CHANGELOG_CATALOG, { 0, 0, 0 }, 0, NULL, NULL },
+
+ /* changelog_users */
+ { CHANGELOG_USERS, { 0, 0, 0 }, 0, NULL, NULL },
+
+ /* fld */
+ { "fld", { FID_SEQ_LOCAL_FILE, FLD_INDEX_OID, 0 }, OLF_SHOW_NAME,
+ NULL, NULL },
+
+ /* last_rcvd */
+ { LAST_RCVD, { FID_SEQ_LOCAL_FILE, LAST_RECV_OID, 0 }, OLF_SHOW_NAME,
+ NULL, NULL },
+
+ /* lfsck_bookmark */
+ { "lfsck_bookmark", { 0, 0, 0 }, 0, NULL, NULL },
+
+ /* lov_objid */
+ { LOV_OBJID, { FID_SEQ_LOCAL_FILE, MDD_LOV_OBJ_OID, 0 }, OLF_SHOW_NAME,
+ NULL, NULL },
+
+ /* lov_objseq */
+ { LOV_OBJSEQ, { FID_SEQ_LOCAL_FILE, MDD_LOV_OBJ_OSEQ, 0 },
+ OLF_SHOW_NAME, NULL, NULL },
+
+ /* quota_master */
+ { QMT_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
+ osd_ios_general_scan, osd_ios_varfid_fill },
+
+ /* quota_slave */
+ { QSD_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
+ osd_ios_general_scan, osd_ios_varfid_fill },
+
+ /* seq_ctl */
+ { "seq_ctl", { FID_SEQ_LOCAL_FILE, FID_SEQ_CTL_OID, 0 },
+ OLF_SHOW_NAME, NULL, NULL },
+
+ /* seq_srv */
+ { "seq_srv", { FID_SEQ_LOCAL_FILE, FID_SEQ_SRV_OID, 0 },
+ OLF_SHOW_NAME, NULL, NULL },
+
+ /* health_check */
+ { HEALTH_CHECK, { FID_SEQ_LOCAL_FILE, OFD_HEALTH_CHECK_OID, 0 },
+ OLF_SHOW_NAME, NULL, NULL },
+
+ /* lfsck_namespace */
+ { "lfsck_namespace", { 0, 0, 0 }, 0, NULL, NULL },
+
+ /* OBJECTS, upgrade from old device */
+ { OBJECTS, { 0, 0, 0 }, OLF_SCAN_SUBITEMS, osd_ios_OBJECTS_scan, NULL },
+
+ /* lquota_v2.user, upgrade from old device */
+ { "lquota_v2.user", { 0, 0, 0 }, 0, NULL, NULL },
+
+ /* lquota_v2.group, upgrade from old device */
+ { "lquota_v2.group", { 0, 0, 0 }, 0, NULL, NULL },
+
+ /* LAST_GROUP, upgrade from old device */
+ { "LAST_GROUP", { FID_SEQ_LOCAL_FILE, OFD_LAST_GROUP_OID, 0 },
+ OLF_SHOW_NAME, NULL, NULL },
+
+ /* lost+found */
+ { "lost+found", { 0, 0, 0 }, OLF_SCAN_SUBITEMS | OLF_NO_OI,
+ osd_ios_general_scan, osd_ios_lf_fill },
+
+ { NULL, { 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,
+ NULL, NULL },
+
+ { NULL, { 0, 0, 0 }, 0, NULL, NULL }
+};
+
+struct osd_ios_item {
+ cfs_list_t oii_list;
+ struct dentry *oii_dentry;
+ scandir_t oii_scandir;
+ filldir_t oii_filldir;
+};
+
+struct osd_ios_filldir_buf {
+ 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;
+
+ CDEBUG(D_LFSCK, "init lookup one: parent = %.*s, name = %.*s\n",
+ parent->d_name.len, parent->d_name.name, namelen, name);
+
+ dentry = ll_lookup_one_len(name, parent, namelen);
+ if (!IS_ERR(dentry) && 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);
+
+ CFS_INIT_LIST_HEAD(&item->oii_list);
+ item->oii_dentry = dget(dentry);
+ item->oii_scandir = scandir;
+ item->oii_filldir = filldir;
+ cfs_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;
+
+ CDEBUG(D_LFSCK, "init scan one: ino = %ld\n", inode->i_ino);
+
+ rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
+ if (rc != 0 && rc != -ENODATA)
+ 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;
+ rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
+ if (rc != 0)
+ 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);
+ 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);
+ 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>.
+ */
+static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type)
+{
+ struct osd_ios_filldir_buf *fill_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)) {
+ CWARN("%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)
+ CWARN("%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 {
+ CWARN("%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;
+}
+
+static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type)
+{
+ struct osd_ios_filldir_buf *fill_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);
+}
+
+static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type)
+{
+ struct osd_ios_filldir_buf *fill_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 (strlen(map->olm_name) != 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);
+}
+
+static int osd_ios_root_fill(void *buf, const char *name, int namelen,
+ loff_t offset, __u64 ino, unsigned d_type)
+{
+ struct osd_ios_filldir_buf *fill_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 (strlen(map->olm_name) != 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 = { info, dev, dentry };
+ struct file *filp = &info->oti_it_ea.oie_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_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);
+
+ rc = fops->readdir(filp, &buf, filldir);
+ 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;
+ }
+ }
+ } else {
+ /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
+ * so the client will get IGIF for the ".lustre" object when
+ * the MDT restart.
+ *
+ * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
+ * it does not know whether there are some old clients cached
+ * the ".lustre" IGIF during the upgrading. Two choices:
+ *
+ * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
+ * It will allow the old connected clients to access the
+ * ".lustre" with cached IGIF. But it will cause others
+ * on the MDT failed to check "fid_is_dot_lustre()".
+ *
+ * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
+ * for ".lustre" in spite of whether there are some clients
+ * cached the ".lustre" IGIF or not. It enables the check
+ * "fid_is_dot_lustre()" on the MDT, although it will cause
+ * that the old connected clients cannot access the ".lustre"
+ * with the cached IGIF.
+ *
+ * Usually, it is rare case for the old connected clients
+ * to access the ".lustre" with cached IGIF. So we prefer
+ * to the solution 2). */
+ rc = osd_ios_scan_one(info, dev, child->d_inode,
+ &LU_DOT_LUSTRE_FID, 0);
+ if (rc == 0)
+ rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
+ osd_ios_dl_fill);
+ dput(child);
+ }
+
+ RETURN(rc);
+}
+
+static int
+osd_ios_OBJECTS_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;
+
+ if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
+ sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
+ rc = osd_scrub_file_store(scrub);
+ if (rc != 0)
+ RETURN(rc);
+ }