static int osd_oi_index_create_one(struct osd_thread_info *info, struct osd_device *osd, const char *name, struct dt_index_features *feat) { const struct lu_env *env = info->oti_env; struct osd_inode_id *id = &info->oti_id; struct buffer_head *bh; struct inode *inode; struct ldiskfs_dir_entry_2 *de; struct dentry *dentry; struct super_block *sb = osd_sb(osd); struct inode *dir = sb->s_root->d_inode; handle_t *jh; int rc; dentry = osd_child_dentry_by_inode(env, dir, name, strlen(name)); bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, NULL); if (bh) { osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN); brelse(bh); inode = osd_iget(info, osd, id); if (!IS_ERR(inode)) { iput(inode); inode = ERR_PTR(-EEXIST); } return PTR_ERR(inode); } jh = osd_journal_start_sb(sb, LDISKFS_HT_MISC, 100); if (IS_ERR(jh)) return PTR_ERR(jh); inode = ldiskfs_create_inode(jh, dir, (S_IFREG | S_IRUGO | S_IWUSR)); if (IS_ERR(inode)) { ldiskfs_journal_stop(jh); return PTR_ERR(inode); } ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB); unlock_new_inode(inode); if (feat->dif_flags & DT_IND_VARKEY) rc = iam_lvar_create(inode, feat->dif_keysize_max, feat->dif_ptrsize, feat->dif_recsize_max, jh); else rc = iam_lfix_create(inode, feat->dif_keysize_max, feat->dif_ptrsize, feat->dif_recsize_max, jh); dentry = osd_child_dentry_by_inode(env, dir, name, strlen(name)); rc = osd_ldiskfs_add_entry(info, jh, dentry, inode, NULL); ldiskfs_journal_stop(jh); iput(inode); return rc; }
int osd_compat_objid_lookup(struct osd_thread_info *info, struct osd_device *dev, const struct lu_fid *fid, struct osd_inode_id *id) { struct osd_compat_objid *map; struct dentry *d; struct dentry *d_seq; struct ost_id *ostid = &info->oti_ostid; int rc = 0; int dirn; char name[32]; struct ldiskfs_dir_entry_2 *de; struct buffer_head *bh; struct inode *dir; ENTRY; /* on the very first lookup we find and open directories */ map = dev->od_ost_map; LASSERT(map); LASSERT(map->root); fid_ostid_pack(fid, ostid); LASSERT(ostid->oi_seq < MAX_OBJID_GROUP); LASSERT(map->subdir_count > 0); LASSERT(map->groups[ostid->oi_seq].groot); dirn = ostid->oi_id & (map->subdir_count - 1); d = map->groups[ostid->oi_seq].dirs[dirn]; LASSERT(d); sprintf(name, "%llu", ostid->oi_id); d_seq = &info->oti_child_dentry; d_seq->d_parent = d; d_seq->d_name.hash = 0; d_seq->d_name.name = name; /* XXX: we can use rc from sprintf() instead of strlen() */ d_seq->d_name.len = strlen(name); dir = d->d_inode; LOCK_INODE_MUTEX(dir); bh = osd_ldiskfs_find_entry(dir, d_seq, &de, NULL); UNLOCK_INODE_MUTEX(dir); rc = -ENOENT; if (bh) { struct inode *inode; id->oii_ino = le32_to_cpu(de->inode); brelse(bh); id->oii_gen = OSD_OII_NOGEN; inode = osd_iget(info, dev, id); if (IS_ERR(inode)) GOTO(cleanup, rc = PTR_ERR(inode)); rc = 0; id->oii_gen = inode->i_generation; iput(inode); } cleanup: RETURN(rc); }
int osd_oi_insert(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, handle_t *th, enum oi_check_flags flags) { struct lu_fid *oi_fid = &info->oti_fid2; struct osd_inode_id *oi_id = &info->oti_id2; int rc = 0; if (unlikely(fid_is_last_id(fid))) return osd_obj_spec_insert(info, osd, fid, id, th); if (fid_is_on_ost(info, osd, fid, flags) || fid_is_llog(fid)) return osd_obj_map_insert(info, osd, fid, id, th); fid_cpu_to_be(oi_fid, fid); osd_id_pack(oi_id, id); rc = osd_oi_iam_refresh(info, osd_fid2oi(osd, fid), (const struct dt_rec *)oi_id, (const struct dt_key *)oi_fid, th, true); if (rc != 0) { struct inode *inode; struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs; if (rc != -EEXIST) return rc; rc = osd_oi_lookup(info, osd, fid, oi_id, 0); if (rc != 0) return rc; if (unlikely(osd_id_eq(id, oi_id))) return 1; /* Check whether the mapping for oi_id is valid or not. */ inode = osd_iget(info, osd, oi_id); if (IS_ERR(inode)) { rc = PTR_ERR(inode); if (rc == -ENOENT || rc == -ESTALE) goto update; return rc; } /* The EA inode should NOT be in OI, old OI scrub may added * such OI mapping by wrong, replace it. */ if (unlikely(osd_is_ea_inode(inode))) { iput(inode); goto update; } rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma); iput(inode); if (rc == -ENODATA) goto update; if (rc != 0) return rc; if (!(lma->lma_compat & LMAC_NOT_IN_OI) && lu_fid_eq(fid, &lma->lma_self_fid)) { CERROR("%.16s: the FID "DFID" is used by two objects: " "%u/%u %u/%u\n", LDISKFS_SB(osd_sb(osd))->s_es->s_volume_name, PFID(fid), oi_id->oii_ino, oi_id->oii_gen, id->oii_ino, id->oii_gen); return -EEXIST; } update: osd_id_pack(oi_id, id); rc = osd_oi_iam_refresh(info, osd_fid2oi(osd, fid), (const struct dt_rec *)oi_id, (const struct dt_key *)oi_fid, th, false); if (rc != 0) return rc; } if (unlikely(fid_seq(fid) == FID_SEQ_LOCAL_FILE)) rc = osd_obj_spec_insert(info, osd, fid, id, th); return rc; }