X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fosd-ldiskfs%2Fosd_handler.c;h=acf36f5c05f5317cf8d9d5a629108d98afe0f77e;hb=f37bce8a573dfc5aac1b9f51f4d5c8314ba05d30;hp=554a26da040a6f7646b7150b30caab7f2b2e7939;hpb=33f95f7ae7300f93433bc781845594d292a18b67;p=fs%2Flustre-release.git diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 554a26d..acf36f5 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -285,6 +285,76 @@ osd_idc_find_or_init(const struct lu_env *env, struct osd_device *osd, return idc; } +static void osd_idc_dump_lma(const struct lu_env *env, + struct osd_device *osd, + unsigned long ino, + bool check_in_oi) +{ + struct osd_thread_info *info = osd_oti_get(env); + struct lustre_ost_attrs *loa = &info->oti_ost_attrs; + const struct lu_fid *fid; + struct osd_inode_id lid; + struct inode *inode; + int rc; + + inode = osd_ldiskfs_iget(osd_sb(osd), ino); + if (IS_ERR(inode)) { + CERROR("%s: can't get inode %lu: rc = %d\n", + osd->od_svname, ino, (int)PTR_ERR(inode)); + return; + } + if (is_bad_inode(inode)) { + CERROR("%s: bad inode %lu\n", osd->od_svname, ino); + goto put; + } + rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa); + if (rc) { + CERROR("%s: can't get LMA for %lu: rc = %d\n", + osd->od_svname, ino, rc); + goto put; + } + fid = &loa->loa_lma.lma_self_fid; + LCONSOLE(D_INFO, "%s: "DFID" in inode %lu/%u\n", osd->od_svname, + PFID(fid), ino, (unsigned)inode->i_generation); + if (!check_in_oi) + goto put; + rc = osd_oi_lookup(osd_oti_get(env), osd, fid, &lid, 0); + if (rc) { + CERROR("%s: can't lookup "DFID": rc = %d\n", + osd->od_svname, PFID(fid), rc); + goto put; + } + LCONSOLE(D_INFO, "%s: "DFID" maps to %u/%u\n", osd->od_svname, + PFID(fid), lid.oii_ino, lid.oii_gen); +put: + iput(inode); +} + +static void osd_idc_dump_debug(const struct lu_env *env, + struct osd_device *osd, + const struct lu_fid *fid, + unsigned long ino1, + unsigned long ino2) +{ + struct osd_inode_id lid; + + int rc; + + rc = osd_oi_lookup(osd_oti_get(env), osd, fid, &lid, 0); + if (!rc) { + LCONSOLE(D_INFO, "%s: "DFID" maps to %u/%u\n", + osd->od_svname, PFID(fid), lid.oii_ino, lid.oii_gen); + osd_idc_dump_lma(env, osd, lid.oii_ino, false); + } else { + CERROR("%s: can't lookup "DFID": rc = %d\n", + osd->od_svname, PFID(fid), rc); + } + if (ino1) + osd_idc_dump_lma(env, osd, ino1, true); + if (ino2) + osd_idc_dump_lma(env, osd, ino2, true); +} + /* * lookup mapping for given FID and fill it from the given object. * the object is lolcal by definition. @@ -302,7 +372,12 @@ static int osd_idc_find_and_init(const struct lu_env *env, if (obj->oo_inode == NULL) return 0; if (idc->oic_lid.oii_ino != obj->oo_inode->i_ino) { - LASSERT(idc->oic_lid.oii_ino == 0); + if (idc->oic_lid.oii_ino) { + osd_idc_dump_debug(env, osd, fid, + idc->oic_lid.oii_ino, + obj->oo_inode->i_ino); + return -EINVAL; + } idc->oic_lid.oii_ino = obj->oo_inode->i_ino; idc->oic_lid.oii_gen = obj->oo_inode->i_generation; } @@ -392,12 +467,11 @@ int osd_get_lma(struct osd_thread_info *info, struct inode *inode, lustre_loa_swab(loa, true); /* Check LMA compatibility */ if (lma->lma_incompat & ~LMA_INCOMPAT_SUPP) { - CWARN("%s: unsupported incompat LMA feature(s) %#x " - "for fid = "DFID", ino = %lu\n", + rc = -EOPNOTSUPP; + CWARN("%s: unsupported incompat LMA feature(s) %#x for fid = "DFID", ino = %lu: rc = %d\n", osd_ino2name(inode), lma->lma_incompat & ~LMA_INCOMPAT_SUPP, - PFID(&lma->lma_self_fid), inode->i_ino); - rc = -EOPNOTSUPP; + PFID(&lma->lma_self_fid), inode->i_ino, rc); } } else if (rc == 0) { rc = -ENODATA; @@ -442,10 +516,11 @@ struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev, iput(inode); inode = ERR_PTR(-ESTALE); } else if (is_bad_inode(inode)) { - CWARN("%s: bad inode: ino = %u\n", - osd_dev2name(dev), id->oii_ino); + rc = -ENOENT; + CWARN("%s: bad inode: ino = %u: rc = %d\n", + osd_dev2name(dev), id->oii_ino, rc); iput(inode); - inode = ERR_PTR(-ENOENT); + inode = ERR_PTR(rc); } else if ((rc = osd_attach_jinode(inode))) { iput(inode); inode = ERR_PTR(rc); @@ -484,7 +559,7 @@ int osd_ldiskfs_add_entry(struct osd_thread_info *info, struct osd_device *osd, if (!rc2) { fid = &loa->loa_lma.lma_self_fid; } else if (rc2 == -ENODATA) { - if (unlikely(parent == inode->i_sb->s_root->d_inode)) { + if (unlikely(is_root_inode(parent))) { fid = &info->oti_fid3; lu_local_obj_fid(fid, OSD_FS_ROOT_OID); } else if (!osd->od_is_ost && osd->od_index == 0) { @@ -529,7 +604,7 @@ osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev, if (!rc) { *fid = loa->loa_lma.lma_self_fid; } else if (rc == -ENODATA) { - if (unlikely(inode == osd_sb(dev)->s_root->d_inode)) + if (unlikely(is_root_inode(inode))) lu_local_obj_fid(fid, OSD_FS_ROOT_OID); else lu_igif_build(fid, inode->i_ino, inode->i_generation); @@ -858,7 +933,6 @@ struct osd_check_lmv_buf { struct dir_context ctx; struct osd_thread_info *oclb_info; struct osd_device *oclb_dev; - struct osd_idmap_cache *oclb_oic; int oclb_items; bool oclb_found; }; @@ -884,7 +958,6 @@ static int osd_stripe_dir_filldir(void *buf, struct lu_fid *fid = &oti->oti_fid3; struct osd_inode_id *id = &oti->oti_id3; struct osd_device *dev = oclb->oclb_dev; - struct osd_idmap_cache *oic = oclb->oclb_oic; struct inode *inode; oclb->oclb_items++; @@ -907,10 +980,7 @@ static int osd_stripe_dir_filldir(void *buf, iput(inode); osd_add_oi_cache(oti, dev, id, fid); - oic->oic_fid = *fid; - oic->oic_lid = *id; - oic->oic_dev = dev; - osd_oii_insert(dev, oic, true); + osd_oii_insert(dev, fid, id, true); oclb->oclb_found = true; return 1; @@ -953,7 +1023,7 @@ static int osd_stripe_dir_filldir(void *buf, * the correct OI mapping for the slave MDT-object. */ static int osd_check_lmv(struct osd_thread_info *oti, struct osd_device *dev, - struct inode *inode, struct osd_idmap_cache *oic) + struct inode *inode) { struct lu_buf *buf = &oti->oti_big_buf; struct dentry *dentry = &oti->oti_obj_dentry; @@ -963,7 +1033,6 @@ static int osd_check_lmv(struct osd_thread_info *oti, struct osd_device *dev, .ctx.actor = osd_stripe_dir_filldir, .oclb_info = oti, .oclb_dev = dev, - .oclb_oic = oic, .oclb_found = false, }; int rc = 0; @@ -1016,10 +1085,10 @@ again: out: if (rc < 0) - CDEBUG(D_LFSCK, "%s: fail to check LMV EA, inode = %lu/%u," - DFID": rc = %d\n", osd_ino2name(inode), - inode->i_ino, inode->i_generation, - PFID(&oic->oic_fid), rc); + CDEBUG(D_LFSCK, + "%s: cannot check LMV, ino = %lu/%u: rc = %d\n", + osd_ino2name(inode), inode->i_ino, inode->i_generation, + rc); else rc = 0; @@ -1052,7 +1121,13 @@ static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj, LINVRNT(osd_invariant(obj)); LASSERT(obj->oo_inode == NULL); - LASSERTF(fid_is_sane(fid) || fid_is_idif(fid), DFID"\n", PFID(fid)); + + if (fid_is_sane(fid) == 0) { + CERROR("%s: invalid FID "DFID"\n", ldev->ld_obd->obd_name, + PFID(fid)); + dump_stack(); + RETURN(-EINVAL); + } dev = osd_dev(ldev); scrub = &dev->od_scrub.os_scrub; @@ -1171,16 +1246,15 @@ trigger: if (scrub->os_partial_scan && !scrub->os_in_join) goto join; - osd_add_oi_cache(info, dev, id, fid); if (IS_ERR_OR_NULL(inode) || result) { - osd_oii_insert(dev, oic, result == -ENOENT); + osd_oii_insert(dev, fid, id, result == -ENOENT); GOTO(out, result = -EINPROGRESS); } LASSERT(remote); LASSERT(obj->oo_inode == inode); - osd_oii_insert(dev, oic, true); + osd_oii_insert(dev, fid, id, true); goto found; } @@ -1202,16 +1276,15 @@ join: if (rc1 && rc1 != -EALREADY) GOTO(out, result = -EREMCHG); - osd_add_oi_cache(info, dev, id, fid); if (IS_ERR_OR_NULL(inode) || result) { - osd_oii_insert(dev, oic, result == -ENOENT); + osd_oii_insert(dev, fid, id, result == -ENOENT); GOTO(out, result = -EINPROGRESS); } LASSERT(remote); LASSERT(obj->oo_inode == inode); - osd_oii_insert(dev, oic, true); + osd_oii_insert(dev, fid, id, true); goto found; check_lma: @@ -1308,6 +1381,8 @@ check_lma: if (saved_ino == id->oii_ino && saved_gen == id->oii_gen) { result = -EREMCHG; + osd_scrub_refresh_mapping(info, dev, fid, id, DTO_INDEX_DELETE, + true, 0, NULL); goto trigger; } @@ -1342,7 +1417,7 @@ found: if (S_ISDIR(inode->i_mode) && (flags & SS_AUTO_PARTIAL || sf->sf_status == SS_SCANNING)) - osd_check_lmv(info, dev, inode, oic); + osd_check_lmv(info, dev, inode); result = osd_attach_jinode(inode); if (result) @@ -1757,6 +1832,7 @@ static struct thandle *osd_trans_create(const struct lu_env *env, th->th_dev = d; th->th_result = 0; oh->ot_credits = 0; + oh->oh_declared_ext = 0; INIT_LIST_HEAD(&oh->ot_commit_dcb_list); INIT_LIST_HEAD(&oh->ot_stop_dcb_list); INIT_LIST_HEAD(&oh->ot_trunc_locks); @@ -2040,6 +2116,7 @@ static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt, if (unlikely(remove_agents != 0)) osd_process_scheduled_agent_removals(env, osd); + LASSERT(oti->oti_ins_cache_depth > 0); oti->oti_ins_cache_depth--; /* reset OI cache for safety */ if (oti->oti_ins_cache_depth == 0) @@ -2346,13 +2423,12 @@ static void osd_conf_get(const struct lu_env *env, OBD_CKSUM_T10IP512 : OBD_CKSUM_T10IP4K; } else { - CERROR("%s: unsupported checksum type of " - "T10PI type '%s'", + CERROR("%s: unsupported checksum type of T10PI type '%s'\n", d->od_svname, name); } } else { - CERROR("%s: unsupported T10PI type '%s'", + CERROR("%s: unsupported T10PI type '%s'\n", d->od_svname, name); } } @@ -2808,9 +2884,9 @@ static int osd_declare_attr_set(const struct lu_env *env, bool ignore_edquot = !(attr->la_flags & LUSTRE_SET_SYNC_FL); if (!ignore_edquot) - CDEBUG(D_QUOTA, "%s: enforce quota on UID %u, GID %u" - "(the quota space is %lld)\n", - obj->oo_inode->i_sb->s_id, attr->la_uid, + CDEBUG(D_QUOTA, + "%s: enforce quota on UID %u, GID %u (quota space is %lld)\n", + osd_ino2name(obj->oo_inode), attr->la_uid, attr->la_gid, bspace); /* USERQUOTA */ @@ -3003,9 +3079,8 @@ static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr, rc = dquot_transfer(inode, &iattr); if (rc) { - CERROR("%s: quota transfer failed: rc = %d. Is quota " - "enforcement enabled on the ldiskfs " - "filesystem?\n", inode->i_sb->s_id, rc); + CERROR("%s: quota transfer failed. Is quota enforcement enabled on the ldiskfs filesystem? rc = %d\n", + osd_ino2name(inode), rc); return rc; } } @@ -3019,9 +3094,8 @@ static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr, rc = -ENOTSUPP; #endif if (rc) { - CERROR("%s: quota transfer failed: rc = %d. Is project " - "enforcement enabled on the ldiskfs " - "filesystem?\n", inode->i_sb->s_id, rc); + CERROR("%s: quota transfer failed. Is project enforcement enabled on the ldiskfs filesystem? rc = %d\n", + osd_ino2name(inode), rc); return rc; } } @@ -3145,12 +3219,21 @@ static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj, struct osd_thandle *oth; struct dt_object *parent = NULL; struct inode *inode; - uid_t owner[2] = {0, 0}; + struct iattr iattr = { + .ia_valid = ATTR_UID | ATTR_GID | + ATTR_CTIME | ATTR_MTIME | ATTR_ATIME, + .ia_ctime.tv_sec = attr->la_ctime, + .ia_mtime.tv_sec = attr->la_mtime, + .ia_atime.tv_sec = attr->la_atime, + .ia_uid = GLOBAL_ROOT_UID, + .ia_gid = GLOBAL_ROOT_GID, + }; + const struct osd_timespec omit = { .tv_nsec = UTIME_OMIT }; if (attr->la_valid & LA_UID) - owner[0] = attr->la_uid; + iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid); if (attr->la_valid & LA_GID) - owner[1] = attr->la_gid; + iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid); LINVRNT(osd_invariant(obj)); LASSERT(obj->oo_inode == NULL); @@ -3170,10 +3253,18 @@ static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj, !dt_object_remote(hint->dah_parent)) parent = hint->dah_parent; + /* if a time component is not valid set it to UTIME_OMIT */ + if (!(attr->la_valid & LA_CTIME)) + iattr.ia_ctime = omit; + if (!(attr->la_valid & LA_MTIME)) + iattr.ia_mtime = omit; + if (!(attr->la_valid & LA_ATIME)) + iattr.ia_atime = omit; + inode = ldiskfs_create_inode(oth->ot_handle, parent ? osd_dt_obj(parent)->oo_inode : osd_sb(osd)->s_root->d_inode, - mode, owner); + mode, &iattr); if (!IS_ERR(inode)) { /* Do not update file c/mtime in ldiskfs. */ inode->i_flags |= S_NOCMTIME; @@ -3460,6 +3551,9 @@ static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj, LASSERT(obj->oo_inode != NULL); + if (CFS_FAIL_CHECK(OBD_FAIL_OSD_OI_ENOSPC)) + return -ENOSPC; + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(oh->ot_handle); osd_trans_exec_op(env, th, OSD_OT_INSERT); @@ -3818,6 +3912,9 @@ static int osd_add_dot_dotdot_internal(struct osd_thread_info *info, __u32 saved_nlink = dir->i_nlink; int rc; + if (OBD_FAIL_CHECK(OBD_FAIL_OSD_DOTDOT_ENOSPC)) + return -ENOSPC; + dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2; osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid); @@ -3858,7 +3955,15 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env, struct osd_thread_info *info = osd_oti_get(env); struct inode *local; struct osd_thandle *oh; - uid_t own[2] = {0, 0}; + struct iattr iattr = { + .ia_valid = ATTR_UID | ATTR_GID | + ATTR_CTIME | ATTR_MTIME | ATTR_ATIME, + .ia_ctime.tv_nsec = UTIME_OMIT, + .ia_mtime.tv_nsec = UTIME_OMIT, + .ia_atime.tv_nsec = UTIME_OMIT, + .ia_uid = GLOBAL_ROOT_UID, + .ia_gid = GLOBAL_ROOT_GID, + }; int rc; ENTRY; @@ -3867,7 +3972,8 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env, oh = container_of(th, struct osd_thandle, ot_super); LASSERT(oh->ot_handle->h_transaction != NULL); - local = ldiskfs_create_inode(oh->ot_handle, pobj->oo_inode, type, own); + local = ldiskfs_create_inode(oh->ot_handle, pobj->oo_inode, + type, &iattr); if (IS_ERR(local)) { CERROR("%s: create local error %d\n", osd_name(osd), (int)PTR_ERR(local)); @@ -3887,8 +3993,8 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env, */ if (S_ISLNK(type)) { BUILD_BUG_ON(LDISKFS_N_BLOCKS * 4 < FID_LEN + 1); - rc = snprintf((char *)LDISKFS_I(local)->i_data, - LDISKFS_N_BLOCKS * 4, DFID, PFID(fid)); + rc = scnprintf((char *)LDISKFS_I(local)->i_data, + LDISKFS_N_BLOCKS * 4, DFID, PFID(fid)); i_size_write(local, rc); LDISKFS_I(local)->i_disksize = rc; @@ -3901,9 +4007,8 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env, i_projid_read(pobj->oo_inode) != 0) { rc = osd_transfer_project(local, 0, th); if (rc) { - CERROR("%s: quota transfer failed: rc = %d. Is project " - "quota enforcement enabled on the ldiskfs " - "filesystem?\n", local->i_sb->s_id, rc); + CERROR("%s: quota transfer failed:. Is project quota enforcement enabled on the ldiskfs filesystem? rc = %d\n", + osd_ino2name(local), rc); RETURN(ERR_PTR(rc)); } } @@ -4067,8 +4172,21 @@ static int osd_create(const struct lu_env *env, struct dt_object *dt, obj->oo_dt.do_body_ops = &osd_body_ops; } - if (!result && !CFS_FAIL_CHECK(OBD_FAIL_OSD_NO_OI_ENTRY)) + if (!result && !CFS_FAIL_CHECK(OBD_FAIL_OSD_NO_OI_ENTRY)) { + struct inode *inode = obj->oo_inode; + result = __osd_oi_insert(env, obj, fid, th); + if (result && inode) { + spin_lock(&obj->oo_guard); + clear_nlink(inode); + spin_unlock(&obj->oo_guard); + osd_dirty_inode(inode, I_DIRTY_DATASYNC); + ldiskfs_set_inode_state(inode, + LDISKFS_STATE_LUSTRE_DESTROY); + iput(inode); + obj->oo_inode = NULL; + } + } /* * a small optimization - dt_insert() isn't usually applied @@ -4092,6 +4210,7 @@ static int osd_declare_ref_add(const struct lu_env *env, struct dt_object *dt, struct thandle *handle) { struct osd_thandle *oh; + int rc; /* it's possible that object doesn't exist yet */ LASSERT(handle != NULL); @@ -4102,9 +4221,10 @@ static int osd_declare_ref_add(const struct lu_env *env, struct dt_object *dt, osd_trans_declare_op(env, oh, OSD_OT_REF_ADD, osd_dto_credits_noquota[DTO_ATTR_SET_BASE]); - osd_idc_find_and_init(env, osd_dev(dt->do_lu.lo_dev), osd_dt_obj(dt)); + rc = osd_idc_find_and_init(env, osd_dev(dt->do_lu.lo_dev), + osd_dt_obj(dt)); - return 0; + return rc; } /* @@ -4834,6 +4954,10 @@ static int osd_invalidate(const struct lu_env *env, struct dt_object *dt) return 0; } +static bool osd_check_stale(struct dt_object *dt) +{ + return false; +} /* * Index operations. */ @@ -5022,6 +5146,7 @@ static const struct dt_object_operations osd_obj_ops = { .do_xattr_list = osd_xattr_list, .do_object_sync = osd_object_sync, .do_invalidate = osd_invalidate, + .do_check_stale = osd_check_stale, }; static const struct dt_object_operations osd_obj_otable_it_ops = { @@ -5478,8 +5603,7 @@ static int __osd_ea_add_rec(struct osd_thread_info *info, LASSERT(pobj->oo_inode); ldp = (struct ldiskfs_dentry_param *)info->oti_ldp; - if (unlikely(pobj->oo_inode == - osd_sb(osd_obj2dev(pobj))->s_root->d_inode)) + if (unlikely(osd_object_is_root(pobj))) ldp->edp_magic = 0; else osd_get_ldiskfs_dirent_param(ldp, fid); @@ -5640,11 +5764,9 @@ static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj, static int osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev, - struct osd_idmap_cache *oic) + const struct lu_fid *fid, struct osd_inode_id *id) { struct lustre_scrub *scrub = &dev->od_scrub.os_scrub; - struct lu_fid *fid = &oic->oic_fid; - struct osd_inode_id *id = &oic->oic_lid; struct inode *inode = NULL; int once = 0; bool insert; @@ -5707,7 +5829,7 @@ trigger: } } - rc = osd_oii_insert(dev, oic, insert); + rc = osd_oii_insert(dev, fid, id, insert); /* * There is race condition between osd_oi_lookup and OI scrub. * The OI scrub finished just after osd_oi_lookup() failure. @@ -5720,7 +5842,7 @@ trigger: if (!S_ISDIR(inode->i_mode)) rc = 0; else - rc = osd_check_lmv(oti, dev, inode, oic); + rc = osd_check_lmv(oti, dev, inode); GOTO(out, rc); } @@ -5729,8 +5851,7 @@ trigger: rc = osd_scrub_start(oti->oti_env, dev, SS_AUTO_PARTIAL | SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT); CDEBUG(D_LFSCK | D_CONSOLE | D_WARNING, - "%s: trigger partial OI scrub for RPC inconsistency " - "checking FID "DFID": rc = %d\n", + "%s: trigger partial OI scrub for RPC inconsistency checking FID "DFID": rc = %d\n", osd_dev2name(dev), PFID(fid), rc); if (rc == 0 || rc == -EALREADY) goto again; @@ -5739,18 +5860,17 @@ trigger: GOTO(out, rc); out: - if (inode) - iput(inode); + iput(inode); RETURN(rc); } static int osd_fail_fid_lookup(struct osd_thread_info *oti, struct osd_device *dev, - struct osd_idmap_cache *oic, struct lu_fid *fid, __u32 ino) { struct lustre_ost_attrs *loa = &oti->oti_ost_attrs; + struct osd_idmap_cache *oic = &oti->oti_cache; struct inode *inode; int rc; @@ -5941,13 +6061,12 @@ static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj, if (!IS_ERR(bh)) { struct osd_thread_info *oti = osd_oti_get(env); struct osd_inode_id *id = &oti->oti_id; - struct osd_idmap_cache *oic = &oti->oti_cache; struct osd_device *dev = osd_obj2dev(obj); ino = le32_to_cpu(de->inode); if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP)) { brelse(bh); - rc = osd_fail_fid_lookup(oti, dev, oic, fid, ino); + rc = osd_fail_fid_lookup(oti, dev, fid, ino); GOTO(out, rc); } @@ -5975,19 +6094,24 @@ static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj, osd_id_gen(id, ino, OSD_OII_NOGEN); } - if (rc != 0 || osd_remote_fid(env, dev, fid)) { - fid_zero(&oic->oic_fid); - + if (rc != 0 || osd_remote_fid(env, dev, fid)) GOTO(out, rc); - } - osd_add_oi_cache(osd_oti_get(env), osd_obj2dev(obj), id, fid); - rc = osd_consistency_check(oti, dev, oic); - if (rc == -ENOENT) - fid_zero(&oic->oic_fid); - else + rc = osd_consistency_check(oti, dev, fid, id); + if (rc != -ENOENT) { /* Other error should not affect lookup result. */ rc = 0; + + /* Normal file mapping should be added into OI cache + * after FID in LMA check, but for local files like + * hsm_actions, their FIDs are not stored in OI files, + * see osd_initial_OI_scrub(), and here is the only + * place to load mapping into OI cache. + */ + if (!fid_is_namespace_visible(fid)) + osd_add_oi_cache(osd_oti_get(env), + osd_obj2dev(obj), id, fid); + } } else { rc = PTR_ERR(bh); } @@ -6690,18 +6814,13 @@ static int osd_ldiskfs_it_fill(const struct lu_env *env, filp->f_cred = current_cred(); rc = osd_security_file_alloc(filp); if (rc) - RETURN(rc); + GOTO(unlock, rc); filp->f_flags |= O_NOATIME; filp->f_mode |= FMODE_NONOTIFY; rc = iterate_dir(filp, &buf.ctx); if (rc) - RETURN(rc); - - if (hlock != NULL) - ldiskfs_htree_unlock(hlock); - else - up_read(&obj->oo_ext_idx_sem); + GOTO(unlock, rc); if (it->oie_rd_dirent == 0) { /* @@ -6715,6 +6834,11 @@ static int osd_ldiskfs_it_fill(const struct lu_env *env, it->oie_dirent = it->oie_buf; it->oie_it_dirent = 1; } +unlock: + if (hlock != NULL) + ldiskfs_htree_unlock(hlock); + else + up_read(&obj->oo_ext_idx_sem); RETURN(rc); } @@ -6863,11 +6987,10 @@ osd_dirent_reinsert(const struct lu_env *env, struct osd_device *dev, * That means we lose it! */ if (rc != 0) - CDEBUG(D_LFSCK, "%s: fail to reinsert the dirent, " - "dir = %lu/%u, name = %.*s, "DFID": rc = %d\n", - osd_ino2name(inode), - dir->i_ino, dir->i_generation, namelen, - dentry->d_name.name, PFID(fid), rc); + CDEBUG(D_LFSCK, + "%s: fail to reinsert the dirent, dir = %lu/%u, name = %.*s, "DFID": rc = %d\n", + osd_ino2name(inode), dir->i_ino, dir->i_generation, + namelen, dentry->d_name.name, PFID(fid), rc); RETURN(rc); } @@ -7597,11 +7720,11 @@ static int osd_mount(const struct lu_env *env, const char *name = lustre_cfg_string(cfg, 0); const char *dev = lustre_cfg_string(cfg, 1); const char *opts; - unsigned long page, s_flags, lmd_flags = 0; + unsigned long page, s_flags = 0, lmd_flags = 0; struct page *__page; struct file_system_type *type; char *options = NULL; - char *str; + const char *str; struct osd_thread_info *info = osd_oti_get(env); struct lu_fid *fid = &info->oti_fid; struct inode *inode; @@ -7616,11 +7739,9 @@ static int osd_mount(const struct lu_env *env, RETURN(-E2BIG); strcpy(o->od_mntdev, dev); - str = lustre_cfg_string(cfg, 2); - s_flags = simple_strtoul(str, NULL, 0); - str = strstr(str, ":"); - if (str) - lmd_flags = simple_strtoul(str + 1, NULL, 0); + str = lustre_cfg_buf(cfg, 2); + sscanf(str, "%lu:%lu", &s_flags, &lmd_flags); + opts = lustre_cfg_string(cfg, 3); #ifdef __BIG_ENDIAN if (opts == NULL || strstr(opts, "bigendian_extents") == NULL) { @@ -7670,6 +7791,7 @@ static int osd_mount(const struct lu_env *env, "force_over_256tb", "force_over_512tb", "force_over_1024tb", + "resetoi", NULL }; strncat(options, opts, PAGE_SIZE); @@ -7725,7 +7847,7 @@ static int osd_mount(const struct lu_env *env, } if (lmd_flags & LMD_FLG_DEV_RDONLY) { - LCONSOLE_WARN("%s: not support dev_rdonly on this device", + LCONSOLE_WARN("%s: not support dev_rdonly on this device\n", name); GOTO(out_mnt, rc = -EOPNOTSUPP); @@ -7787,6 +7909,8 @@ static struct lu_device *osd_device_fini(const struct lu_env *env, osd_procfs_fini(o); if (o->od_oi_table != NULL) osd_oi_fini(osd_oti_get(env), o); + if (o->od_extent_bytes_percpu) + free_percpu(o->od_extent_bytes_percpu); osd_obj_map_fini(o); osd_umount(env, o); @@ -7799,8 +7923,10 @@ static int osd_device_init0(const struct lu_env *env, { struct lu_device *l = osd2lu_dev(o); struct osd_thread_info *info; - int rc; int cplen = 0; + char *opts = NULL; + bool restored = false; + int rc; /* if the module was re-loaded, env can loose its keys */ rc = lu_env_refill((struct lu_env *)env); @@ -7828,6 +7954,8 @@ static int osd_device_init0(const struct lu_env *env, o->od_readcache_max_iosize = OSD_READCACHE_MAX_IO_MB << 20; o->od_writethrough_max_iosize = OSD_WRITECACHE_MAX_IO_MB << 20; o->od_auto_scrub_interval = AS_DEFAULT; + /* default fallocate to unwritten extents: LU-14326/LU-14333 */ + o->od_fallocate_zero_blocks = 0; cplen = strlcpy(o->od_svname, lustre_cfg_string(cfg, 4), sizeof(o->od_svname)); @@ -7865,10 +7993,14 @@ static int osd_device_init0(const struct lu_env *env, if (rc != 0) GOTO(out_site, rc); + opts = lustre_cfg_string(cfg, 3); + if (opts && strstr(opts, "resetoi")) + restored = true; + INIT_LIST_HEAD(&o->od_ios_list); /* setup scrub, including OI files initialization */ o->od_in_init = 1; - rc = osd_scrub_setup(env, o); + rc = osd_scrub_setup(env, o, restored); o->od_in_init = 0; if (rc < 0) GOTO(out_site, rc); @@ -7910,6 +8042,12 @@ static int osd_device_init0(const struct lu_env *env, GOTO(out_procfs, rc); } + o->od_extent_bytes_percpu = alloc_percpu(unsigned int); + if (!o->od_extent_bytes_percpu) { + rc = -ENOMEM; + GOTO(out_procfs, rc); + } + RETURN(0); out_procfs: @@ -8257,7 +8395,7 @@ static int __init osd_init(void) (void *)kallsyms_lookup_name("security_file_alloc"); #endif - rc = class_register_type(&osd_obd_device_ops, NULL, true, NULL, + rc = class_register_type(&osd_obd_device_ops, NULL, true, LUSTRE_OSD_LDISKFS_NAME, &osd_device_type); if (rc) { lu_kmem_fini(ldiskfs_caches);