int fld_index_init(struct lu_server_fld *fld, const struct lu_env *env, struct dt_device *dt) { struct dt_object *dt_obj; struct lu_fid fid; int rc; ENTRY; dt_obj = dt_store_open(env, dt, "", fld_index_name, &fid); if (!IS_ERR(dt_obj)) { fld->lsf_obj = dt_obj; rc = dt_obj->do_ops->do_index_try(env, dt_obj, &fld_index_features); if (rc == 0) { LASSERT(dt_obj->do_index_ops != NULL); rc = fld_insert_igif_fld(fld, env); if (rc != 0) { CERROR("insert igif in fld! = %d\n", rc); lu_object_put(env, &dt_obj->do_lu); fld->lsf_obj = NULL; } } else CERROR("%s: File \"%s\" is not an index!\n", fld->lsf_name, fld_index_name); } else { CERROR("%s: Can't find \"%s\" obj %d\n", fld->lsf_name, fld_index_name, (int)PTR_ERR(dt_obj)); rc = PTR_ERR(dt_obj); } RETURN(rc); }
int fld_index_init(const struct lu_env *env, struct lu_server_fld *fld, struct dt_device *dt) { struct dt_object *dt_obj = NULL; struct lu_fid fid; struct lu_attr *attr = NULL; struct lu_seq_range *range = NULL; struct fld_thread_info *info; struct dt_object_format dof; struct dt_it *it; const struct dt_it_ops *iops; int rc; ENTRY; info = lu_context_key_get(&env->le_ctx, &fld_thread_key); LASSERT(info != NULL); lu_local_obj_fid(&fid, FLD_INDEX_OID); OBD_ALLOC_PTR(attr); if (attr == NULL) RETURN(-ENOMEM); memset(attr, 0, sizeof(attr)); attr->la_valid = LA_MODE; attr->la_mode = S_IFREG | 0666; dof.dof_type = DFT_INDEX; dof.u.dof_idx.di_feat = &fld_index_features; dt_obj = dt_find_or_create(env, dt, &fid, &dof, attr); if (IS_ERR(dt_obj)) { rc = PTR_ERR(dt_obj); CERROR("%s: Can't find \"%s\" obj %d\n", fld->lsf_name, fld_index_name, rc); dt_obj = NULL; GOTO(out, rc); } fld->lsf_obj = dt_obj; rc = dt_obj->do_ops->do_index_try(env, dt_obj, &fld_index_features); if (rc == 0) { LASSERT(dt_obj->do_index_ops != NULL); mutex_lock(&fld->lsf_lock); rc = fld_insert_igif_fld(fld, env); mutex_unlock(&fld->lsf_lock); if (rc != 0) { CERROR("insert igif in fld! = %d\n", rc); GOTO(out, rc); } } else { CERROR("%s: File \"%s\" is not an index: rc = %d!\n", fld->lsf_name, fld_index_name, rc); GOTO(out, rc); } range = &info->fti_rec; /* Load fld entry to cache */ iops = &dt_obj->do_index_ops->dio_it; it = iops->init(env, dt_obj, 0, NULL); if (IS_ERR(it)) GOTO(out, rc = PTR_ERR(it)); rc = iops->load(env, it, 0); if (rc < 0) GOTO(out_it_fini, rc); do { rc = iops->rec(env, it, (struct dt_rec *)range, 0); if (rc != 0) GOTO(out_it_fini, rc); LASSERT(range != NULL); range_be_to_cpu(range, range); rc = fld_cache_insert(fld->lsf_cache, range); if (rc != 0) GOTO(out_it_fini, rc); rc = iops->next(env, it); } while (rc == 0); rc = 0; out_it_fini: iops->fini(env, it); out: if (attr != NULL) OBD_FREE_PTR(attr); if (rc != 0) { if (dt_obj != NULL) lu_object_put(env, &dt_obj->do_lu); fld->lsf_obj = NULL; } RETURN(rc); }